如何从关联的帐户(Node.js)中提取付款的Stripe费用

时间:2020-08-12 13:34:55

标签: node.js stripe-payments

我一直在阅读有关如何从给定的付款here中提取条纹费用的文档:

// Set your secret key. Remember to switch to your live secret key in production!
// See your keys here: https://dashboard.stripe.com/account/apikeys
const stripe = require('stripe')('sk_test_xyz');

const paymentIntent = await stripe.paymentIntents.retrieve(
  'pi_1Gpl8kLHughnNhxyIb1RvRTu',
  {
    expand: ['charges.data.balance_transaction'],
  }
);

const feeDetails = paymentIntent.charges.data[0].balance_transaction.fee_details;

但是,我想检索对关联帐户付款的Stripe费用。如果我尝试通过链接帐户中的付款方式尝试上面的代码,则会收到错误消息:

Error: No such payment_intent: 'pi_1Gpl8kLHughnNhxyIb1RvRTu'

但是,当我从Webhook接收发布的数据时,我实际上可以看到列出的付款意图:

{ id: 'evt_1HFJfyLNyLwMDlAN7ItaNezN',
   object: 'event',
   account: 'acct_1FxPu7LTTTTMDlAN',
   api_version: '2019-02-11',
   created: 1597237650,
   data:
    { object:
       { id: 'pi_1Gpl8kLHughnNhxyIb1RvRTu',
         object: 'payment_intent',

有什么提示吗?

1 个答案:

答案 0 :(得分:0)

我想检索对已连接网络的付款的Stripe费用 帐户。如果我尝试通过链接中的付款方式尝试上面的代码 帐户出现错误:

要检索代表关联帐户(使用direct Charge)进行的付款的Stripe费用,您需要通过指定特殊的Stripe-Account标头来发出检索请求作为关联帐户在请求中。使用stripe-node时,如果您传入account ID as part of the request options,我们将自动为您添加该标头。例如:

  const paymentIntent = await stripe.paymentIntents.retrieve(
    "pi_1HCSheKNuiVAYpc7siO5HkJC",
    {
      expand: ["charges.data.balance_transaction"],
    },
    {
      stripeAccount: "acct_1GDvMqKNuiVAYpc7",
    }
  );

您可以在https://stripe.com/docs/api/connected_accounts

上阅读有关在stripe-node和我们的其他库中代表关联帐户进行请求的更多信息。