Class: ActiveMerchant::Billing::Integrations::Ipay88::Helper

Inherits:
Helper
  • Object
show all
Includes:
RequiresParameters
Defined in:
lib/active_merchant/billing/integrations/ipay88/helper.rb

Constant Summary collapse

SUPPORTED_CURRENCIES =

Currencies supported

MYR (Malaysian Ringgit - for all payment methods except China Union Pay and PayPal)
USD (US Dollar - only for PayPal)
CNY (Yuan Renminbi - only for China Union Pay)
%w[MYR USD CNY]
SUPPORTED_LANGS =

Languages supported

ISO-8859-1 (English)
UTF-8      (Unicode)
GB2312     (Chinese Simplified)
GD18030    (Chinese Simplified)
BIG5       (Chinese Traditional)
%w[ISO-8859-1 UTF-8 GB2312 GD18030 BIG5]
PAYMENT_METHODS =

Payment methods supported

8  (Alliance Online Transfer)
10 (AmBank)
21 (China Union Pay)
20 (CIMB Click)
2  (Credit Card MYR)
16 (FPX)
15 (Hong Leong Bank Transfer)
6  (Maybank2u.com)
23 (MEPS Cash)
17 (Mobile Money)
33 (PayPal)
14 (RHB)
%w[8 10 21 20 2 16 15 6 23 17 33 14]

Instance Attribute Summary collapse

Attributes inherited from Helper

#fields

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Helper

#add_field, #add_fields, #add_raw_html_field, #billing_address, #form_fields, #form_method, mapping, #raw_html_fields, #shipping_address, #test?

Constructor Details

#initialize(order, account, options = {}) ⇒ Helper

Returns a new instance of Helper.



41
42
43
44
45
46
47
# File 'lib/active_merchant/billing/integrations/ipay88/helper.rb', line 41

def initialize(order, , options = {})
  requires!(options, :amount, :currency, :credential2)
  @merchant_key = options[:credential2]
  @amount_in_cents = options[:amount]
  super
  add_field mappings[:signature], signature
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ActiveMerchant::Billing::Integrations::Helper

Instance Attribute Details

#amount_in_centsObject (readonly)

Returns the value of attribute amount_in_cents.



39
40
41
# File 'lib/active_merchant/billing/integrations/ipay88/helper.rb', line 39

def amount_in_cents
  @amount_in_cents
end

#merchant_keyObject (readonly)

Returns the value of attribute merchant_key.



39
40
41
# File 'lib/active_merchant/billing/integrations/ipay88/helper.rb', line 39

def merchant_key
  @merchant_key
end

Class Method Details

.sign(str) ⇒ Object



82
83
84
# File 'lib/active_merchant/billing/integrations/ipay88/helper.rb', line 82

def self.sign(str)
  [Digest::SHA1.digest(str)].pack("m").chomp
end

Instance Method Details

#amount=(money) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/active_merchant/billing/integrations/ipay88/helper.rb', line 53

def amount=(money)
  @amount_in_cents = money.respond_to?(:cents) ? money.cents : money
  if money.is_a?(String) or @amount_in_cents.to_i < 0
    raise ArgumentError, "money amount must be either a Money object or a positive integer in cents."
  end
  add_field mappings[:amount], amount_in_dollars
end

#amount_in_dollarsObject



49
50
51
# File 'lib/active_merchant/billing/integrations/ipay88/helper.rb', line 49

def amount_in_dollars
  sprintf("%.2f", @amount_in_cents.to_f/100)
end

#currency(symbol) ⇒ Object

Raises:

  • (ArgumentError)


61
62
63
64
# File 'lib/active_merchant/billing/integrations/ipay88/helper.rb', line 61

def currency(symbol)
  raise ArgumentError, "unsupported currency" unless SUPPORTED_CURRENCIES.include?(symbol)
  add_field mappings[:currency], symbol
end

#customer(params = {}) ⇒ Object



76
77
78
79
80
# File 'lib/active_merchant/billing/integrations/ipay88/helper.rb', line 76

def customer(params = {})
  add_field(mappings[:customer][:name], "#{params[:first_name]} #{params[:last_name]}")
  add_field(mappings[:customer][:email], params[:email])
  add_field(mappings[:customer][:phone], params[:phone])
end

#language(lang) ⇒ Object

Raises:

  • (ArgumentError)


66
67
68
69
# File 'lib/active_merchant/billing/integrations/ipay88/helper.rb', line 66

def language(lang)
  raise ArgumentError, "unsupported language" unless SUPPORTED_LANGS.include?(lang)
  add_field mappings[:language], lang
end

#payment(pay_method) ⇒ Object

Raises:

  • (ArgumentError)


71
72
73
74
# File 'lib/active_merchant/billing/integrations/ipay88/helper.rb', line 71

def payment(pay_method)
  raise ArgumentError, "unsupported payment method" unless PAYMENT_METHODS.include?(pay_method.to_s)
  add_field mappings[:payment], pay_method
end

#signatureObject



86
87
88
# File 'lib/active_merchant/billing/integrations/ipay88/helper.rb', line 86

def signature
  self.class.sign(self.sig_components)
end