Class: OffsitePayments::Integrations::Ipay88::Helper

Inherits:
Helper
  • Object
show all
Includes:
ActiveUtils::RequiresParameters
Defined in:
lib/offsite_payments/integrations/ipay88.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, inherited, mapping, #raw_html_fields, #shipping_address, #test?

Methods included from MoneyCompatibility

#to_cents

Constructor Details

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

Returns a new instance of Helper.



56
57
58
59
60
61
62
# File 'lib/offsite_payments/integrations/ipay88.rb', line 56

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 OffsitePayments::Helper

Instance Attribute Details

#amount_in_centsObject (readonly)

Returns the value of attribute amount_in_cents.



54
55
56
# File 'lib/offsite_payments/integrations/ipay88.rb', line 54

def amount_in_cents
  @amount_in_cents
end

#merchant_keyObject (readonly)

Returns the value of attribute merchant_key.



54
55
56
# File 'lib/offsite_payments/integrations/ipay88.rb', line 54

def merchant_key
  @merchant_key
end

Class Method Details

.sign(str) ⇒ Object



97
98
99
# File 'lib/offsite_payments/integrations/ipay88.rb', line 97

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

Instance Method Details

#amount=(money) ⇒ Object

Raises:

  • (ArgumentError)


68
69
70
71
72
73
74
# File 'lib/offsite_payments/integrations/ipay88.rb', line 68

def amount=(money)
  @amount_in_cents = to_cents(money)
  raise ArgumentError, "amount must be a Money object or an integer" if money.is_a?(String)
  raise ActionViewHelperError, "amount must be greater than $0.00" if @amount_in_cents.to_i <= 0

  add_field mappings[:amount], amount_in_dollars
end

#amount_in_dollarsObject



64
65
66
# File 'lib/offsite_payments/integrations/ipay88.rb', line 64

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

#currency(symbol) ⇒ Object

Raises:

  • (ArgumentError)


76
77
78
79
# File 'lib/offsite_payments/integrations/ipay88.rb', line 76

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

#customer(params = {}) ⇒ Object



91
92
93
94
95
# File 'lib/offsite_payments/integrations/ipay88.rb', line 91

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)


81
82
83
84
# File 'lib/offsite_payments/integrations/ipay88.rb', line 81

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

#payment(pay_method) ⇒ Object

Raises:

  • (ArgumentError)


86
87
88
89
# File 'lib/offsite_payments/integrations/ipay88.rb', line 86

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



101
102
103
# File 'lib/offsite_payments/integrations/ipay88.rb', line 101

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