Class: Laundry::PaymentsGateway::AccountDriver

Inherits:
MerchantAuthenticatableDriver show all
Defined in:
lib/laundry/payments_gateway/drivers/account_driver.rb

Instance Attribute Summary collapse

Attributes inherited from MerchantAuthenticatableDriver

#merchant

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from MerchantAuthenticatableDriver

#default_body, #setup_client!, uglify_hash

Methods included from SOAPModel

#actions, extended, #setup

Constructor Details

#initialize(client, merchant) ⇒ AccountDriver

Returns a new instance of AccountDriver



7
8
9
10
# File 'lib/laundry/payments_gateway/drivers/account_driver.rb', line 7

def initialize(client, merchant)
  super merchant
  self.client = client
end

Instance Attribute Details

#clientObject

Returns the value of attribute client



6
7
8
# File 'lib/laundry/payments_gateway/drivers/account_driver.rb', line 6

def client
  @client
end

Class Method Details

.prettifiable_fieldsObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/laundry/payments_gateway/drivers/account_driver.rb', line 34

def self.prettifiable_fields
  ['MerchantID',
   'ClientID',
   'PaymentMethodID',
   'AcctHolderName',
   'EcAccountNumber',
   'EcAccountTRN',
   'EcAccountType',
   'Note',
   'IsDefault']
end

Instance Method Details

#client_driverObject



12
13
14
# File 'lib/laundry/payments_gateway/drivers/account_driver.rb', line 12

def client_driver
  @client_driver ||= ClientDriver.new(self.merchant)
end

#create!(options = {}) ⇒ Object

Returns the payment method id

Raises:

  • (ArgumentError)


24
25
26
27
28
29
30
31
32
# File 'lib/laundry/payments_gateway/drivers/account_driver.rb', line 24

def create!(options = {})
  raise ArgumentError, "Tried to create an account on an invalid client." if self.client.nil? || self.client.blank?
  options = {merchant_id: self.merchant.id, client_id: self.client.id, payment_method_id: 0}.merge(options)
  options = AccountDriver.uglify_hash(options)
  r = client_driver.create_payment_method({'payment' => options}) do
    http.headers["SOAPAction"] = 'https://ws.paymentsgateway.net/v1/IClientService/createPaymentMethod'
  end
  r[:create_payment_method_response][:create_payment_method_result]
end

#find(payment_method_id) ⇒ Object



16
17
18
19
20
21
# File 'lib/laundry/payments_gateway/drivers/account_driver.rb', line 16

def find(payment_method_id)
  r = client_driver.get_payment_method({'ClientID' => self.client.id, 'PaymentMethodID' => payment_method_id}) do
    http.headers["SOAPAction"] = 'https://ws.paymentsgateway.net/v1/IClientService/getPaymentMethod'
  end
  Account.from_response(r, self.merchant)
end