我试图使用Stripe API获取费用。
一切都很好,但我不明白为什么这个请求不起作用:
Stripe::Charge.all(metadata: { project_id: an_id })
我收到了错误:
Stripe :: InvalidRequestError:收到未知参数:metadata
这里的回复是什么样的:
{"id":"ch_1BQIXjGrTKCCbjGtKVJOKzbg","object":"charge","amount":1000,"amount_refunded":0,"application":null,"application_fee":"fee_1BQIXlEsrND8ZkheXtsfgQWj","balance_transaction":"txn_1BQIXlGrTKCCbjGtpSDEu34m","captured":true,"created":1511196887,"currency":"eur","customer":"cus_BnuMP3mm0iEFL8","description":"Don","destination":"acct_1BEzwEEsrND8Zkhe","dispute":null,"failure_code":null,"failure_message":null,"fraud_details":{},"invoice":null,"livemode":true,"**metadata":**{"donation_amount":"10","donation_fees":"0","donation_id":"21110","donation_referer_id":"417","donation_reward_id":"2120",**"project_id":"501"**,"project_name":"Arcadia - Le Concert Classique des youtubers","user_city":"Segré","user_country":"FR","user_email":"simon-chretien@hotmail.fr","user_first_name":"Simon","user_id":"23038","user_last_name":"Chrétien"},"on_behalf_of":"acct_1BEzwEEsrND8Zkhe","order":null,"outcome":{"network_status":"approved_by_network","reason":null,"risk_level":"normal","seller_message":"Payment complete.","type":"authorized"},"paid":true,"receipt_email":"simon-chretien@hotmail.fr","receipt_number":"1097-0153","refunded":false,"refunds":{"object":"list","data":[],"has_more":false,"total_count":0,"url":"/v1/charges/ch_1BQIXjGrTKCCbjGtKVJOKzbg/refunds"},"review":null,"shipping":null,"source":{"id":"card_1BQIXcGrTKCCbjGtKktLMM42","object":"card","address_city":null,"address_country":null,"address_line1":null,"address_line1_check":null,"address_line2":null,"address_state":null,"address_zip":null,"address_zip_check":null,"brand":"Visa","country":"FR","customer":"cus_BnuMP3mm0iEFL8","cvc_check":"pass","dynamic_last4":null,"exp_month":10,"exp_year":2020,"fingerprint":"aMPkqWKgq4dQUnWy","funding":"credit","last4":"8073","metadata":{},"name":"simon-chretien@hotmail.fr","tokenization_method":null},"source_transfer":null,"statement_descriptor":null,"status":"succeeded","transfer":"tr_1BQIXlGrTKCCbjGtjFk4oC0D","transfer_group":"group_ch_1BQIXjGrTKCCbjGtKVJOKzbg"},
正如您所看到的那样,元数据=> project_id作为回应
我做错了什么?
答案 0 :(得分:1)
正如其中一条评论所说,如果您想要退还一笔费用,可以使用retrieve。您必须将费用ID传递给方法:
Stripe::Charge.retrieve('ch_1BQIXjGrTKCCbjGtKVJOKzbg')
您要查找的文档位于List all charges下。 all
实际上是list
的别名。根据完成您正在进行的操作的文档,您可以返回所有条带费用,然后在project_id
内搜索metadata
。
根据您收取的费用数量而言,这似乎是过度杀戮所有费用。相反,请考虑仅根据customer
仅返回此客户ID指定的客户的费用。
Stripe::Charge.list(customer: "cus_BnuMP3mm0iEFL8")
# or
Stripe::Charge.all(customer: "cus_BnuMP3mm0iEFL8")