我需要从条带支付网关获取每日,每周,每月,每年帐户的总收入。有没有办法在Node.js API中做到这一点?
我试过这个,
var stripe = require("stripe")(
"sk_test_R8lnqjR3wPDwbMhsc2pti0yN"
);
stripe.balance.retrieve(function(err, balance) {
console.log(balance);
});
但这只会返回可用金额。我需要每天,每周,每月,每年明智。
答案 0 :(得分:1)
您可以使用条带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
});
答案 1 :(得分:0)
获得净利润的最简单方法是使用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;