【发布时间】:2019-11-09 14:13:44
【问题描述】:
我正在使用 react-stripe-checkout 表单来收集客户和卡信息并获取令牌。到目前为止,这工作得很好。 弹出对话框完成后,调用 onToken 函数将令牌发送到后端,问题是我需要状态中的另一个信息发送到后端,我不知道如何访问它
我无法访问 this.state
async onToken(token){
console.log(this.state) //Error, state undefined
console.log('Stripe Token: ', token)
var result = await API.post("videos", "videos/offer/"+this.state.videoid, {
body: {'price': this.state.pricePerMin, 'token': token}
});
}
渲染函数:
StripeCheckout
stripeKey=""
name=""
token={this.onToken}
label={'Pay ' + this.state.price + '€ and start video analysis'}
description={this.state.price+'€ (' + this.state.minutesToPay + ' x ' + this.state.pricePerMin + '€)'}
amount={10 * 100} // cents
currency="EUR"
locale="de"
shippingAddress={false}
billingAddress={true}
// Note: enabling both zipCode checks and billing or shipping address will
// cause zipCheck to be pulled from billing address (set to shipping if none provided).
zipCode={true}
alipay={false} // accept Alipay (default false)
bitcoin={false} // accept Bitcoins (default false)
allowRememberMe // "Remember Me" option (default true)
/>
要进行 api 调用,我需要 onToken 函数中状态的 videoid。
【问题讨论】:
标签: node.js reactjs stripe-payments