class DragonPay::Client

Attributes

amount[RW]

attributes that are required

currency[RW]

attributes that can be given default value

customer_email_address[RW]

attributes that are required

digest[RW]

attributes that can be given default value

merchant_id[RW]

attributes that can be given default value

param1[RW]

attributes that can be given default value

param2[RW]

attributes that can be given default value

payment_description[RW]

attributes that can be generated from other attributes

secret_key[RW]

attributes that can be given default value

transaction_id[RW]

attributes that are required

Public Class Methods

new(options) click to toggle source
# File lib/dragon_pay/client.rb, line 14
def initialize(options)
  self.transaction_id         = options[:transaction_id]
  self.amount                 = options[:amount]
  self.customer_email_address = options[:customer_email_address]
  fill_in_defaults(options)
end

Public Instance Methods

generate_request_url() click to toggle source
# File lib/dragon_pay/client.rb, line 21
def generate_request_url
  %Q{
    #{payment_switch_url}?
     merchantid = #{merchant_id}&
          txnid = #{transaction_id}&
         amount = #{amount}&
            ccy = #{currency}&
    description = #{uri_encode(payment_description)}&
          email = #{uri_encode(customer_email_address)}&
         digest = #{digest}&
         param1 = #{param1}&
         param2 = #{param2}
  }.split.join
end

Private Instance Methods

digestable_parameters() click to toggle source

combines all the parameters into 1 so that it can be SHA1 digested

# File lib/dragon_pay/client.rb, line 67
def digestable_parameters
  %Q{
    #{merchant_id}:
    #{transaction_id}:
    #{amount}:
    #{currency}:
    #{payment_description}:
    #{customer_email_address}:
    #{secret_key}
  }.split.join
end
fill_in_defaults(options) click to toggle source

fields that can be assigned default values

# File lib/dragon_pay/client.rb, line 45
def fill_in_defaults(options)
  self.merchant_id = options[:merchant_id] || DragonPay.configuration.merchant_id
  self.secret_key  = options[:secret_key]  || DragonPay.configuration.secret_key
  self.currency    = options[:currency]    || DragonPay.configuration.currency
  self.param1      = options[:param1]      || ''
  self.param2      = options[:param2]      || ''

  description = generate_payment_description unless options[:payment_description]
  self.payment_description = uri_encode(description)
end
generate_payment_description() click to toggle source

generates description based on param values

# File lib/dragon_pay/client.rb, line 57
def generate_payment_description
  "Payment of #{currency}#{amount} from buyer #{customer_email_address} to merchant #{merchant_id}"
end
payment_switch_url() click to toggle source
# File lib/dragon_pay/client.rb, line 40
def payment_switch_url
  "#{DragonPay.configuration.payment_switch_domain}/Pay.aspx"
end
uri_encode(string) click to toggle source
# File lib/dragon_pay/client.rb, line 83
def uri_encode(string)
  CGI::escape(string)
end