Class: PaymentRails::PaymentGateway
- Inherits:
-
Object
- Object
- PaymentRails::PaymentGateway
- Includes:
- GatewayHelper
- Defined in:
- lib/paymentrails/gateways/PaymentGateway.rb
Instance Method Summary collapse
- #create(batch_id, body) ⇒ Object
- #delete(batch_id, payment_id) ⇒ Object
- #find(batch_id, payment_id) ⇒ Object
-
#initialize(client) ⇒ PaymentGateway
constructor
A new instance of PaymentGateway.
- #payment_builder(response) ⇒ Object
- #payments_list_builder(response) ⇒ Object
- #search(batch_id, page = 1, page_size = 10, term = '') ⇒ Object
- #update(batch_id, payment_id, body) ⇒ Object
Methods included from GatewayHelper
Constructor Details
#initialize(client) ⇒ PaymentGateway
Returns a new instance of PaymentGateway.
8 9 10 |
# File 'lib/paymentrails/gateways/PaymentGateway.rb', line 8 def initialize(client) @client = client end |
Instance Method Details
#create(batch_id, body) ⇒ Object
17 18 19 20 |
# File 'lib/paymentrails/gateways/PaymentGateway.rb', line 17 def create(batch_id, body) response = @client.post('/v1/batches/' + batch_id + '/payments', body) payment_builder(response) end |
#delete(batch_id, payment_id) ⇒ Object
27 28 29 30 |
# File 'lib/paymentrails/gateways/PaymentGateway.rb', line 27 def delete(batch_id, payment_id) @client.delete('/v1/batches/' + batch_id + '/payments/' + payment_id) true end |
#find(batch_id, payment_id) ⇒ Object
12 13 14 15 |
# File 'lib/paymentrails/gateways/PaymentGateway.rb', line 12 def find(batch_id, payment_id) response = @client.get('/v1/batches/' + batch_id + '/payments/' + payment_id) payment_builder(response) end |
#payment_builder(response) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/paymentrails/gateways/PaymentGateway.rb', line 37 def payment_builder(response) payment = Payment.new data = JSON.parse(response) data.each do |key, value| next unless key === 'payment' loosely_hydrate_model(payment, value) end payment end |
#payments_list_builder(response) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/paymentrails/gateways/PaymentGateway.rb', line 47 def payments_list_builder(response) payments = [] data = JSON.parse(response) data.each do |key, value| next unless key === 'payments' value.each do |newKey, _newValue| payment = loosely_hydrate_model(Payment.new, newKey) payments.push(payment) end end payments end |
#search(batch_id, page = 1, page_size = 10, term = '') ⇒ Object
32 33 34 35 |
# File 'lib/paymentrails/gateways/PaymentGateway.rb', line 32 def search(batch_id, page = 1, page_size = 10, term = '') response = @client.get('/v1/batches/' + batch_id.to_s + '/payments?page=' + page.to_s + '&pageSize=' + page_size.to_s + '&search=' + term) payments_list_builder(response) end |
#update(batch_id, payment_id, body) ⇒ Object
22 23 24 25 |
# File 'lib/paymentrails/gateways/PaymentGateway.rb', line 22 def update(batch_id, payment_id, body) @client.patch('/v1/batches/' + batch_id + '/payments/' + payment_id, body) true end |