【发布时间】:2019-06-04 00:58:09
【问题描述】:
所以我尝试提交用户输入其信用卡的订单。
为此,我调用 order 方法,该方法对 Stripe (createSource) 进行 API 调用以创建支付来源。然后我使用 axios 将订单参数发布到我的 Rails 后端,其中我发送刚刚创建的源的 id (source.id)。
async order() {
let {source} = await this.props.stripe.createSource({type: 'card', currency: 'eur', owner: {email: this.props.currentUserEmail}});
axios.post("/orders", {sourceId: source.id,
mealId: this.props.mealId,
price: this.state.mealPrice,
selectedPickupTime: this.state.selectedPickupTime
})
}
问题是,我认为当 axios 将 post 请求发送到后端时尚未创建源,因为我收到以下错误:
Unhandled Rejection (TypeError): Cannot read property 'id' of undefined for source.id
如何更改它并等待在 axios 发送发布请求之前创建源?
【问题讨论】:
标签: javascript reactjs stripe-payments axios