在Stripe Balance Transaction API响应中获取零费用

时间:2016-12-27 15:04:45

标签: ruby-on-rails ruby stripe-payments

我正在使用Stripe API来接收来自多个用户的贡献。所以我想为我们的客户生成声明,以便他们可以看到确切的金额,费用减免,交易计数等。

在查看Stripe API后,我发现有两个API(Stripe::TransferStripe::BalanceTransaction),这些可以用来满足我的要求。

根据文档Stripe API ,我正在调用Stripe::Transfer API,此API会返回正确的响应,如下所示

transfer = #<Stripe::Transfer:0x3f997455ac88 id=tr_1xxxxxxxxxxxxxx>    JSON: {
"id": "tr_1xxxxxxxxxxxxxxxxx",
"object": "transfer",
"amount": 9510,
"amount_reversed": 0,
"application_fee": null,
"balance_transaction": "txn_123",
"created": 1477485158,
"currency": "usd",
"date": 1477485158,
"description": null,
"destination": "acct_xxxxxxxxxxxxxx",
"destination_payment": "py_xxxxxxxxxxx",
"failure_code": null,
"failure_message": null,
"livemode": false,
"metadata": {},
"method": "standard",
"recipient": null,
"reversals": {"object":"list","data":[],"has_more":false,"total_count":0,"url":"/v1/transfers/tr_xx/reversals"},
"reversed": false,
"source_transaction": "ch_xxxxxxxxx",
"source_type": "card",
"statement_descriptor": null,
"status": "paid",
"type": "stripe_account"
}

我正在调用Stripe :: BalanceTransaction API以获取特定传输事务的详细信息

balance_transaction_id = transfer.balance_transaction
Stripe::BalanceTransaction.retrieve(balance_transaction_id)

获得以下回复

#<Stripe::BalanceTransaction:0x3f9974f2f1c8 id=txn_123> JSON: {
"id": "txn_123",
"object": "balance_transaction",
"amount": -9510,
"available_on": 1478044800,
"created": 1477485158,
"currency": "usd",
"description": null,
"fee": 0,
"fee_details": [

],
"net": -9510,
"source": "tr_xxxxxxxx",
"sourced_transfers": {"object":"list","data":  [],"has_more":false,"total_count":0,"url":"/v1/transfers?  source_transaction=tr_xxxx"},
"status": "available",
"type": "transfer"
}

我设置了申请费(2%),这在Stripe Dashboard上显示正确但在上面的回复中我得到的fee0

所以任何人都可以帮助/建议我如何在此回复中获得feetotal_count

预先感谢您的任何帮助和建议。

1 个答案:

答案 0 :(得分:0)

您不希望在此处查看转帐及其余额交易以获取费用。这是来自目的地付款的帐户之间的自动转帐,因此不会收取任何费用。

您需要在source_transaction中检索原始费用,然后查看此费用自己的balance_transactionapplication_fee个对象。

您甚至可以使用扩展功能在一次API调用中执行此操作: https://stripe.com/docs/api#expanding_objects

关于总计数我怀疑你想要这个用户的交易数量,那么你需要在列出这个帐户的所有转账时查看这个,并在请求中添加以下可选参数:

:include => ['total_count']

这只有在您不在目的地费用之外创建到关联帐户的手动转帐时才有效。