【问题标题】:How to get the total revenue of my account in stripe (Node.js)?如何在条带(Node.js)中获取我帐户的总收入?
【发布时间】:2018-12-14 15:43:29
【问题描述】:

我需要每天、每周、每月、每年从条带支付网关获取我帐户的总收入。有没有办法在 Node.js API 中做到这一点?

我试过这个,

var stripe = require("stripe")(
  "sk_test_R8lnqjR3wPDwbMhsc2pti0yN"
);

 stripe.balance.retrieve(function(err, balance) {
  console.log(balance);
 });

但这只会返回可用金额。我需要每天、每周、每月、每年。

【问题讨论】:

    标签: node.js stripe-payments


    【解决方案1】:

    获得净利润的最简单解决方案是使用payouts 而不是余额数据。这可能会使您不必管理分页,因为例如,如果您只想要过去 30 天的收入,那么您的付款可能不会超过 100 次。

    我的代码如下所示。

    const payouts = await stripe.payouts.list({
      created: { gte: ..startRangeTimestamp.., lte: ..endRangeTimestamp.. } as any,
      limit: 100 // Maximum limit (10 is default)
    });
    
    const amountTotal = payouts.data.reduce((a: any, b: any) => ({ amount: a.amount + b.amount })).amount;
    

    【讨论】:

    • 注意,如果您当月没有支付任何费用,这将返回 0。即使您当月已经赚钱。
    【解决方案2】:

    您可以使用 stripe api 检索all transactions,然后您可以计算每个月的结果等...

    var stripe = require("stripe")(
      "sk_test_BQokikJOvBiI2HlWgH4olfQ2"
    );
    
    stripe.balance.listTransactions(
      {
        starting_after: startAt, //specify your start date
        ending_before: endAt, // specify your end date
      }, function(err, transactions) {
    
        // here sum the balance for the transactions
    });
    

    【讨论】:

    • 此解决方案可能需要分页。而是使用支出,因为这可能不会。此外,starting_after 和ending_before 用作光标位置,而不是日期范围
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    • 2018-02-11
    • 2023-03-18
    • 2012-10-12
    • 2019-12-22
    • 1970-01-01
    • 2018-12-27
    相关资源
    最近更新 更多