Class: ActiveMerchant::Billing::Integrations::Ipay88::Helper
- 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
-
#amount_in_cents ⇒ Object
readonly
Returns the value of attribute amount_in_cents.
-
#merchant_key ⇒ Object
readonly
Returns the value of attribute merchant_key.
Attributes inherited from Helper
Class Method Summary collapse
Instance Method Summary collapse
- #amount=(money) ⇒ Object
- #amount_in_dollars ⇒ Object
- #currency(symbol) ⇒ Object
- #customer(params = {}) ⇒ Object
-
#initialize(order, account, options = {}) ⇒ Helper
constructor
A new instance of Helper.
- #language(lang) ⇒ Object
- #payment(pay_method) ⇒ Object
- #signature ⇒ Object
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, account, = {}) requires!(, :amount, :currency, :credential2) @merchant_key = [:credential2] @amount_in_cents = [: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_cents ⇒ Object (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_key ⇒ Object (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_dollars ⇒ Object
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
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
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
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 |
#signature ⇒ Object
86 87 88 |
# File 'lib/active_merchant/billing/integrations/ipay88/helper.rb', line 86 def signature self.class.sign(self.sig_components) end |