Class: PaymentGateway
- Inherits:
-
Object
- Object
- PaymentGateway
- Defined in:
- lib/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_number = 10, term = '') ⇒ Object
- #update(batch_id, payment_id, body) ⇒ Object
Constructor Details
#initialize(client) ⇒ PaymentGateway
Returns a new instance of PaymentGateway.
4 5 6 |
# File 'lib/PaymentGateway.rb', line 4 def initialize(client) @client = client end |
Instance Method Details
#create(batch_id, body) ⇒ Object
13 14 15 16 |
# File 'lib/PaymentGateway.rb', line 13 def create(batch_id, body) response = @client.post('/v1/batches/' + batch_id + '/payments', body) payment_builder(response) end |
#delete(batch_id, payment_id) ⇒ Object
23 24 25 26 |
# File 'lib/PaymentGateway.rb', line 23 def delete(batch_id, payment_id) @client.delete('/v1/batches/' + batch_id + '/payments/' + payment_id) true end |
#find(batch_id, payment_id) ⇒ Object
8 9 10 11 |
# File 'lib/PaymentGateway.rb', line 8 def find(batch_id, payment_id) response = @client.get('/v1/batches/' + batch_id + '/payments/' + payment_id) payment_builder(response) end |
#payment_builder(response) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/PaymentGateway.rb', line 33 def payment_builder(response) payment = Payment.new data = JSON.parse(response) data.each do |key, value| next unless key === 'payment' value.each do |recipKey, recipValue| payment.send("#{recipKey}=", recipValue) end end payment end |
#payments_list_builder(response) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/PaymentGateway.rb', line 45 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 = Payment.new newKey.each do |key1, value1| payment.send("#{key1}=", value1) end payments.push(payment) end end payments end |
#search(batch_id, page = 1, page_number = 10, term = '') ⇒ Object
28 29 30 31 |
# File 'lib/PaymentGateway.rb', line 28 def search(batch_id, page = 1, page_number = 10, term = '') response = @client.get('/v1/batches/' + batch_id.to_s + '/payments?' + 'page=' + page.to_s + '&pageSize=' + page_number.to_s + '&search=' + term) payments_list_builder(response) end |
#update(batch_id, payment_id, body) ⇒ Object
18 19 20 21 |
# File 'lib/PaymentGateway.rb', line 18 def update(batch_id, payment_id, body) @client.patch('/v1/batches/' + batch_id + '/payments/' + payment_id, body) true end |