she*_*dur 5 stripe-payments stripe.net stripe-connect
关于条纹费的计算,是否有任何方法可以根据提供的金额来获取条纹费。
我们必须以这样的方式实现这一点,即我们必须向一个交易商支付x金额,向另一个交易商支付y金额。
第一种情况:
假设我们要付给Stripe 100美元。
根据我们的需要,我们要先计算Stripe费用,然后将该费用添加到$ 100金额中。
例如:
您需要从客户帐户中扣除的金额为$ 100 + $ 3(剥离费用)= $ 103(总计)。
第二种情况:
我们需要向交易商支付95美元,剩下的5美元要保留在我们的帐户中(不包括条纹费用)。
如果可能的话,我们如何实现呢?
最简单的方法是为余额交易添加扩展
$charge = \Stripe\Charge::create(array(
"amount" => $totalAmount,
"currency" => $currency_code,
"source" => $stripeToken,
"transfer_group" => $orderId,
"expand" => array("balance_transaction")
));
Run Code Online (Sandbox Code Playgroud)
这将为您提供带区收费的费用,然后您可以进行剩余的计算
从 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
Run Code Online (Sandbox Code Playgroud)
目前,Stripe 的 API 无法在创建费用之前计算费用。你需要自己做这件事。
如果您想将费用转嫁给付费客户,以下支持文章将非常有帮助:https ://support.stripe.com/questions/can-i-charge-my-stripe-fees-to-my-customers
要代表另一个帐户处理付款,并可选择从交易中删除,您需要使用Stripe Connect。您可以在文档中阅读更多信息: https: //stripe.com/docs/connect。
对于正在寻找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);
Run Code Online (Sandbox Code Playgroud)
https://gist.github.com/c3954950798ae14d6caabd6ba15b302b
| 归档时间: |
|
| 查看次数: |
7446 次 |
| 最近记录: |