如何解决如何在 DjStripe 中将 PaymentMethod 附加到 Stripe Customer?
我有以下 Django 类:
class PurchaseSubscriptionView(APIView):
def post(self,request,user_id):
price_name = request.data.get("price_name")
payment_method = request.data.get("payment_method")
user = User.objects.get(id=user_id)
customer,created = djstripe.models.Customer.get_or_create(subscriber=user)
payment_method_json = json.dumps(payment_method)
customer.add_payment_method(payment_method_json)
price = djstripe.models.Price.objects.get(nickname=price_name)
customer.subscribe(price=price)
一切正常,直到 customer.add_payment_method(payment_method_json)
此时我得到:
stripe.error.InvalidRequestError: Request req_8KcCUrPg7z8Aok: No such PaymentMethod: '{\"id\": \"pm_1IaFMyJs57u3g5HDGoe83cGx\",\"object\": \"payment_method\",\"billing_details\": {\"address\": {\"city\": null,\"country\": null,\"line1\": null,\"line2\": null,\"postal_code\": null,\"state\": null},\"email\": null,\"name\": null,\"phone\": null},\"card\": {\"brand\": \"visa\",\"checks\": {\"address_line1_check\": null,\"address_postal_code_check\": null,\"cvc_check\": null},\"country\": \"US\",\"exp_month\": 2,\"exp_year\": 2022,\"funding\": \"credit\",\"generated_from\": null,\"last4\": \"4242\",\"networks\": {\"available\": [\"visa\"],\"preferred\": null},\"three_d_secure_usage\": {\"supported\": true},\"wallet\": null},\"created\": 1617002320,\"customer\": null,\"livemode\": false,\"type\": \"card\"}'
究竟是怎么回事?我在生成它后从我的客户那里传递了 PaymentMethod - 这应该有效,对吗?我是否遗漏了任何步骤?
解决方法
在调用 customer.add_payment_method
时,您应该传入 PaymentMethod ID,但您似乎试图将整个 JSON 对象转储到那里。
你可能想要
customer.add_payment_method(payment_method_json.id)
相反。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。