From b19e5dc2d168906914cdd219a0a52a4da8896800 Mon Sep 17 00:00:00 2001 From: Monica Giambitto Date: Fri, 6 Oct 2023 13:59:48 +0200 Subject: [PATCH 1/2] Enhance log message for Bogus payments Fixes [#4867](https://github.com/solidusio/solidus/issues/4867). For both bogus_credit_card and simple_bogus_credit_card, identifies the method from which the message is being created and adds that information to the log. --- .../spree/payment_method/bogus_credit_card.rb | 23 +++++++++++-------- .../simple_bogus_credit_card.rb | 18 ++++++++++----- core/spec/models/spree/refund_spec.rb | 2 +- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/core/app/models/spree/payment_method/bogus_credit_card.rb b/core/app/models/spree/payment_method/bogus_credit_card.rb index a5983b04c9d..2b37dd271e6 100644 --- a/core/app/models/spree/payment_method/bogus_credit_card.rb +++ b/core/app/models/spree/payment_method/bogus_credit_card.rb @@ -29,39 +29,44 @@ def create_profile(payment) def authorize(_money, credit_card, _options = {}) profile_id = credit_card.gateway_customer_profile_id + message_detail = " - #{__method__}" if VALID_CCS.include?(credit_card.number) || (profile_id && profile_id.starts_with?('BGS-')) - ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE, {}, test: true, authorization: AUTHORIZATION_CODE, avs_result: { code: 'D' }) + ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE + message_detail, {}, test: true, authorization: AUTHORIZATION_CODE, avs_result: { code: 'D' }) else - ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE, { message: FAILURE_MESSAGE }, test: true) + ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE + message_detail, { message: FAILURE_MESSAGE + message_detail }, test: true) end end def purchase(_money, credit_card, _options = {}) profile_id = credit_card.gateway_customer_profile_id + message_detail = " - #{__method__}" if VALID_CCS.include?(credit_card.number) || (profile_id && profile_id.starts_with?('BGS-')) - ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE, {}, test: true, authorization: AUTHORIZATION_CODE, avs_result: { code: 'M' }) + ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE + message_detail, {}, test: true, authorization: AUTHORIZATION_CODE, avs_result: { code: 'M' }) else - ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE, message: FAILURE_MESSAGE, test: true) + ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE + message_detail, message: FAILURE_MESSAGE + message_detail, test: true) end end def credit(_money, _credit_card, _response_code, _options = {}) - ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE, {}, test: true, authorization: AUTHORIZATION_CODE) + message_detail = " - #{__method__}" + ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE + message_detail, {}, test: true, authorization: AUTHORIZATION_CODE) end def capture(_money, authorization, _gateway_options) + message_detail = " - #{__method__}" if authorization == '12345' - ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE, {}, test: true) + ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE + message_detail, {}, test: true) else - ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE, error: FAILURE_MESSAGE, test: true) + ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE + message_detail, error: FAILURE_MESSAGE + message_detail, test: true) end end def void(_response_code, _credit_card, options = {}) + message_detail = " - #{__method__}" if options[:originator].completed? - ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE, {}, test: true, authorization: AUTHORIZATION_CODE) + ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE + message_detail, {}, test: true, authorization: AUTHORIZATION_CODE) else - ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE, {}, test: true, authorization: AUTHORIZATION_CODE) + ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE + message_detail, {}, test: true, authorization: AUTHORIZATION_CODE) end end diff --git a/core/app/models/spree/payment_method/simple_bogus_credit_card.rb b/core/app/models/spree/payment_method/simple_bogus_credit_card.rb index 5065300b033..46372c69047 100644 --- a/core/app/models/spree/payment_method/simple_bogus_credit_card.rb +++ b/core/app/models/spree/payment_method/simple_bogus_credit_card.rb @@ -8,26 +8,32 @@ def payment_profiles_supported? end def authorize(_money, credit_card, _options = {}) + message_detail = " - #{__method__}" + if VALID_CCS.include? credit_card.number - ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE, {}, test: true, authorization: AUTHORIZATION_CODE, avs_result: { code: 'A' }) + ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE + message_detail, {}, test: true, authorization: AUTHORIZATION_CODE, avs_result: { code: 'A' }) else - ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE, { message: FAILURE_MESSAGE }, test: true) + ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE + message_detail, { message: FAILURE_MESSAGE }, test: true) end end def purchase(_money, credit_card, _options = {}) + message_detail = " - #{__method__}" + if VALID_CCS.include? credit_card.number - ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE, {}, test: true, authorization: AUTHORIZATION_CODE, avs_result: { code: 'A' }) + ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE + message_detail, {}, test: true, authorization: AUTHORIZATION_CODE, avs_result: { code: 'A' }) else - ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE, message: FAILURE_MESSAGE, test: true) + ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE + message_detail, message: FAILURE_MESSAGE, test: true) end end def void(_response_code, options = {}) + message_detail = " - #{__method__}" + if options[:originator].completed? - ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE, {}, test: true, authorization: AUTHORIZATION_CODE) + ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE + message_detail, {}, test: true, authorization: AUTHORIZATION_CODE) else - ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE, {}, test: true, authorization: AUTHORIZATION_CODE) + ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE + message_detail, {}, test: true, authorization: AUTHORIZATION_CODE) end end end diff --git a/core/spec/models/spree/refund_spec.rb b/core/spec/models/spree/refund_spec.rb index 1cf6ac4acff..10ff8c13917 100644 --- a/core/spec/models/spree/refund_spec.rb +++ b/core/spec/models/spree/refund_spec.rb @@ -63,7 +63,7 @@ expect { subject }.to change { refund.perform_response }.from(nil) expect(refund.perform_response).to be_a(ActiveMerchant::Billing::Response) - expect(refund.perform_response.message).to eq(Spree::PaymentMethod::BogusCreditCard::SUCCESS_MESSAGE) + expect(refund.perform_response.message).to include(Spree::PaymentMethod::BogusCreditCard::SUCCESS_MESSAGE) end it "sets a transaction_id" do From abb004bacbf873da1b709354bcf61d0c4bbf02f5 Mon Sep 17 00:00:00 2001 From: Monica Giambitto Date: Fri, 6 Oct 2023 14:20:18 +0200 Subject: [PATCH 2/2] rubocop offense: remove double space around + operator --- core/app/models/spree/payment_method/bogus_credit_card.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/app/models/spree/payment_method/bogus_credit_card.rb b/core/app/models/spree/payment_method/bogus_credit_card.rb index 2b37dd271e6..85e24734ce6 100644 --- a/core/app/models/spree/payment_method/bogus_credit_card.rb +++ b/core/app/models/spree/payment_method/bogus_credit_card.rb @@ -33,7 +33,7 @@ def authorize(_money, credit_card, _options = {}) if VALID_CCS.include?(credit_card.number) || (profile_id && profile_id.starts_with?('BGS-')) ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE + message_detail, {}, test: true, authorization: AUTHORIZATION_CODE, avs_result: { code: 'D' }) else - ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE + message_detail, { message: FAILURE_MESSAGE + message_detail }, test: true) + ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE + message_detail, { message: FAILURE_MESSAGE + message_detail }, test: true) end end