Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
Merge pull request #173 from aldesantis/fix-try-void
Browse files Browse the repository at this point in the history
Fix Gateway#try_void expecting a respose code instead of a payment
  • Loading branch information
tvdeyen authored Jul 18, 2018
2 parents 9a06fa9 + a08ae6d commit da9343e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions app/models/solidus_paypal_braintree/gateway.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,16 @@ def cancel(response_code)
# Otherwise, we return false so Solidus creates a refund instead.
#
# @api public
# @param response_code [String] the transaction id of the payment to void
# @param payment [Spree::Payment] the payment to void
# @return [Response|FalseClass]
def try_void(response_code)
transaction = braintree.transaction.find(response_code)
def try_void(payment)
transaction = braintree.transaction.find(payment.response_code)
if transaction.status.in? SolidusPaypalBraintree::Gateway::VOIDABLE_STATUSES
# Sometimes Braintree returns a voidable status although it is not voidable anymore.
# When we try to void that transaction we receive an error and need to return false
# so Solidus can create a refund instead.
begin
void(response_code, nil, {})
void(payment.response_code, nil, {})
rescue ActiveMerchant::ConnectionError => e
e.message.match(NON_VOIDABLE_STATUS_ERROR_REGEXP) ? false : raise(e)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/solidus_paypal_braintree/gateway_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@
end

describe '#try_void' do
subject { gateway.try_void(source.token) }
subject { gateway.try_void(instance_double('Spree::Payment', response_code: source.token)) }

let(:transaction_request) do
class_double('Braintree::Transaction',
Expand Down

0 comments on commit da9343e

Please sign in to comment.