[英]Stripe source creation is failing
我看到一个与 Stripe 相关的奇怪错误,因为我无法使用我的实时 API 密钥创建源。
在我的应用程序中创建客户后,在 Stripe 上创建了一个客户(即实时 API 密钥正在工作)
使用测试条 API 密钥时,我可以添加卡并进行收费
当我在我的站点上使用我的实时API 密钥时,即使我将有效源传递给 function,customer.sources.create() 调用也会失败。
stripe_customer_id = cus_IoiFADFAADFASDF (made up value for this post, but is a valid one in my environment that has been generated by Stripe) source = src_1ILfdf3asdfasdfasdfadsf (made up value for this post, but is a valid one in my environment that has been generated by Stripe) customer = stripe.Customer.retrieve(stripe_customer_id) stripe_card_response = customer.sources.create(source=source) #THIS IS THE LINE OF CODE THAT FAILS
我已经确认我传递给这些函数的 stripe_customer_id 和源变量已被填充。 它们填充了从 Stripe 发送给我的值。
不幸的是,Stripe 不会返回任何可识别的错误。 换句话说,当我通过代码中的以下异常进行 go 时,只有最后一个被命中,这是一个通用的包罗万象。
except stripe.error.CardError as e:
except stripe.error.RateLimitError as e:
except stripe.error.InvalidRequestError as e:
except stripe.error.AuthenticationError as e:
except stripe.error.APIConnectionError as e:
except stripe.error.StripeError as e:
except Exception as e: #this is where the error falls as it doesn't relate to any of the others
500 错误返回以下内容
raise AttributeError(*err.args)
AttributeError: sources
谢谢你的帮助!
问题是,当您检索客户时,默认情况下不会返回其来源。
如果您在检索客户时扩展请求,您的代码应该可以按预期工作:
customer = stripe.Customer.retrieve(stripe_customer_id,
expand=['sources']
)
stripe_card_response = customer.sources.create(source=source)
“检索、就地变异然后保存”模式是 Stripe 正在远离的一种模式,转而支持客户服务。 相反,您可以执行以下操作,这意味着您无需检索客户并避免您扩展sources
:
source = stripe.Customer.create_source(
stripe_customer_id
source=source
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.