Skip to content

Commit

Permalink
Uses stripe.handleNextAction for payment intents
Browse files Browse the repository at this point in the history
  • Loading branch information
chrissrogers committed Nov 21, 2024
1 parent 6b9d477 commit 1778bd4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
21 changes: 13 additions & 8 deletions lib/recurly/risk/three-d-secure/strategy/stripe.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,20 @@ export default class StripeStrategy extends ThreeDSecureStrategy {

this.whenReady(() => {
const isPaymentIntent = this.stripeClientSecret.indexOf('pi') === 0;
const handleAction = isPaymentIntent ? this.stripe.handleCardAction : this.stripe.confirmCardSetup;

handleAction(this.stripeClientSecret).then(result => {
if (result.error) {
throw result.error;
}
const { id } = result.paymentIntent || result.setupIntent;
this.emit('done', { id });
}).catch(err => this.threeDSecure.error('3ds-auth-error', { cause: err }));
(() => (
isPaymentIntent
? this.stripe.handleNextAction({ clientSecret: this.stripeClientSecret })
: this.stripe.confirmCardSetup(this.stripeClientSecret)
))()
.then(result => {
if (result.error) {
throw result.error;
}
const { id } = result.paymentIntent || result.setupIntent;
this.emit('done', { id });
})
.catch(err => this.threeDSecure.error('3ds-auth-error', { cause: err }));
});
}

Expand Down
8 changes: 4 additions & 4 deletions test/unit/risk/three-d-secure/strategy/stripe.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('StripeStrategy', function () {
setupIntent: { id: 'seti-test-id', test: 'result', consistingOf: 'arbitrary-values' }
};
this.stripe = {
handleCardAction: sinon.stub().resolves(this.paymentIntentResult),
handleNextAction: sinon.stub().resolves(this.paymentIntentResult),
confirmCardSetup: sinon.stub().resolves(this.setupIntentResult)
};
window.Stripe = sinon.spy(publishableKey => this.stripe);
Expand Down Expand Up @@ -78,8 +78,8 @@ describe('StripeStrategy', function () {
it('instructs Stripe.js to handle the card action using the client secret', function () {
const { strategy, target, stripe } = this;
strategy.attach(target);
assert(stripe.handleCardAction.calledOnce);
assert(stripe.handleCardAction.calledWithExactly('pi-test-stripe-client-secret'));
assert(stripe.handleNextAction.calledOnce);
assert(stripe.handleNextAction.calledWithExactly({ clientSecret: 'pi-test-stripe-client-secret' }));
});

it('emits done with the paymentIntent result', function (done) {
Expand All @@ -95,7 +95,7 @@ describe('StripeStrategy', function () {
beforeEach(function () {
const { strategy } = this;
this.exampleResult = { error: { example: 'error', for: 'testing' } };
strategy.stripe.handleCardAction = sinon.stub().resolves(this.exampleResult);
strategy.stripe.handleNextAction = sinon.stub().resolves(this.exampleResult);
});

it('emits an error on threeDSecure', function (done) {
Expand Down

0 comments on commit 1778bd4

Please sign in to comment.