node.js - 欧洲的 Stripe Connect:使用支付意图向客户收费(React 和 Node js)
问题描述
我正在设置一个直接收费的标准条带连接帐户。
这对我使用带有令牌的费用 api 非常有效,但对我使用欧盟要求的支付意图 api 不起作用。
下面的代码在获取客户端密码方面起作用。
axios.post(`${process.env.REACT_APP_API}/paymentIntent`, stripeData).then(res => {console.log('paymentIntent res', res.data)
let clientSecret = res.data.clientSecret
this.props.stripe.createToken({}).then(res => {
console.log('stripe token', res)
if (!res.token) {
this.setState({
message:
"Invalid Credit Card. Your tickets have not been booked. You have not been charged"
})
}
else{
this.props.stripe.confirmCardPayment(
clientSecret,
{
payment_method: {
card: {
token: res.token.id
}
}
}
).then( res => {console.log(res)})
}
})
}
但我在控制台中收到以下错误:
Failed to load resource: the server responded with a status of 404 ()
error:
code: "resource_missing"
doc_url: "https://stripe.com/docs/error-codes/resource-missing"
message: "No such payment_intent: pi_1FnrwXLkWxxxxxxxxxxxxxxx"
param: "intent"
type: "invalid_request_error"
有几件事让我感到困惑。
- 我的 clientSecret 代码格式如下:
pi_1FnrwXLkWxxxxxxxxxxxxxxx_secret_pGBi46eAzWxxxxxxxxxxxxxxx
从错误消息中,它似乎只有一部分被发送到条带 api。这是导致错误的原因吗?
两个条纹答案建议在前端使用以下代码。
var stripe = Stripe(STRIPE_PUBLIC_KEY, { stripeAccount: "{{ connected_account }}" })
如果这是正确的,我该如何调整此代码以进行反应,以及将其放在组件中的什么位置?它现在给我一个错误。
Ref1: Code=50 “No such payment_intent” 当确认条带的支付意图时
Ref2:Stripe Connect PaymentIntent 错误:没有这样的 payment_intent
- 在 Stripe 文档的其他地方,它说使用 Payment Methods API 而不是使用 Payment Intents API 的令牌。我应该完全放弃使用令牌吗?
解决方案
我已经找到了这些问题的答案(在条纹的帮助下)
Q1。这不是问题
Q3。不要将令牌与 Payment Intents API 一起使用。
Q2。不要使用文档中的代码。利用
<StripeProvider
apiKey={process.env.REACT_APP_API_STRIPE_PUBLISH}
stripeAccount="{{ connected_account }}">
当我对帐户进行硬编码时,这对我有用,但当我从后端获取连接的帐户 ID 并保存在 State 中时,这不起作用。我通过有条件地渲染组件来让它工作。我将状态中的连接帐户初始化为''
并使用以下代码:
{this.state.userEvent.organiser.stripeAccountID !== '' &&
<StripeProvider
apiKey={process.env.REACT_APP_API_STRIPE_PUBLISH}
stripeAccount={this.state.userEvent.organiser.stripeAccountID}>
<Elements>
<CheckoutForm
total={this.displayTotal()}
applicationFee={this.displayAdminFee()}
currency={this.state.userEvent.currency}
eventTitle={this.state.userEvent.title}
purchaser={this.state.purchaser}
userEvent={this.state.userEvent}
numTicketsSought={this.state.userEvent.numTicketsSought}
/>
</Elements>
</StripeProvider>
}
推荐阅读
- python - 按列表中的第一个元素对嵌套列表进行排序
- pyspark - 使用 pyspark 验证不同行中同一列的数据
- html - 将元素拉伸到自动计算网格的末尾,而不仅仅是显式网格
- powershell - 同时使用桌面 Powershell 5.1 和 Powershell Core 6.1
- cmake - 在 cmake 中命名可执行文件
- tfvc - TFS2018 TFVC On-Premise Build Definition 如何在其他团队项目中包含解决方案
- java - Google Cloud Speech to Text 错误:java.lang.NoSuchMethodError:没有虚拟方法 build()Lcom/google/protobuf/GeneratedMessageLite;
- css - 使用 3d css 变换旋转对象时,如何保持方向不变,即“越过顶部”而不是向后
- hazelcast - Payara4/Hazelcast x 第一次失败的容错
- scala - 将文件从 Hdfs 复制到 Hdfs scala