I'm using Stripe Checkout in my React App. Somehow I'm not passing the properties to my onToken function correctly as I'm getting not defined errors.
I eventually need to send a bunch of props, but for now just trying to get it to work correctly.
import axios from 'axios'
import React from 'react'
import StripeCheckout from 'react-stripe-checkout';
const PAYMENT_SERVER_URL = '3RD_PARTY_SERVER';
const CURRENCY = 'USD';
export default class Stripe25 extends React.Component {
onToken = (token) => {
axios.post(PAYMENT_SERVER_URL,
{
description,
source: token.id,
currency: CURRENCY,
amount: amount
})
.then(successPayment)
.catch(errorPayment);
}
render() {
return (
<StripeCheckout
token={this.onToken}
stripeKey="STRIPE_PUBLIC_KEY"
name=""
description=""
image=""
panelLabel="Donate"
amount={2500} // cents
currency="USD"
locale="auto"
zipCode={false}
billingAddress={true}
>
<button className="btn btn-primary">
$25
</button>
</StripeCheckout>
)
}
}
Try changing
source: token.idtosource: token && token.id.The token may not yet be defined when you are trying to set the id. This is often an issue with dot chaining in an async environment.