Skip to content

Commit

Permalink
fix(apple pay): Do not teardown Braintree on cancel
Browse files Browse the repository at this point in the history
`teardown` completely removes the Braintree instance which will cause
issues if the client cancels and tries to initialize a payment. This is
not needed as beginning a session does not reinitialize the BT client,
so we can have successive attempts on the same client.

Fixes the `performValidation cannot be called after teardown` error on
subsequent tries.
  • Loading branch information
cbarton committed Apr 18, 2023
1 parent 54a5cda commit 720e536
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
13 changes: 4 additions & 9 deletions lib/recurly/apple-pay/apple-pay.braintree.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ export class ApplePayBraintree extends ApplePay {
event.payment.gatewayToken = braintreeToken;
return super.token(event);
})
.catch(err => this.error('apple-pay-payment-failure', err));
.catch(err => {
this.session.completePayment({ status: this.session.STATUS_FAILURE });
return this.error('apple-pay-payment-failure', err);
});
}

mapPaymentData (event) {
Expand All @@ -81,12 +84,4 @@ export class ApplePayBraintree extends ApplePay {
},
};
}

onCancel (event) {
debug('Teardown payment', event);

this.braintree.applePay
.teardown()
.finally(() => super.onCancel(event));
}
}
10 changes: 0 additions & 10 deletions test/unit/apple-pay.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ const getBraintreeStub = () => ({
create: sinon.stub().resolves({
performValidation: sinon.stub().resolves('MERCHANT_SESSION'),
tokenize: sinon.stub().resolves('TOKENIZED_PAYLOAD'),
teardown: sinon.stub().resolves('TEARDOWN'),
}),
},
});
Expand Down Expand Up @@ -1309,15 +1308,6 @@ function applePayTest (integrationType, requestMethod) {
});
});
});

if (isBraintreeIntegration) {
it('teardown braintree', function (done) {
this.applePay.on('cancel', ensureDone(done, () => {
assert.ok(this.applePay.braintree.applePay.teardown.called);
}));
this.applePay.session.oncancel('event');
});
}
});
});
});
Expand Down

0 comments on commit 720e536

Please sign in to comment.