Class: PaymentRails::BatchGateway
- Inherits:
-
Object
- Object
- PaymentRails::BatchGateway
- Includes:
- GatewayHelper
- Defined in:
- lib/paymentrails/gateways/BatchGateway.rb
Instance Method Summary collapse
- #all ⇒ Object
- #batch_builder(response) ⇒ Object
- #batch_list_builder(response) ⇒ Object
- #create(body) ⇒ Object
- #delete(batch_id) ⇒ Object
- #find(batch_id) ⇒ Object
- #generate_quote(batch_id) ⇒ Object
-
#initialize(client) ⇒ BatchGateway
constructor
A new instance of BatchGateway.
- #search(page = 1, page_size = 10, term = '') ⇒ Object
- #start_processing(batch_id) ⇒ Object
- #summary(batch_id) ⇒ Object
- #update(batch_id, body) ⇒ Object
Methods included from GatewayHelper
Constructor Details
#initialize(client) ⇒ BatchGateway
Returns a new instance of BatchGateway.
8 9 10 |
# File 'lib/paymentrails/gateways/BatchGateway.rb', line 8 def initialize(client) @client = client end |
Instance Method Details
#all ⇒ Object
17 18 19 20 |
# File 'lib/paymentrails/gateways/BatchGateway.rb', line 17 def all response = @client.get('/v1/batches/') batch_list_builder(response) end |
#batch_builder(response) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/paymentrails/gateways/BatchGateway.rb', line 52 def batch_builder(response) batch = Batch.new data = JSON.parse(response) data.each do |key, value| next unless key === 'batch' loosely_hydrate_model(batch, value) end batch end |
#batch_list_builder(response) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/paymentrails/gateways/BatchGateway.rb', line 73 def batch_list_builder(response) batches = [] data = JSON.parse(response) data.each do |key, value| next unless key === 'batches' value.each do |newKey, _newValue| batches.push( loosely_hydrate_model(Batch.new, newKey) ) end end batches end |
#create(body) ⇒ Object
22 23 24 25 |
# File 'lib/paymentrails/gateways/BatchGateway.rb', line 22 def create(body) response = @client.post('/v1/batches/', body) batch_builder(response) end |
#delete(batch_id) ⇒ Object
32 33 34 35 |
# File 'lib/paymentrails/gateways/BatchGateway.rb', line 32 def delete(batch_id) @client.delete('/v1/batches/' + batch_id) true end |
#find(batch_id) ⇒ Object
12 13 14 15 |
# File 'lib/paymentrails/gateways/BatchGateway.rb', line 12 def find(batch_id) response = @client.get('/v1/batches/' + batch_id) batch_builder(response) end |
#generate_quote(batch_id) ⇒ Object
37 38 39 40 |
# File 'lib/paymentrails/gateways/BatchGateway.rb', line 37 def generate_quote(batch_id) response = @client.post('/v1/batches/' + batch_id + '/generate-quote', {}) batch_builder(response) end |
#search(page = 1, page_size = 10, term = '') ⇒ Object
47 48 49 50 |
# File 'lib/paymentrails/gateways/BatchGateway.rb', line 47 def search(page = 1, page_size = 10, term = '') response = @client.get('/v1/batches?page=' + page.to_s + '&pageSize=' + page_size.to_s + '&search=' + term) batch_list_builder(response) end |
#start_processing(batch_id) ⇒ Object
42 43 44 45 |
# File 'lib/paymentrails/gateways/BatchGateway.rb', line 42 def start_processing(batch_id) response = @client.post('/v1/batches/' + batch_id + '/start-processing', {}) batch_builder(response) end |
#summary(batch_id) ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/paymentrails/gateways/BatchGateway.rb', line 62 def summary(batch_id) response = @client.get('/v1/batches/' + batch_id + '/summary') summary = BatchSummary.new data = JSON.parse(response) data.each do |key, value| next unless key === 'batchSummary' loosely_hydrate_model(summary, value) end summary end |
#update(batch_id, body) ⇒ Object
27 28 29 30 |
# File 'lib/paymentrails/gateways/BatchGateway.rb', line 27 def update(batch_id, body) @client.patch('/v1/batches/' + batch_id, body) true end |