class OffsitePayments::Integrations::Molpay::Helper

(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

Constants

SERVICE_URL
SUPPORTED_CURRENCIES
SUPPORTED_LANGUAGES

Defaults to en

Attributes

amount_in_cents[R]
channel[R]
verify_key[R]

Public Class Methods

new(order, account, options = {}) click to toggle source
Calls superclass method
# File lib/offsite_payments/integrations/molpay.rb, line 50
def initialize(order, account, options = {})
  requires!(options, :amount, :currency, :credential2)
  @verify_key = options[:credential2] if options[:credential2]
  @amount_in_cents = options[:amount]
  @channel = options.delete(:channel)
  super
end

Public Instance Methods

amount=(money) click to toggle source
# 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_url() click to toggle source
# 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) click to toggle source
# 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_fields() click to toggle source
# File lib/offsite_payments/integrations/molpay.rb, line 58
def form_fields
  add_field mappings[:signature], signature
  @fields
end
language=(lang) click to toggle source
# 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

Private Instance Methods

signature() click to toggle source
# File lib/offsite_payments/integrations/molpay.rb, line 82
def signature
  Digest::MD5.hexdigest("#{@fields[mappings[:amount]]}#{@fields[mappings[:account]]}#{@fields[mappings[:order]]}#{@verify_key}")
end