mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-31 02:26:50 +10:00
Remove whitespace from account/routing nums before sending to Stripe
Stripe seems to fail at least if the account number is copy pasted to the input, and contains spaces (like in the placeholder text). The solution is just to remove any whitespace from the numbers before sending them to the Stripe API.
This commit is contained in:
parent
325acedf1b
commit
cfbcc8589d
1 changed files with 10 additions and 2 deletions
|
|
@ -21,6 +21,11 @@ const BLUR_TIMEOUT = 100;
|
|||
|
||||
const DEBOUNCE_WAIT_TIME = 1000;
|
||||
|
||||
// Remove all whitespace from the given string
|
||||
const cleanedString = str => {
|
||||
return str.replace(/\s/g, '');
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a single-use token from the given bank account data
|
||||
*
|
||||
|
|
@ -173,10 +178,13 @@ class TokenInputFieldComponent extends Component {
|
|||
const accountData = {
|
||||
country: this.props.country,
|
||||
currency: this.props.currency,
|
||||
account_number: accountNumber,
|
||||
|
||||
// Stripe fails if there are spaces within the number, this is
|
||||
// why we have to clean it up first.
|
||||
account_number: cleanedString(accountNumber),
|
||||
};
|
||||
if (routingNumberRequired) {
|
||||
accountData.routing_number = routingNumber;
|
||||
accountData.routing_number = cleanedString(routingNumber);
|
||||
}
|
||||
createToken(accountData)
|
||||
.then(token => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue