Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance log message for Bogus payments #5422

Merged
merged 2 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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)

Check warning on line 46 in core/app/models/spree/payment_method/bogus_credit_card.rb

View check run for this annotation

Codecov / codecov/patch

core/app/models/spree/payment_method/bogus_credit_card.rb#L46

Added line #L46 was not covered by tests
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,32 @@
end

def authorize(_money, credit_card, _options = {})
message_detail = " - #{__method__}"

Check warning on line 11 in core/app/models/spree/payment_method/simple_bogus_credit_card.rb

View check run for this annotation

Codecov / codecov/patch

core/app/models/spree/payment_method/simple_bogus_credit_card.rb#L11

Added line #L11 was not covered by tests

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' })

Check warning on line 14 in core/app/models/spree/payment_method/simple_bogus_credit_card.rb

View check run for this annotation

Codecov / codecov/patch

core/app/models/spree/payment_method/simple_bogus_credit_card.rb#L14

Added line #L14 was not covered by tests
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)

Check warning on line 16 in core/app/models/spree/payment_method/simple_bogus_credit_card.rb

View check run for this annotation

Codecov / codecov/patch

core/app/models/spree/payment_method/simple_bogus_credit_card.rb#L16

Added line #L16 was not covered by tests
end
end

def purchase(_money, credit_card, _options = {})
message_detail = " - #{__method__}"

Check warning on line 21 in core/app/models/spree/payment_method/simple_bogus_credit_card.rb

View check run for this annotation

Codecov / codecov/patch

core/app/models/spree/payment_method/simple_bogus_credit_card.rb#L21

Added line #L21 was not covered by tests

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' })

Check warning on line 24 in core/app/models/spree/payment_method/simple_bogus_credit_card.rb

View check run for this annotation

Codecov / codecov/patch

core/app/models/spree/payment_method/simple_bogus_credit_card.rb#L24

Added line #L24 was not covered by tests
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)

Check warning on line 26 in core/app/models/spree/payment_method/simple_bogus_credit_card.rb

View check run for this annotation

Codecov / codecov/patch

core/app/models/spree/payment_method/simple_bogus_credit_card.rb#L26

Added line #L26 was not covered by tests
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