mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-26 06:47:17 +10:00
Use Stripe v3 API to create bank account tokens
This commit is contained in:
parent
8709a7b225
commit
4a620ef2ff
2 changed files with 11 additions and 26 deletions
|
|
@ -10,7 +10,6 @@ import config from '../../config';
|
|||
import {
|
||||
BANK_ACCOUNT_INPUTS,
|
||||
cleanedString,
|
||||
createToken,
|
||||
formatFieldMessage,
|
||||
requiredInputs,
|
||||
mapInputsToStripeAccountKeys,
|
||||
|
|
@ -140,7 +139,17 @@ class TokenInputFieldComponent extends Component {
|
|||
accountData = { ...accountData, ...inputValueObj };
|
||||
});
|
||||
|
||||
createToken(accountData)
|
||||
// https://stripe.com/docs/stripe-js/reference#collecting-bank-account-details
|
||||
this.stripe
|
||||
.createToken('bank_account', accountData)
|
||||
.then(result => {
|
||||
if (result.error) {
|
||||
const e = new Error(result.error.message);
|
||||
e.stripeError = result.error;
|
||||
throw e;
|
||||
}
|
||||
return result.token.id;
|
||||
})
|
||||
.then(token => {
|
||||
const changedValues = inputsNeeded.filter(
|
||||
inputType => values[inputType] !== cleanedString(this.state[inputType].value)
|
||||
|
|
|
|||
|
|
@ -19,29 +19,6 @@ export const BANK_ACCOUNT_INPUTS = [BSB, SORT_CODE, ROUTING_NUMBER, ACCOUNT_NUMB
|
|||
|
||||
export const supportedCountries = config.stripe.supportedCountries.map(c => c.code);
|
||||
|
||||
/**
|
||||
* Create a single-use token from the given bank account data
|
||||
*
|
||||
* See: https://stripe.com/docs/stripe.js#collecting-bank-account-details
|
||||
*
|
||||
* @param {Object} data - bank account data sent to Stripe
|
||||
*
|
||||
* @return {Promise<String>} Promise that resolves with the bank
|
||||
* account token or rejects when the token creation fails
|
||||
*/
|
||||
export const createToken = data =>
|
||||
new Promise((resolve, reject) => {
|
||||
window.Stripe.bankAccount.createToken(data, (status, response) => {
|
||||
if (response.error) {
|
||||
const e = new Error(response.error.message);
|
||||
e.stripeError = response.error;
|
||||
reject(e);
|
||||
} else {
|
||||
resolve(response.id);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Country specific Stripe configurations
|
||||
*
|
||||
|
|
@ -132,7 +109,6 @@ export const translateStripeError = (country, intl, stripeError) => {
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Map inputs to correct Stripe keys
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue