簡體   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