From 50955d735c3a583a43f55350b8ec349972f10b27 Mon Sep 17 00:00:00 2001 From: Paulo Vilarinho Date: Thu, 17 Dec 2020 00:34:21 -0300 Subject: [PATCH 1/4] Add tests for internationalization of payment method clean name The clean name payment method tests now uses the internationalization string --- spec/models/spree/payment_method_spec.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/spec/models/spree/payment_method_spec.rb b/spec/models/spree/payment_method_spec.rb index 0d9fd451ac..46dc7f4860 100644 --- a/spec/models/spree/payment_method_spec.rb +++ b/spec/models/spree/payment_method_spec.rb @@ -58,14 +58,14 @@ module Spree end it "generates a clean name for known Payment Method types" do - expect(Spree::PaymentMethod::Check.clean_name).to eq("Cash/EFT/etc. (payments for which automatic validation is not required)") - expect(Spree::Gateway::Migs.clean_name).to eq("MasterCard Internet Gateway Service (MIGS)") - expect(Spree::Gateway::Pin.clean_name).to eq("Pin Payments") - expect(Spree::Gateway::PayPalExpress.clean_name).to eq("PayPal Express") - expect(Spree::Gateway::StripeConnect.clean_name).to eq("Stripe") - - # Testing else condition - expect(Spree::Gateway::BogusSimple.clean_name).to eq("BogusSimple") + expect(Spree::PaymentMethod::Check.clean_name).to eq(I18n.t("spree.admin.payment_methods.providers.check")) + expect(Spree::Gateway::Migs.clean_name).to eq(I18n.t("spree.admin.payment_methods.providers.migs")) + expect(Spree::Gateway::Pin.clean_name).to eq(I18n.t("spree.admin.payment_methods.providers.pin")) + expect(Spree::Gateway::PayPalExpress.clean_name).to eq(I18n.t("spree.admin.payment_methods.providers.paypalexpress")) + expect(Spree::Gateway::StripeConnect.clean_name).to eq(I18n.t("spree.admin.payment_methods.providers.stripeconnect")) + expect(Spree::Gateway::StripeSCA.clean_name).to eq(I18n.t("spree.admin.payment_methods.providers.stripesca")) + expect(Spree::Gateway::BogusSimple.clean_name).to eq(I18n.t("spree.admin.payment_methods.providers.bogussimple")) + expect(Spree::Gateway::Bogus.clean_name).to eq(I18n.t("spree.admin.payment_methods.providers.bogus")) end it "computes the amount of fees" do From 6225c83abb31505895dcf5941700b12e047c34ac Mon Sep 17 00:00:00 2001 From: Paulo Vilarinho Date: Thu, 17 Dec 2020 00:35:57 -0300 Subject: [PATCH 2/4] Add internationalization of payment method clean name The clean name payment method now uses the internationalization string --- app/models/spree/payment_method.rb | 20 +++----------------- config/locales/en.yml | 8 ++++++++ 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/app/models/spree/payment_method.rb b/app/models/spree/payment_method.rb index 049936c42a..11044cb8c3 100644 --- a/app/models/spree/payment_method.rb +++ b/app/models/spree/payment_method.rb @@ -110,23 +110,9 @@ module Spree end def self.clean_name - case name - when "Spree::PaymentMethod::Check" - "Cash/EFT/etc. (payments for which automatic validation is not required)" - when "Spree::Gateway::Migs" - "MasterCard Internet Gateway Service (MIGS)" - when "Spree::Gateway::Pin" - "Pin Payments" - when "Spree::Gateway::StripeConnect" - "Stripe" - when "Spree::Gateway::StripeSCA" - "Stripe SCA" - when "Spree::Gateway::PayPalExpress" - "PayPal Express" - else - i = name.rindex('::') + 2 - name[i..-1] - end + i = name.rindex('::') + 2 + i18n_name = "spree.admin.payment_methods.providers." + name[i..-1].downcase + I18n.t(i18n_name) end private diff --git a/config/locales/en.yml b/config/locales/en.yml index 495a94ea50..c3b846af74 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3431,6 +3431,14 @@ See the %{link} to find out more about %{sitename}'s features and to start using deactivation_warning: "De-activating a payment method can make the payment method disappear from your list. Alternatively, you can hide a payment method from the checkout page by setting the option 'Display' to 'back office only'." providers: provider: "Provider" + check: "Cash/EFT/etc. (payments for which automatic validation is not required)" + migs: "MasterCard Internet Gateway Service (MIGS)" + pin: "Pin Payments" + paypalexpress: "PayPal Express" + stripeconnect: "Stripe" + stripesca: "Stripe SCA" + bogus: "Bogus" + bogussimple: "BogusSimple" payments: source_forms: stripe: From 92649ca97c9f820d1e082d0d75d682890e75d648 Mon Sep 17 00:00:00 2001 From: Paulo Vilarinho Date: Thu, 17 Dec 2020 10:06:41 -0300 Subject: [PATCH 3/4] Refactor payment method clean name method --- app/models/spree/payment_method.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/models/spree/payment_method.rb b/app/models/spree/payment_method.rb index 11044cb8c3..a3445a6048 100644 --- a/app/models/spree/payment_method.rb +++ b/app/models/spree/payment_method.rb @@ -110,9 +110,8 @@ module Spree end def self.clean_name - i = name.rindex('::') + 2 - i18n_name = "spree.admin.payment_methods.providers." + name[i..-1].downcase - I18n.t(i18n_name) + I18n_key = "spree.admin.payment_methods.providers." + name.demodulize.downcase + I18n.t(I18n_key) end private From 85663d15d1de427f4945064d82fd7f8217ca372b Mon Sep 17 00:00:00 2001 From: Paulo Vilarinho Date: Thu, 17 Dec 2020 10:14:54 -0300 Subject: [PATCH 4/4] Fix dynamic constant assignment issues --- app/models/spree/payment_method.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/spree/payment_method.rb b/app/models/spree/payment_method.rb index a3445a6048..d519e3284a 100644 --- a/app/models/spree/payment_method.rb +++ b/app/models/spree/payment_method.rb @@ -110,8 +110,8 @@ module Spree end def self.clean_name - I18n_key = "spree.admin.payment_methods.providers." + name.demodulize.downcase - I18n.t(I18n_key) + i18n_key = "spree.admin.payment_methods.providers." + name.demodulize.downcase + I18n.t(i18n_key) end private