簡體   English   中英

如何將 PaymentMethod 附加到 DjStripe 中的條帶客戶?

[英]How do I attach a PaymentMethod to a stripe Customer in DjStripe?

我有以下 Django class:

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 object 轉儲到那里。

你可能想要

customer.add_payment_method(payment_method_json.id)

反而。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM