class OffsitePayments::Integrations::Ipay88::Helper

Constants

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)
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)
SUPPORTED_LANGS

Languages supported

ISO-8859-1 (English)
UTF-8      (Unicode)
GB2312     (Chinese Simplified)
GD18030    (Chinese Simplified)
BIG5       (Chinese Traditional)

Attributes

amount_in_cents[R]
merchant_key[R]

Public Class Methods

new(order, account, options = {}) click to toggle source
Calls superclass method
# File lib/offsite_payments/integrations/ipay88.rb, line 56
def initialize(order, account, options = {})
  requires!(options, :amount, :currency, :credential2)
  @merchant_key = options[:credential2]
  @amount_in_cents = options[:amount]
  super
  add_field mappings[:signature], signature
end
sign(str) click to toggle source
# File lib/offsite_payments/integrations/ipay88.rb, line 97
def self.sign(str)
  [Digest::SHA1.digest(str)].pack("m").chomp
end

Public Instance Methods

amount=(money) click to toggle source
# File lib/offsite_payments/integrations/ipay88.rb, line 68
def amount=(money)
  @amount_in_cents = money.respond_to?(:cents) ? money.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_dollars() click to toggle source
# File lib/offsite_payments/integrations/ipay88.rb, line 64
def amount_in_dollars
  sprintf("%.2f", @amount_in_cents.to_f/100)
end
currency(symbol) click to toggle source
# 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 = {}) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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
signature() click to toggle source
# File lib/offsite_payments/integrations/ipay88.rb, line 101
def signature
  self.class.sign(self.sig_components)
end

Protected Instance Methods

sig_components() click to toggle source
# File lib/offsite_payments/integrations/ipay88.rb, line 122
def sig_components
  components  = [merchant_key]
  components << fields[mappings[:account]]
  components << fields[mappings[:order]]
  components << amount_in_dollars.gsub(/[.,]/, '')
  components << fields[mappings[:currency]]
  components.join
end