条纹费用计算

19

关于Stripe费用计算,是否有一种方法可以根据提供的金额获取Stripe费用。

我们需要以这样的方式实现,即我们必须支付x金额给一个经销商和y金额给另一个经销商。

第一种情况:

假设我们要支付$100给Stripe。

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

例如:

要支付的金额是$100 + $3(Stripe费用)= $103(总额),您需要从客户账户中扣除。

第二种情况:

我们需要向经销商支付$95,而剩下的$5我们想留在我们的账户中(不包括Stripe费用)。

如果可能,我们应该如何实现呢?


这与SilverStripe PHP框架有什么关系? - wmk
@wmk 可能他正在使用该模块...sher,你想要的是分成付款,这并不是很常见。如果您希望,我可以为您提供一个支付网关的建议,但我认为Stripe不支持此功能。 - Barry
12个回答

24

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

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

这将告诉您Stripe收取的费用,然后您可以进行剩余的计算。


如果有人对POST请求中应该如何看待此内容感兴趣,这里是:&expand%5B%5D=balance_transaction - FlorianB

20

如果有人正在寻找用于计算Stripe手续费的JavaScript代码(也许是要求客户支付Stripe手续费),我编写了一个小脚本来执行此操作。

/**
 * 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


1
你确定费用取决于支付货币吗?我认为这是由平台账户的货币决定的。例如:如果你的平台在美国,每笔付款无论支付货币如何都将是“百分比:2.9,固定费用:0.30”。 - Jim Smith
根据我在Stripe网站上所看到的(2018年12月23日),所有欧盟费用为1.4% + 0.20p,所有非欧盟费用为2.9% + 20p。 - Martin James
2
不,费用取决于卡的发行地,而不是交易货币。 - w00t
1
这个公式非常有用,非常感谢。但是是否可能提供一个国际费用的公式?我知道除此之外还有额外的国际费用。 - Tsuna
1
有没有获取费用计算的API?例如,我们向Stripe请求适当的费用,然后得到响应。 - zacoder

12
从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

我可以使用这个来获取给定客户收费的详细信息(净金额和/或Stripe费用)吗? - ilyanaDev

5

1
我正在使用这个公式来计算 Stripe 费用。假设金额为 $100。(100 * 0.029) + 0.30 = 103.20 但在 Stripe 上显示的是 103.29 而不是 103.20。 不知道出了什么问题? - sher bahadur
2
你需要支付2.9%的手续费,即$0.09,这是基于$3.20的。 - tsdorsey
2
(100 / (1 - 0.029)) + 0.30 = 103.28661174,四舍五入为$103.29。 - tsdorsey

3

我想补充Harshal Lonare的答案,关于发送付款意图确认,您可以通过以下方式获取余额交易数据:

"expand" => array("charges.data.balance_transaction")

1
您可以提前计算Stripe的费用。只需查看他们最新的计算公式,网址在此 https://stripe.com/us/pricing (记得更改URL以匹配您的国家,例如对于我(法国),URL是https://stripe.com/fr/pricing)。
因此,在我的情况下,有点特殊:
- 对于欧洲卡,Stripe的费用为1.4% + 0.25€。 - 对于非欧洲卡,Stripe的费用为2.9% + 0.25€。 - 对于美国,Stripe的费用为2.9% + 0.30美元。
注意:百分比是从总金额中扣除的。 例如:对于一个美国账户,如果我以100美元的价格出售一个产品,那么Stripe的费用将是:
(100 * 0.029) + 0.30 = 3.2 USD

如果方便的话,可以随意分摊Stripe费用。


1

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;

0
这些答案没有考虑到费用是根据总金额收取的事实。因此,如果您开具的是$100 + ($100 * 2.9% + $0.30) = $103.20的账单,Stripe现在会对$103.20收取费用,而不是最初的$100。
此帖子中有一个有用的公式,我已将其改编为Ruby语言。
def calculate(desired_total, percent_fee, fixed_fee)
  return 0 if desired_total <= 0

  # X = what to charge
  # Y = what we want
  #
  # The basic formula is:
  #   X - (X * 0.029) - 0.30 = Y
  #
  # First... we want our percentage (0.029) to be a whole number so we will
  # multiply each variable by 1000
  multiplier = 1000
  y = desired_total * multiplier

  percent_component = (percent_fee) * multiplier # => 29
  base_component = fixed_fee * multiplier # => 300
  coefficient = multiplier - percent_component # => 971

  # This gives us
  #    1000X - 29X - 300 = Y
  #
  # Which we then re-arrange the terms to
  #    971X = Y + 300
  #
  # And can then calculate the total we need to charge as
  #   X = (Y + 300) / 971
  total_charge = (y + base_component) / coefficient
end

p calculate(100, 0.029, 0.30) => # 103.29557157569516
p calculate(200, 0.029, 0.30) => # 206.2821833161689

0
在NodeJs中,使用支付意向ID获取Stripe收取的处理费。
 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;

在charges对象的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"
                        }
                    ],
                },

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接