Class: OffsitePayments::Integrations::Valitor::Helper
- Inherits:
-
Helper
- Object
- Helper
- OffsitePayments::Integrations::Valitor::Helper
show all
- Includes:
- ActiveUtils::RequiresParameters
- Defined in:
- lib/offsite_payments/integrations/valitor.rb
Constant Summary
collapse
- DEFAULT_SUCCESS_TEXT =
"The transaction has been completed."
Instance Attribute Summary
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?
#to_cents
Constructor Details
#initialize(order, account, options = {}) ⇒ Helper
Returns a new instance of Helper.
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/offsite_payments/integrations/valitor.rb', line 31
def initialize(order, account, options={})
options[:currency] ||= 'ISK'
super
add_field 'Adeinsheimild', '0'
add_field 'KaupandaUpplysingar', '0'
add_field 'SlokkvaHaus', '0'
@security_number = options[:credential2]
@amount = options[:amount]
@order = order
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class OffsitePayments::Helper
Instance Method Details
#authorize_only ⇒ Object
55
56
57
|
# File 'lib/offsite_payments/integrations/valitor.rb', line 55
def authorize_only
add_field 'Adeinsheimild', '1'
end
|
#collect_customer_info ⇒ Object
59
60
61
|
# File 'lib/offsite_payments/integrations/valitor.rb', line 59
def collect_customer_info
add_field 'KaupandaUpplysingar', '1'
end
|
92
93
94
95
96
|
# File 'lib/offsite_payments/integrations/valitor.rb', line 92
def form_fields
product(1, :amount => @amount, :description => @order) if Array(@products).empty?
@fields[mappings[:success_text]] ||= DEFAULT_SUCCESS_TEXT
@fields.merge('RafraenUndirskrift' => signature)
end
|
98
99
100
|
# File 'lib/offsite_payments/integrations/valitor.rb', line 98
def format_amount(amount, currency)
OffsitePayments::CURRENCIES_WITHOUT_FRACTIONS.include?(currency) ? amount.to_f.round : sprintf("%.2f", amount)
end
|
63
64
65
|
# File 'lib/offsite_payments/integrations/valitor.rb', line 63
def
add_field 'SlokkvaHaus', '1'
end
|
#product(id, options = {}) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/offsite_payments/integrations/valitor.rb', line 67
def product(id, options={})
raise ArgumentError, "Product id #{id} is not an integer between 1 and 500" unless id.to_i > 0 && id.to_i <= 500
requires!(options, :amount, :description)
options.assert_valid_keys([:description, :quantity, :amount, :discount])
add_field("Vara_#{id}_Verd", format_amount(options[:amount], @fields[mappings[:currency]]))
add_field("Vara_#{id}_Fjoldi", options[:quantity] || "1")
add_field("Vara_#{id}_Lysing", options[:description]) if options[:description]
add_field("Vara_#{id}_Afslattur", options[:discount] || '0')
@products ||= []
@products << id.to_i
end
|
#signature ⇒ Object
82
83
84
85
86
87
88
89
90
|
# File 'lib/offsite_payments/integrations/valitor.rb', line 82
def signature
raise ArgumentError, "Security number not set" unless @security_number
parts = [@security_number, @fields['Adeinsheimild']]
@products.sort.uniq.each do |id|
parts.concat(["Vara_#{id}_Fjoldi", "Vara_#{id}_Verd", "Vara_#{id}_Afslattur"].collect{|e| @fields[e]})
end if @products
parts.concat(%w(VefverslunID Tilvisunarnumer SlodTokstAdGjaldfaera SlodTokstAdGjaldfaeraServerSide Gjaldmidill).collect{|e| @fields[e]})
Digest::MD5.hexdigest(parts.compact.join(''))
end
|