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, 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
# File 'lib/active_merchant/billing/integrations/ipay88/helper.rb', line 41

def initialize(order, , options = {})
  requires!(options, :amount, :currency)
  @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

Class Method Details

.sign(str) ⇒ Object

Generate a Base64-encoded SHA1 given a string



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

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

Instance Method Details

#amount=(money) ⇒ Object



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

def amount=(money)
  cents = money.respond_to?(:cents) ? money.cents : money
  if money.is_a?(String) or 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], sprintf("%.2f", cents.to_f/100)
end

#currency(symbol) ⇒ Object

Raises:

  • (ArgumentError)


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

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

#language(lang) ⇒ Object

Raises:

  • (ArgumentError)


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

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

#payment(pay_method) ⇒ Object

Raises:

  • (ArgumentError)


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

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



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

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