Class: Laundry::PaymentsGateway::Account

Inherits:
ResponseModel show all
Defined in:
lib/laundry/payments_gateway/models/account.rb

Constant Summary collapse

EFT_SALE =

EFT TRANSACTION_CODES

20
EFT_AUTH_ONLY =
21
EFT_CAPTURE =
22
EFT_CREDIT =
23
EFT_VOID =
24
EFT_FORCE =
25
EFT_VERIFY_ONLY =
26

Instance Attribute Summary

Attributes inherited from ResponseModel

#merchant, #record

Instance Method Summary collapse

Methods inherited from ResponseModel

#blank?, dump, #dumpable, from_response, load, #method_missing, #require_merchant!, #to_hash

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Laundry::PaymentsGateway::ResponseModel

Instance Method Details

#credit_cents(cents, *args) ⇒ Object


23
24
25
# File 'lib/laundry/payments_gateway/models/account.rb', line 23

def credit_cents(cents, *args)
  credit_dollars(dollarize(cents), *args)
end

#credit_dollars(dollars, *args) ⇒ Object


31
32
33
# File 'lib/laundry/payments_gateway/models/account.rb', line 31

def credit_dollars(dollars, *args)
  perform_transaction(dollars, EFT_CREDIT, *args)
end

#debit_cents(cents, *args) ⇒ Object


19
20
21
# File 'lib/laundry/payments_gateway/models/account.rb', line 19

def debit_cents(cents, *args)
  debit_dollars(dollarize(cents), *args)
end

#debit_dollars(dollars, *args) ⇒ Object


27
28
29
# File 'lib/laundry/payments_gateway/models/account.rb', line 27

def debit_dollars(dollars, *args)
  perform_transaction(dollars, EFT_SALE, *args)
end

#idObject


49
50
51
# File 'lib/laundry/payments_gateway/models/account.rb', line 49

def id
  payment_method_id
end

#initialize_with_response(response) ⇒ Object


6
7
8
# File 'lib/laundry/payments_gateway/models/account.rb', line 6

def initialize_with_response(response)
  self.record = response[:get_payment_method_response][:get_payment_method_result][:payment_method]
end

#perform_transaction(dollars, type, options = {}) ⇒ Object


35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/laundry/payments_gateway/models/account.rb', line 35

def perform_transaction(dollars, type, options = {})
  require_merchant!
  options = {
   'pg_merchant_id' => self.merchant.id,
   'pg_password' => self.merchant.transaction_password,
   'pg_total_amount' => dollars,
   'pg_client_id' => self.client_id,
   'pg_payment_method_id' => self.id,
   'pg_transaction_type' => type
   }.merge(options)
  r = self.merchant.socket_driver.exec(options)
  TransactionResponse.from_response(r, self.merchant)
end