似乎无法使用python检索条带电荷 [英] Can't seem to retrieve stripe charge using python

查看:42
本文介绍了似乎无法使用python检索条带电荷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下python代码在条带中创建费用.

I have the following python code to create a charge in stripe.

a_charge = stripe.Charge.create(
amount=cents, 
currency="usd",
source=token,
description="my_description",
application_fee=application_fee,
stripe_account=teacher_stripe_id
)

这成功了(我认为),因为它显示在我的仪表板中并且带有charge_id.但是,紧接着在代码之后,以下操作失败:

This succeeds (I think), because it shows up in my dashboard with a charge_id. But then, immediately after in the code, the following fails:

stripe.Charge.retrieve(a_charge.id)

有错误:没有这样的费用:这里有些长串

With error: No such charge: somelongstringhere

但是,长条串确实是我的条纹仪表板上的收费详细信息下的ID.那么,Stripe为何无法收回此笔费用?这不是正确的ID吗?

However, somelongstringhere is indeed the ID under charge details on my stripe dashboard. So how come Stripe can't retrieve this charge? Is this not the correct id?

推荐答案

费用检索调用失败的原因是,该费用是在其他帐户上创建的.

The reason the charge retrieval call fails is because the charge was created on a different account.

创建费用时:

a_charge = stripe.Charge.create(
  amount=cents, 
  currency="usd",
  source=token,
  description="my_description",
  application_fee=application_fee,
  stripe_account=teacher_stripe_id
)

您使用 stripe_account 参数,该参数指示库使用 Stripe-Account .这是用来告诉Stripe的API,该请求是由您的平台代表其关联帐户之一发出的.

you use the stripe_account parameter, which instructs the library to use the Stripe-Account in the request. This is used to tell Stripe's API that the request is issued by your platform on behalf of one of its connected accounts.

因此,要检索费用,您需要使用相同的 stripe_account 参数:

So in order to retrieve the charge, you need to use the same stripe_account parameter:

the_same_charge = stripe.Charge.retrieve(a_charge.id, stripe_account= teacher_stripe_id)

也就是说,实际上没有什么用.您已经在 a_charge 中拥有了充电对象.如果执行上面的代码,您会发现 a_charge == the_same_charge .

That said, there is little use to do this in practice. You already have the charge object in a_charge. If you execute the code above, you'd find that a_charge == the_same_charge.

通常,当您已经拥有Stripe对象的实例并想要从API获取最新状态时,可以使用 refresh()方法:

More generally, when you already have an instance of a Stripe object and want to get the latest state from the API, you can use the refresh() method:

a_charge.refresh()

这将查询API(无需担心 stripe_account 参数-实例记住"该参数并将在后台使用它)并使用值刷新实例的属性从API检索.

This will query the API (without you having to worry about the stripe_account parameter -- the instance "remembers" about it and will use it in the background) and refresh the instance's attributes with the values retrieved from the API.

这篇关于似乎无法使用python检索条带电荷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆