Class: SlimpayClient::Payment

Inherits:
Resource show all
Defined in:
lib/slimpay_client/payment.rb

Overview

An abstract Payment to be inherited from.

Defines API Payment non-semantic methods.

Instance Method Summary collapse

Methods inherited from Base

#generate_api_methods

Constructor Details

#initializePayment

Returns a new instance of Payment.



6
7
8
9
# File 'lib/slimpay_client/payment.rb', line 6

def initialize
  @resource_name = self.class.to_s.demodulize.underscore.dasherize.pluralize
  super
end

Instance Method Details

#cancel(id) ⇒ Object



32
33
34
35
36
37
# File 'lib/slimpay_client/payment.rb', line 32

def cancel(id)
  url = "payments/#{id}/cancellation"
  body_options = {}
  response = HTTParty.post("#{@endpoint}/#{url}", body: body_options.to_json, headers: options)
  follow_up_api(response)
end

#get_one(id = 1) ⇒ Object



11
12
13
14
15
16
# File 'lib/slimpay_client/payment.rb', line 11

def get_one(id = 1)
  url = "#{@endpoint}/payments/#{id}"
  response = HTTParty.get(url, headers: options)
  generate_api_methods(JSON.parse(response.body))
  SlimpayClient.answer(response)
end

#issues(id = 1) ⇒ Object



18
19
20
21
22
23
# File 'lib/slimpay_client/payment.rb', line 18

def issues(id = 1)
  url = "#{@endpoint}/payments/#{id}/issues"
  response = HTTParty.get(url, headers: options)
  generate_api_methods(JSON.parse(response.body))
  SlimpayClient.answer(response)
end

#refund(id, amount) ⇒ Object



25
26
27
28
29
30
# File 'lib/slimpay_client/payment.rb', line 25

def refund(id, amount)
  url = "payments/#{id}/refund"
  body_options = {amount: amount}
  response = HTTParty.post("#{@endpoint}/#{url}", body: body_options.to_json, headers: options)
  follow_up_api(response)
end