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?

Constructor Details

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


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

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


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

def amount_in_cents
  @amount_in_cents
end

#channelObject (readonly)

Returns the value of attribute channel


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

def channel
  @channel
end

#verify_keyObject (readonly)

Returns the value of attribute verify_key


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

def verify_key
  @verify_key
end

Instance Method Details

#amount=(money) ⇒ Object


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

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


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

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)

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

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

#form_fieldsObject


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

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

#language=(lang) ⇒ Object

Raises:

  • (ArgumentError)

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

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