class OffsitePayments::Integrations::Universal::Helper

Constants

CURRENCY_SPECIAL_MINOR_UNITS

Public Class Methods

new(order, account, options = {}) click to toggle source
Calls superclass method
# File lib/offsite_payments/integrations/universal.rb, line 49
def initialize(order, account, options = {})
  @forward_url = options[:forward_url]
  @key = options[:credential2]
  @currency = options[:currency]

  # x_credential3 should not be included in the request when using the universal offsite dev kit.
  options[:credential3] = nil if options[:credential3] == @forward_url

  super
  self.country = options[:country]
  self.account_name = options[:account_name]
  self.transaction_type = options[:transaction_type]
  add_field 'x_test', @test.to_s
end

Public Instance Methods

amount=(amount) click to toggle source
# File lib/offsite_payments/integrations/universal.rb, line 72
def amount=(amount)
  add_field 'x_amount', format_amount(amount, @currency)
end
credential_based_url() click to toggle source
# File lib/offsite_payments/integrations/universal.rb, line 64
def credential_based_url
  @forward_url
end
form_fields() click to toggle source
# File lib/offsite_payments/integrations/universal.rb, line 68
def form_fields
  sign_fields
end
generate_signature() click to toggle source
# File lib/offsite_payments/integrations/universal.rb, line 80
def generate_signature
  Universal.sign(@fields, @key)
end
sign_fields() click to toggle source
# File lib/offsite_payments/integrations/universal.rb, line 76
def sign_fields
  @fields.merge!('x_signature' => generate_signature)
end

Private Instance Methods

format_amount(amount, currency) click to toggle source
# File lib/offsite_payments/integrations/universal.rb, line 128
def format_amount(amount, currency)
  units = CURRENCY_SPECIAL_MINOR_UNITS[currency] || 2
  sprintf("%.#{units}f", amount)
end