Class: Trolley::OfflinePaymentGateway

Inherits:
Object
  • Object
show all
Defined in:
lib/trolley/gateways/OfflinePaymentGateway.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ OfflinePaymentGateway

Returns a new instance of OfflinePaymentGateway.



5
6
7
# File 'lib/trolley/gateways/OfflinePaymentGateway.rb', line 5

def initialize(client)
  @client = client
end

Instance Method Details

#create(recipient_id, body) ⇒ Object



9
10
11
12
# File 'lib/trolley/gateways/OfflinePaymentGateway.rb', line 9

def create(recipient_id, body)
  response = @client.post("/v1/recipients/#{recipient_id}/offlinePayments", body)
  offline_payment_builder(response)
end

#delete(recipient_id, offline_payment_id) ⇒ Object



19
20
21
22
# File 'lib/trolley/gateways/OfflinePaymentGateway.rb', line 19

def delete(recipient_id, offline_payment_id)
  @client.delete("/v1/recipients/#{recipient_id}/offlinePayments/#{offline_payment_id}")
  true
end

#offline_payment_builder(response) ⇒ Object

rubocop:enable Metrics/ParameterLists



36
37
38
# File 'lib/trolley/gateways/OfflinePaymentGateway.rb', line 36

def offline_payment_builder(response)
  Utils::ResponseMapper.build(response, OfflinePayment)
end

#offline_payments_list_builder(response) ⇒ Object



40
41
42
# File 'lib/trolley/gateways/OfflinePaymentGateway.rb', line 40

def offline_payments_list_builder(response)
  Utils::PaginatedArray.from_response(response, OfflinePayment)
end

#search(recipient_id = '', page = 1, page_size = 10, term = '') ⇒ Object

rubocop:disable Metrics/ParameterLists



25
26
27
28
29
30
31
32
33
# File 'lib/trolley/gateways/OfflinePaymentGateway.rb', line 25

def search(recipient_id = '', page = 1, page_size = 10, term = '')
  if recipient_id === ''
    response = @client.get("/v1/offline-payments?page=#{page}&pageSize=#{page_size}&search=#{term}")
  else
    response = @client.get("/v1/recipients/#{recipient_id}/offlinePayments?page=#{page}&pageSize=#{page_size}&search=#{term}")
  end

  offline_payments_list_builder(response)
end

#update(recipient_id, offline_payment_id, body) ⇒ Object



14
15
16
17
# File 'lib/trolley/gateways/OfflinePaymentGateway.rb', line 14

def update(recipient_id, offline_payment_id, body)
  @client.patch("/v1/recipients/#{recipient_id}/offlinePayments/#{offline_payment_id}", body)
  true
end