Class: OffsitePayments::Integrations::CheckoutFinland::Helper
- Includes:
- ActiveUtils::PostsData
- Defined in:
- lib/offsite_payments/integrations/checkout_finland.rb
Instance Attribute Summary
Attributes inherited from Helper
Instance Method Summary collapse
-
#add_field(name, value) ⇒ Object
Apply parameter length limitations recommended by Checkout.fi.
-
#check_param_length(name, value) ⇒ Object
API parameter length limitations specified by Checkout.fi Parameters longer than this cause the HTTP POST to fail.
-
#form_fields ⇒ Object
Add MAC to form fields.
-
#generate_md5string ⇒ Object
Calculate MAC.
-
#initialize(order, account, options = {}) ⇒ Helper
constructor
A new instance of Helper.
- #md5secret(value) ⇒ Object
Methods inherited from Helper
#add_fields, #add_raw_html_field, #billing_address, #form_method, inherited, mapping, #raw_html_fields, #shipping_address, #test?
Methods included from MoneyCompatibility
Constructor Details
#initialize(order, account, options = {}) ⇒ Helper
Returns a new instance of Helper.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/offsite_payments/integrations/checkout_finland.rb', line 16 def initialize(order, account, = {}) md5secret .delete(:credential2) super # Add default fields add_field("VERSION", "0001") # API version add_field("ALGORITHM", "3") # Return MAC version (3 is HMAC-SHA256) add_field("TYPE", "0") add_field("DEVICE", "1") # Offsite payment by default end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class OffsitePayments::Helper
Instance Method Details
#add_field(name, value) ⇒ Object
Apply parameter length limitations recommended by Checkout.fi
37 38 39 40 |
# File 'lib/offsite_payments/integrations/checkout_finland.rb', line 37 def add_field(name, value) return if name.blank? || value.blank? @fields[name.to_s] = check_param_length(name_to_s, value.to_s) end |
#check_param_length(name, value) ⇒ Object
API parameter length limitations specified by Checkout.fi Parameters longer than this cause the HTTP POST to fail
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/offsite_payments/integrations/checkout_finland.rb', line 44 def check_param_length(name, value) # Soft limitations, fields that can be clipped max_length_substring = { "FIRSTNAME" => 40, "FAMILYNAME" => 40, "ADDRESS" => 40, "POSTCODE" => 14, "POSTOFFICE" => 18, "MESSAGE" => 1000, "EMAIL" => 200, "PHONE" => 30 } # Hard limitations, fields that cannot be clipped max_length_exception = { "RETURN" => 300, "CANCEL" => 300, "REJECT" => 300, "DELAYED" => 300, "STAMP" => 20, "AMOUNT" => 8, "REFERENCE" => 20, "CONTENT" => 2, "LANGUAGE" => 2, "MERCHANT" => 20, "COUNTRY" => 3, "CURRENCY" => 3, "DELIVERY_DATE" => 8 } if max_length_substring.include? name return value.to_s[0, max_length_substring[name]] end if max_length_exception.include? name if value.to_s.length > max_length_exception[name] raise ArgumentError, "Field #{name} length #{value.length} is longer than permitted by provider API. Maximum length #{max_length_exception[name]}." else return value end end value end |
#form_fields ⇒ Object
Add MAC to form fields
32 33 34 |
# File 'lib/offsite_payments/integrations/checkout_finland.rb', line 32 def form_fields @fields.merge("MAC" => generate_md5string) end |
#generate_md5string ⇒ Object
Calculate MAC
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/offsite_payments/integrations/checkout_finland.rb', line 63 def generate_md5string fields = [@fields["VERSION"], @fields["STAMP"], @fields["AMOUNT"], @fields["REFERENCE"], @fields["MESSAGE"], @fields["LANGUAGE"], @fields["MERCHANT"], @fields["RETURN"], @fields["CANCEL"], @fields["REJECT"], @fields["DELAYED"], @fields["COUNTRY"], @fields["CURRENCY"], @fields["DEVICE"], @fields["CONTENT"], @fields["TYPE"], @fields["ALGORITHM"], @fields["DELIVERY_DATE"], @fields["FIRSTNAME"], @fields["FAMILYNAME"], @fields["ADDRESS"], @fields["POSTCODE"], @fields["POSTOFFICE"], @md5secret] fields = fields.join("+") Digest::MD5.hexdigest(fields).upcase end |
#md5secret(value) ⇒ Object
27 28 29 |
# File 'lib/offsite_payments/integrations/checkout_finland.rb', line 27 def md5secret(value) @md5secret = value end |