14

关于 Stripe 费用计算,有没有办法根据提供的金额获得 Stripe 费用。

我们必须以这样的方式实现这一点,我们必须向一个经销商支付x金额,向另一个经销商支付y金额。

第一种情况:

假设我们有 100 美元要支付给 Stripe。

根据我们的需要,我们想先计算 Stripe 费用,然后将该费用添加到 100 美元的金额中。

例如:

要支付的金额为 100 美元 + 3 美元(条纹费)= 103 美元(总计),您需要从客户账户中扣除。

第二种情况:

我们需要向经销商支付 95 美元,剩下的 5 美元要保留在我们的帐户中(不包括 Stripe 费用)。

如果这是可能的,我们如何实现呢?

4

11 回答 11

24

最简单的方法是为余额交易添加扩展

$charge = \Stripe\Charge::create(array(
              "amount" => $totalAmount,
              "currency" => $currency_code,
              "source" => $stripeToken,
              "transfer_group" => $orderId,
              "expand" => array("balance_transaction")
            ));

这将为您提供条带收取的费用,然后您可以进行剩余计算

于 2018-06-06T12:31:56.847 回答
16

对于寻找 javascript 代码来计算条带费的人(也许要求客户支付条带费)。我写了一个小脚本来做

/**
 * Calculate stripe fee from amount
 * so you can charge stripe fee to customers
 * lafif <hello@lafif.me>
 */
var fees = { 
    USD: { Percent: 2.9, Fixed: 0.30 },
    GBP: { Percent: 2.4, Fixed: 0.20 },
    EUR: { Percent: 2.4, Fixed: 0.24 },
    CAD: { Percent: 2.9, Fixed: 0.30 },
    AUD: { Percent: 2.9, Fixed: 0.30 },
    NOK: { Percent: 2.9, Fixed: 2 },
    DKK: { Percent: 2.9, Fixed: 1.8 },
    SEK: { Percent: 2.9, Fixed: 1.8 },
    JPY: { Percent: 3.6, Fixed: 0 },
    MXN: { Percent: 3.6, Fixed: 3 }
};

function calcFee(amount, currency) {
    var _fee = fees[currency];
    var amount = parseFloat(amount);
    var total = (amount + parseFloat(_fee.Fixed)) / (1 - parseFloat(_fee.Percent) / 100);
    var fee = total - amount;

    return {
        amount: amount,
        fee: fee.toFixed(2),
        total: total.toFixed(2)
    };
}

var charge_data = calcFee(100, 'USD');
alert('You should ask: ' + charge_data.total + ' to customer, to cover ' + charge_data.fee + ' fee from ' + charge_data.amount );
console.log(charge_data);

https://gist.github.com/c3954950798ae14d6caabd6ba15b302b

于 2018-02-03T06:37:48.490 回答
11

从 Stripe Charge ID 我们可以得到从金额中扣除的手续费

stripe.Charge.retrieve("ch_1DBKfWECTOB5aCAKpzxm5VIW", expand=['balance_transaction'])

    "id": "txn_1DBKfWECTOB5aCAKtwwLMCjd",
    "net": 941,
    "object": "balance_transaction",
    "source": "ch_1DBKfWECTOB5aCAKpzxm5VIW",
    "status": "pending",
    "type": "charge"

"net": 941 is the amount credited to merchant account
于 2018-09-17T11:24:44.773 回答
4

目前,Stripe 的 API 无法在创建费用之前计算费用。你需要自己做这件事。

如果您想将费用转嫁给付费客户,以下支持文章将非常有帮助: https: //support.stripe.com/questions/can-i-charge-my-stripe-fees-to-my-customers

要代表另一个帐户处理付款,并可选择从交易中提取,您需要使用Stripe Connect。您可以在文档中阅读更多内容:https ://stripe.com/docs/connect 。

于 2016-04-28T09:00:11.207 回答
3

只是想弹出并添加到 Harshal Lonare 的答案中,为了发送付款意图确认,您可以通过以下方式获取余额交易数据:

"expand" => array("charges.data.balance_transaction")
于 2020-06-19T02:31:54.273 回答
1

您可以提前计算 Stripe 费用。只需在此处查看他们最新的计算公式:https ://stripe.com/us/pricing(请记住更改 URL 以匹配您的国家,例如我(法国)的 URL 是https://stripe.com /fr/定价

所以,就我而言,它有点特别:

  • 对于欧洲卡,Stripe 费用为 1.4% + 0.25€</li>
  • 对于非欧洲卡,Stripe 费用为 2.9% + 0.25€</li>

对于美国,Stripe 费用为 2.9% + 0.30 美元

注:百分比取自总金额。示例:对于美国账户,如果我以 100 美元的价格出售产品,Stripe 费用将为:

(100 * 0.029) + 0.30 = 3.2 USD

然后随意拆分 Stripe 费用以方便您使用

于 2018-12-07T05:17:05.160 回答
0

使用托管帐户最后我能够实现上述场景。

用于计算条纹费。

stripe_fixed_fee = 0.30;//cent stripe_charge = 0.029; //分

您可以参考此链接 http://www.blackdog.ie/stripe/ https://support.stripe.com/questions/can-i-charge-my-stripe-fees-to-my-customers

谢谢!

于 2016-05-12T09:31:33.730 回答
0

您可以使用这样的函数来计算绝对支付金额(“需要支付”金额+条纹“税”):

const stripeFee = (amount) => {
  if (amount <= 0) return 0;
  const amountTax = amount / 100 * stripeProcessingFee;
  const minFeeTax = stripeProcessingMinFee / 100 * stripeProcessingFee;
  const tax = amountTax
    + (amountTax + minFeeTax) / 100 * stripeProcessingFee
    + minFeeTax
    + stripeProcessingMinFee;
  return Math.ceil(amount + tax);
};

*stripeProcessingFee - Stripe 即用即付定价百分比 (2.9 %)
*stripeProcessingMinFee - Stripe 即用即付定价最低价值,以美分 (30 美分)

于 2019-12-15T15:55:01.513 回答
0

即便如此,大部分费用计算都是正确的,我仍然认为最流畅的方法是询问报告 api 而不是进行计算。我只使用节点而不是 PHP,但这是我的代码:

require('dotenv').config()
const stripe = require('stripe')(process.env.STRIPE_SECRET)
const { DateTime } = require('luxon')
const fetch = require('node-fetch')
const { encode } = require('base-64')
const CSV = require('csv-string')


//Important Timestamps
const dt = DateTime.local().setZone('America/Los_Angeles')
const endOfLastMonth = dt.startOf('month').toSeconds()
const startOfLastMonthLA = dt.minus({ month : 1 }).startOf('month').toSeconds()

const params = {
    created : {
        gt : startOfLastMonthLA, lt : endOfLastMonth
    }
}

const gather = async () => {

    const reportRun = await stripe.reporting.reportRuns.create({
        report_type : 'balance_change_from_activity.summary.1', parameters : {
            interval_start : startOfLastMonthLA, interval_end : endOfLastMonth
        }
    })
    let reportTest
    console.time('generateReport')
    while ( true ) {
        console.log('start')
        await new Promise(resolve => {
            setTimeout(resolve, 2000)
        })
        reportTest = await stripe.reporting.reportRuns.retrieve(reportRun.id)

        if (reportTest.status === 'succeeded') {
            console.log(reportTest.id)
            break
        }
    }
    console.timeEnd('generateReport')
    const actualReport = await fetch(reportTest.result.url, {
        headers : {
            'Authorization' : 'Basic ' + encode(process.env.STRIPE_SECRET + ':')
        }
    })
    const data = await actualReport.text()
    //This is the net profit!
    console.log(CSV.parse(data)[4][5])

}

gather().catch(e => console.log(e))

信息都在数据中,我建议看一下数据字符串。它基本上是您获得的报告,当您单击仪表板中的报告时,它们具有不同的报告类型。从语义上讲,通过报告 api 获取报告更正确,然后与更用于处理/检查单笔费用的 api 相比。我更喜欢条带以 JSON 格式直接向我发送该信息,但 csv 也可以。

于 2020-10-12T12:48:28.567 回答
0

可以使用支付意图的 id 检索 Stripe 处理费用。

\Stripe\Stripe::setApiKey('{{secret}}');

$paymentIntent = \Stripe\PaymentIntent::retrieve([
  'id' => '{{payementIntentid}}',
  'expand' => ['charges.data.balance_transaction'],
]);

$feeDetails = $paymentIntent->charges->data[0]->balance_transaction->fee_details;
于 2022-01-17T17:09:27.337 回答
0

在 NodeJs 中使用支付意图 id 来获取条带收取的处理费

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

//Stripe fee
const stripe_fee = paymentIntent.charges.data[0].balance_transaction.fee;

它将在费用对象内的 paymentIntent 中给出以下响应(balance_transaction 的fee_details)

"balance_transaction": {
                    "id": "txn_3JQ9ddddgRF81Q43rnFI1Zn2US9u",
                    "object": "balance_transaction",
                    "exchange_rate": null,
                    "fee": 76,
                    "fee_details": [
                        {
                            "amount": 76,
                            "application": null,
                            "currency": "usd",
                            "description": "Stripe processing fees",
                            "type": "stripe_fee"
                        }
                    ],
                },
于 2021-08-20T09:55:48.340 回答