-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade Stripe to support Bancontact (#177)
- Loading branch information
1 parent
45656d2
commit e8d042e
Showing
5 changed files
with
221 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import { describePayment } from './utils'; | ||
import { UnableAuthenticatePaymentMethodError } from '../../src/utils/errors'; | ||
import StripeBancontactPayment from '../../src/payment/bancontact/stripe'; | ||
|
||
jest.mock('../../src/utils/stripe', () => ({ | ||
getBancontactConfirmationDetails: () => 'Test confirmation details', | ||
})); | ||
|
||
describePayment( | ||
'payment/bancontact/stripe', | ||
(request, options, paymentMock) => { | ||
let params; | ||
let methods; | ||
|
||
const confirmBancontactSetup = jest.fn(() => ({})); | ||
const retrieveSetupIntent = jest.fn(() => ({ | ||
setupIntent: { | ||
id: 'seti_bancontact_test', | ||
}, | ||
})); | ||
|
||
beforeEach(() => { | ||
params = {}; | ||
methods = { | ||
card: { | ||
publishable_key: 'test_stripe_publishable_key', | ||
}, | ||
bancontact: {}, | ||
}; | ||
|
||
global.window.Stripe = jest.fn(() => ({ | ||
confirmBancontactSetup: confirmBancontactSetup, | ||
retrieveSetupIntent: retrieveSetupIntent, | ||
})); | ||
}); | ||
|
||
describe('#tokenize', () => { | ||
it('should create and confirm Stripe Bancontact Setup Intent', async () => { | ||
paymentMock.getCart.mockImplementationOnce(() => | ||
Promise.resolve({ | ||
account_id: 'test_account_id', | ||
}), | ||
); | ||
|
||
const payment = new StripeBancontactPayment( | ||
request, | ||
options, | ||
params, | ||
methods, | ||
); | ||
|
||
await payment.tokenize(); | ||
|
||
expect(global.window.Stripe).toHaveBeenCalledWith( | ||
'test_stripe_publishable_key', | ||
); | ||
expect(paymentMock.createIntent).toHaveBeenCalledWith({ | ||
account_id: 'test_account_id', | ||
gateway: 'stripe', | ||
action: 'setup', | ||
intent: { | ||
payment_method_types: ['bancontact'], | ||
usage: 'off_session', | ||
}, | ||
}); | ||
expect(confirmBancontactSetup).toHaveBeenCalledWith( | ||
'test_stripe_client_secret', | ||
'Test confirmation details', | ||
); | ||
}); | ||
}); | ||
|
||
describe('#handleRedirect', () => { | ||
it('should handle redirect with succeeded redirect status', async () => { | ||
const queryParams = { | ||
redirect_status: 'succeeded', | ||
payment_intent_client_secret: 'test_intent_client_secret', | ||
}; | ||
const payment = new StripeBancontactPayment( | ||
request, | ||
options, | ||
params, | ||
methods, | ||
); | ||
|
||
await payment.handleRedirect(queryParams); | ||
|
||
expect(paymentMock.updateCart).toHaveBeenCalledWith({ | ||
billing: { | ||
method: 'bancontact', | ||
bancontact: { token: 'seti_bancontact_test' }, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should throw an error when the redirect status is not "succeeded"', async () => { | ||
const queryParams = { | ||
redirect_status: 'failed', | ||
}; | ||
const payment = new StripeBancontactPayment( | ||
request, | ||
options, | ||
params, | ||
methods, | ||
); | ||
|
||
await expect(payment.handleRedirect(queryParams)).rejects.toThrow( | ||
UnableAuthenticatePaymentMethodError, | ||
); | ||
}); | ||
}); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters