Class: PaymentRails::InvoicePaymentGateway

Inherits:
Object
  • Object
show all
Includes:
GatewayHelper
Defined in:
lib/paymentrails/gateways/InvoicePaymentGateway.rb

Instance Method Summary collapse

Methods included from GatewayHelper

#loosely_hydrate_model

Constructor Details

#initialize(client) ⇒ InvoicePaymentGateway

Returns a new instance of InvoicePaymentGateway.



8
9
10
# File 'lib/paymentrails/gateways/InvoicePaymentGateway.rb', line 8

def initialize(client)
  @client = client
end

Instance Method Details

#create(body) ⇒ Object



12
13
14
15
# File 'lib/paymentrails/gateways/InvoicePaymentGateway.rb', line 12

def create(body)
  response = @client.post('/v1/invoices/payment/create', body)
  invoice_payment_builder(response)
end

#delete(body) ⇒ Object



22
23
24
25
# File 'lib/paymentrails/gateways/InvoicePaymentGateway.rb', line 22

def delete(body)
  @client.post('/v1/invoices/payment/delete', body)
  true
end

#invoice_payment_builder(response) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/paymentrails/gateways/InvoicePaymentGateway.rb', line 32

def invoice_payment_builder(response)
  invoice_payment = InvoicePayment.new
  data = JSON.parse(response)
  data.each do |key, value|
    next unless key === 'invoicePayment'
    loosely_hydrate_model(invoice_payment, value)
  end
  invoice_payment
end

#invoice_payments_list_builder(response) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/paymentrails/gateways/InvoicePaymentGateway.rb', line 42

def invoice_payments_list_builder(response)
  invoice_payments = []
  data = JSON.parse(response)

  data.each do |key, value|
    next unless key === 'invoicePayments'
    value.each do |newKey, _newValue|
      invoice_payment = loosely_hydrate_model(InvoicePayment.new, newKey)
      invoice_payments.push(invoice_payment)
    end
  end
  invoice_payments
end

#search(body) ⇒ Object



27
28
29
30
# File 'lib/paymentrails/gateways/InvoicePaymentGateway.rb', line 27

def search(body)
  response = @client.post('/v1/invoices/payment/search', body)
  invoice_payments_list_builder(response)
end

#update(body) ⇒ Object



17
18
19
20
# File 'lib/paymentrails/gateways/InvoicePaymentGateway.rb', line 17

def update(body)
  @client.post('/v1/invoices/payment/update', body)
  true
end