繁体   English   中英

欧洲的 Stripe Connect:使用支付意图向客户收费(React 和 Node js)

[英]Stripe Connect in Europe: Using Payment Intents to Charge Customers (React and 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"

有几件事让我感到困惑。

  1. 我的 clientSecret 代码格式如下:

pi_1FnrwXLkWxxxxxxxxxxxxxxx_secret_pGBi46eAzWxxxxxxxxxxxxxxx

从错误消息中,似乎只有一部分被发送到条带 api。 这是导致错误的原因吗?

  1. 两个条纹答案建议在前端使用以下代码。

    var stripe = Stripe(STRIPE_PUBLIC_KEY, { stripeAccount: "{{ connected_account }}" })

如果这是正确的,我该如何调整此代码以进行 react 以及我将它放在组件中的什么位置? 它向我抛出一个错误,因为它目前是。

Ref1: Code=50 “No such payment_intent” 当确认条带的支付意图时

Ref2: Stripe Connect PaymentIntent 错误:没有这样的 payment_intent

  1. 在 Stripe 文档的其他地方,它说使用 Payment Methods API 而不是 Payment Intents API 的令牌。 我应该完全放弃使用令牌吗?

我已经找到了这些问题的答案(在 Stripe 的帮助下)

一季度。 这不是问题

Q3。 不要在 Payment Intents API 中使用令牌。

Q2。 不要使用文档中的代码。

<StripeProvider
    apiKey={process.env.REACT_APP_API_STRIPE_PUBLISH}
    stripeAccount="{{ connected_account }}">

当我对帐户进行硬编码时,这对我有用,但是当我从后端获取连接的帐户 ID 并保存在 State 中时不起作用。 我通过有条件地渲染组件来让它工作。 我将 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>
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM