【问题标题】:How do I create a custom connect stripe account and pass account id to payment intent method using firebase functions?如何使用 firebase 函数创建自定义连接条带帐户并将帐户 ID 传递给付款意图方法?
【发布时间】:2021-07-21 14:33:01
【问题描述】:

我正在尝试使用我的 react 本机应用程序中的 firebase 云功能来收集和转移付款。我正在使用 stripe.accounts.create 和 stripe.paymentIntents.create 函数以及库 axios。我真的不太确定如何创建连接帐户并将创建的帐户 ID 传递到付款意图方法中。我在 Firebase 日志中收到以下错误代码:'StripeInvalidRequestError:只能在 PaymentIntent 尝试直接付款(使用 OAuth 密钥或 Stripe-Account 标头)或目的地付款(使用transfer_data[destination])时应用 application_fee_amount' 尝试在下面运行我的代码时。有人可以帮忙吗?我不认为 connectAcc.id 为空,因为我可以在创建帐户的响应正文中的条带仪表板日志中看到它:

回复正文 { "id": "acct_**********U5", “对象”:“帐户”, “企业简介”:{ "mcc": "5734", “名称”:空, “产品描述”:空, “support_address”:空, “support_email”:空, “支持电话”:空, “support_url”:空,

index.js 文件

const stripe = require('stripe')('**SK_LIVE**');

exports.payWithStripe = functions.https.onRequest((request, response) => {

const connectAcc = stripe.accounts.create({
type: 'custom',
email: 'name@gmail.com',
country: 'GB',
business_type: 'individual',
business_profile: {
   mcc: '5734',
   url: 'site.com',
},
individual: {
   first_name: 'First',
   last_name: 'Last',
   dob : {
     day: 1,
     month: 10,
     year: 1990
       },
   email: 'name@gmail.com',
   phone: '+44xxxxxxx',
   address: {
      city: 'city',
      country: 'GB',
      line1: '1',
      line2: 'Street Rd',
      postal_code: 'XXX XXX'
   }       
},
tos_acceptance: {
       date: Math.floor(Date.now() / 1000),
       ip: request.connection.remoteAddress,
    },
capabilities: {
   card_payments: {requested: true},
   transfers: {requested: true},
},
external_account: {
   object: 'bank_account',
       country: 'GB',
   currency: 'gbp',
   account_number: 'xxxxx',
   routing_number: 'xxxxx',
   accounter_holder_name: 'First Last',
   account_holder_type: 'individual',
  }
 })



 stripe.paymentIntents.create({
    amount: request.body.amount,
    currency: request.body.currency,
    payment_method_types: ['card'],
    payment_method: request.body.payment_method.id,
    application_fee_amount: 20,
    on_behalf_of: connectAcc.id,
    transfer_data: {
    destination: connectAcc.id,
    },
    confirm: true,
    description: 'UniHome'
    }

   ).then((charge) => {
        response.send(charge);
    })
    .catch(err =>{
        console.log(err);
    })

    });

谢谢。

【问题讨论】:

  • 你做了哪些调试?您是否通过查看您的 Stripe 帐户上的 logs 确认这些 API 请求中的任何一个都没有错误?您是否检查过 Firebase 中的日志或将 console.logs 添加到您自己的代码中? “无法处理请求”是一个通用错误,必须有日志可以帮助您准确了解请求是如何处理的以及哪一部分可能无法正常工作。
  • 谢谢。它提到转移需要启用'invalid_request_error 您的目标帐户需要至少启用以下功能之一:转移,legacy_payments。创建帐户时需要填写一些字段,例如业务类型、行业、网站等。谢谢
  • 是的,根据法律要求,创建帐户并向其汇款的一部分首先是登录并从用户那里收集身份验证。不是简单的收集银行账号然后汇款给它!我建议阅读 Stripe 关于这一切的文档。
  • 谢谢。我已经设法提供了设置连接帐户的要求,它在运行时出现在我的条带仪表板中,但资金没有被转移。我的 firebase 函数的日志显示:StripeInvalidRequestError: Can only apply an application_fee_amount when the PaymentIntent is trying to a direct payment (using an OAuth key or Stripe-Account header) or destination payment...

标签: firebase react-native axios google-cloud-functions stripe-payments


【解决方案1】:

connectAcc 不是帐户对象——它是一个 Promise。这就是 Stripe 的 SDK 所返回的。

您必须先解决 Promise,例如:

let connectAcc = await stripe.accounts.create(...); let id = connectAcc.id or stripe.accounts.create(...).then(function(acct){let id = acct.id;} )

【讨论】:

    猜你喜欢
    • 2019-10-10
    • 2021-08-17
    • 1970-01-01
    • 2016-02-07
    • 2021-07-20
    • 2018-07-15
    • 2021-02-13
    • 2013-10-15
    • 2020-03-07
    相关资源
    最近更新 更多