【问题标题】:Saving a card to charge a connected stripe account later in EU (using SCA). React & Node稍后在欧盟保存一张卡以向连接的条带帐户收费(使用 SCA)。反应和节点
【发布时间】:2020-01-24 20:54:19
【问题描述】:

我的代码正在保存客户的卡并稍后在我的条带帐户中向他们收费。但是,当我修改代码以在已连接的条带帐户上对卡进行收费时,它将无法正常工作。

请注意,我在欧盟,所以我必须使用强客户身份验证 - 我不能使用令牌。

相关前端代码为:

        const cardElement = this.props.elements.getElement('card');

    axios.post(`${process.env.REACT_APP_API}/saveCardDetails`, {stripeAccountID: this.props.stripeAccountID}).then(res => {


    this.props.stripe.confirmCardSetup(res.data.client_secret, {
        payment_method: {
    card: cardElement,
  },
    },{
    stripe_account: this.props.stripeAccountID,
    }
).then( confirmCardSetupRes => {..})

相关后端代码为:

    //saveCardDetails controller

module.exports = (req, res) => {

    stripe.setupIntents.create().then(intent => {
        console.log('intent.client_secret', intent.client_secret)
        res.send({client_secret: intent.client_secret})
    })
}

//code to charge the saved card
const chargeSavedCard = (customerStripeID, price, currency, eventTitle, applicationFee, organiserstripeAccountID) => {


    stripe.paymentMethods.list({
        customer: customerStripeID,
        type: 'card',
    }).then(paymentMethods => {
        stripe.paymentIntents.create({
            amount: Math.round(price * 100),
            currency: currency,
            customer: customerStripeID,
            payment_method: paymentMethods.data[0].id,
            off_session: true,
            confirm: true,
            application_fee_amount: Math.round(applicationFee)
        }
        ,{
        stripe_account: organiserstripeAccountID,
        }

    ).then(stripeRes => {.......})

抛出以下错误:

{ Error: No such PaymentMethod: pm_1G4YYVCFzSpFw85fXVcZj0hX; OAuth key or Stripe-Account header was used but API request was provided with a platform-owned payment method ID. Please ensure that the provided payment method matches the specified account.

我不明白为什么我的代码没有在连接的帐户上设置付款方式。我哪里错了?

【问题讨论】:

    标签: node.js reactjs stripe-payments


    【解决方案1】:

    看起来 PaymentMethod 是在 Platform 帐户上创建的,而不是在 Connect 帐户上创建的。

    在您的前端,您应该初始化 Stripe.js 并作为 Connect 帐户进行身份验证:https://stripe.com/docs/connect/authentication#adding-the-connected-account-id-to-a-client-side-application 您现在的方式(通过将{stripe_account: "acct_123"} 作为选项传递给confirmCardSetup)行不通。

    您还应该在 Connect 帐户上创建 SetupIntent,方法是在服务器端传递 Stripe-Account 标头,就像您在创建 PaymentIntent 时所做的那样:https://stripe.com/docs/connect/authentication#stripe-account-header

    【讨论】:

    • 我已初始化 Stripe.js 并使用以下代码作为 Connect 帐户进行身份验证:<StripeProvider apiKey={process.env.REACT_APP_API_STRIPE_PUBLISH} stripeAccount={this.state.userEvent.organiser.stripeAccountID} > 我已按照您的建议更改了后端。我的代码现在看起来像这样://front end const cardElement = this.props.elements.getElement('card'); axios.post(${process.env.REACT_APP_API}/saveCardDetails, {stripeAccountID: this.props.stripeAccountID}) .then(res => {
    • this.props.stripe.confirmCardSetup(res.data.client_secret, { payment_method: {         card: cardElement,       } }     ).then( confirmCardSetupRes => { axios.post(${process.env.REACT_APP_API}/purchaseWaitList, { paymentMethodID: confirmCardSetupRes.setupIntent.payment_method, }) //backend //saveCardDetails controller  stripe.setupIntents.create({ stripe_account: req.body.stripeAccountID, }).then(intent => { res.send({client_secret: intent.client_secret}) })
    • //purchaseWaitListController stripe.customers.create({payment_method: req.body.paymentMethodID}, { stripe_account: purchaser.stripeAccountID} ) 我在尝试创建条带客户时收到以下错误消息:{ Error: No such PaymentMethod: pm_1G5WnCLkWPLevtVYti9Q8U76 你能看出我哪里出错了吗?
    • 我建议确保您后端的 purchaser.stripeAccountIDthis.state.userEvent.organiser.stripeAccountID 相同,Customer 和 PaymentMethod 必须是相同的 Stripe 帐户,因此应该是相同的帐户 ID
    猜你喜欢
    • 2023-03-18
    • 1970-01-01
    • 2021-11-18
    • 1970-01-01
    • 2016-11-19
    • 2018-12-14
    • 2021-07-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多