From 8b0b6d5fca3853787e61c5e8e72fc775756e18f7 Mon Sep 17 00:00:00 2001 From: Bart de Water Date: Thu, 6 Apr 2017 12:04:29 -0400 Subject: [PATCH] Add 2Checkout language support --- lib/offsite_payments/helper.rb | 4 ++++ lib/offsite_payments/integrations/two_checkout.rb | 4 ++++ .../integrations/two_checkout/two_checkout_helper_test.rb | 2 ++ 3 files changed, 10 insertions(+) diff --git a/lib/offsite_payments/helper.rb b/lib/offsite_payments/helper.rb index fe99e189a..62207366c 100644 --- a/lib/offsite_payments/helper.rb +++ b/lib/offsite_payments/helper.rb @@ -97,6 +97,10 @@ def lookup_country_code(name_or_code, format = country_format) name_or_code end + def language_from_locale(locale) + locale[0..1].downcase + end + def method_missing(method_id, *args) method_id = method_id.to_s.gsub(/=$/, '').to_sym # Return and do nothing if the mapping was not found. This allows diff --git a/lib/offsite_payments/integrations/two_checkout.rb b/lib/offsite_payments/integrations/two_checkout.rb index 9fdba9822..c18be7a54 100644 --- a/lib/offsite_payments/integrations/two_checkout.rb +++ b/lib/offsite_payments/integrations/two_checkout.rb @@ -114,6 +114,10 @@ def third_party_cart(params = {}) add_field("c_#{key}_#{line_item_id}", value) end end + + def locale(locale) + add_field 'lang', language_from_locale(locale) + end end class Notification < OffsitePayments::Notification diff --git a/test/unit/integrations/two_checkout/two_checkout_helper_test.rb b/test/unit/integrations/two_checkout/two_checkout_helper_test.rb index ac4c49ecc..06f8e8248 100644 --- a/test/unit/integrations/two_checkout/two_checkout_helper_test.rb +++ b/test/unit/integrations/two_checkout/two_checkout_helper_test.rb @@ -23,12 +23,14 @@ def test_extra_helper_fields @helper.return_url 'https://return.url/' @helper.cart_type 'shopify' @helper.purchase_step 'payment-method' + @helper.locale 'en-US' assert_field 'currency_code', 'ZAR' assert_field 'cart_order_id', '123' assert_field 'x_receipt_link_url', 'https://return.url/' assert_field '2co_cart_type', 'shopify' assert_field 'purchase_step', 'payment-method' + assert_field 'lang', 'en' end def test_customer_fields