Skip to content

Commit

Permalink
Merge pull request #5422 from nirnaeth/enhance-bogus-provider-logging
Browse files Browse the repository at this point in the history
Enhance log message for Bogus payments
  • Loading branch information
elia committed Dec 19, 2023
2 parents cef1755 + abb004b commit fb07e49
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
23 changes: 14 additions & 9 deletions core/app/models/spree/payment_method/bogus_credit_card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 12 additions & 6 deletions core/app/models/spree/payment_method/simple_bogus_credit_card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/spec/models/spree/refund_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fb07e49

Please sign in to comment.