Skip to content

Commit

Permalink
Fix bug where add_payment_method was incorrectly returned early if …
Browse files Browse the repository at this point in the history
…the payment value was a token (#5173)
  • Loading branch information
naashton committed Jul 12, 2024
1 parent 8dc76a4 commit 19d3979
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
32 changes: 17 additions & 15 deletions lib/active_merchant/billing/gateways/flex_charge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,24 +195,26 @@ def add_invoice(post, money, credit_card, options)
end

def add_payment_method(post, credit_card, address, options)
return unless credit_card.number.present?

payment_method = case credit_card
when String
{ Token: true, cardNumber: credit_card }
else
{
holderName: credit_card.name,
cardType: 'CREDIT',
cardBrand: credit_card.brand&.upcase,
cardCountry: address[:country],
expirationMonth: credit_card.month,
expirationYear: credit_card.year,
cardBinNumber: credit_card.number[0..5],
cardLast4Digits: credit_card.number[-4..-1],
cardNumber: credit_card.number,
Token: false
}
when CreditCard
if credit_card.number
{
holderName: credit_card.name,
cardType: 'CREDIT',
cardBrand: credit_card.brand&.upcase,
cardCountry: address[:country],
expirationMonth: credit_card.month,
expirationYear: credit_card.year,
cardBinNumber: credit_card.number[0..5],
cardLast4Digits: credit_card.number[-4..-1],
cardNumber: credit_card.number,
Token: false
}
else
{}
end
end
post[:paymentMethod] = payment_method.compact
end
Expand Down
10 changes: 10 additions & 0 deletions test/unit/gateways/flex_charge_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,16 @@ def test_purchase_using_card_with_no_number
assert_success response
end

def test_successful_purchase_with_token
payment = 'bb114473-43fc-46c4-9082-ea3dfb490509'

response = stub_comms(@gateway, :ssl_request) do
@gateway.purchase(@amount, payment, @options)
end.respond_with(successful_access_token_response, successful_purchase_response)

assert_success response
end

def test_failed_refund
response = stub_comms(@gateway, :ssl_request) do
@gateway.refund(@amount, 'reference', @options)
Expand Down

0 comments on commit 19d3979

Please sign in to comment.