Class: OffsitePayments::Integrations::Molpay::Helper

Inherits:
Helper
  • Object
show all
Includes:
ActiveUtils::RequiresParameters
Defined in:
lib/offsite_payments/integrations/molpay.rb

Overview

(Optional Parameter) = channel //will generate URL to go directly to specific channel, e.g maybank2u, cimb

Please refer MOLPay API spec for the channel routing

Constant Summary collapse

SUPPORTED_CURRENCIES =
['MYR', 'USD', 'SGD', 'PHP', 'VND', 'IDR', 'AUD', 'CNY', 'THB', 'GBP', 'EUR', 'HKD']
SUPPORTED_LANGUAGES =

Defaults to en

['en', 'cn']
SERVICE_URL =
'https://www.onlinepayment.com.my/MOLPay/pay/'.freeze

Instance Attribute Summary collapse

Attributes inherited from Helper

#fields

Instance Method Summary collapse

Methods inherited from Helper

#add_field, #add_fields, #add_raw_html_field, #billing_address, #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.



50
51
52
53
54
55
56
# File 'lib/offsite_payments/integrations/molpay.rb', line 50

def initialize(order, , options = {})
  requires!(options, :amount, :currency, :credential2)
  @verify_key = options[:credential2] if options[:credential2]
  @amount_in_cents = options[:amount]
  @channel = options.delete(:channel)
  super
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.



42
43
44
# File 'lib/offsite_payments/integrations/molpay.rb', line 42

def amount_in_cents
  @amount_in_cents
end

#channelObject (readonly)

Returns the value of attribute channel.



42
43
44
# File 'lib/offsite_payments/integrations/molpay.rb', line 42

def channel
  @channel
end

#verify_keyObject (readonly)

Returns the value of attribute verify_key.



42
43
44
# File 'lib/offsite_payments/integrations/molpay.rb', line 42

def verify_key
  @verify_key
end

Instance Method Details

#amount=(money) ⇒ Object



63
64
65
66
67
68
# File 'lib/offsite_payments/integrations/molpay.rb', line 63

def amount=(money)
  unless money > 0
    raise ArgumentError, "amount must be greater than $0.00."
  end
  add_field mappings[:amount], sprintf("%.2f", money.to_f)
end

#credential_based_urlObject



44
45
46
47
48
# File 'lib/offsite_payments/integrations/molpay.rb', line 44

def credential_based_url
  service_url = SERVICE_URL + @fields[mappings[:account]] + "/"
  service_url = service_url + @channel if @channel
  service_url
end

#currency=(cur) ⇒ Object

Raises:

  • (ArgumentError)


70
71
72
73
# File 'lib/offsite_payments/integrations/molpay.rb', line 70

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

#form_fieldsObject



58
59
60
61
# File 'lib/offsite_payments/integrations/molpay.rb', line 58

def form_fields
  add_field mappings[:signature], signature
  @fields
end

#language=(lang) ⇒ Object

Raises:

  • (ArgumentError)


75
76
77
78
# File 'lib/offsite_payments/integrations/molpay.rb', line 75

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