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 48 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 71 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 63 def credential_based_url @forward_url end
form_fields()
click to toggle source
# File lib/offsite_payments/integrations/universal.rb, line 67 def form_fields sign_fields end
generate_signature()
click to toggle source
# File lib/offsite_payments/integrations/universal.rb, line 79 def generate_signature fields_to_sign = @fields.select { |key, _| key.start_with?('x_') && key != 'x_signature' } Universal.sign(fields_to_sign, @key) end
sign_fields()
click to toggle source
# File lib/offsite_payments/integrations/universal.rb, line 75 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