I am using Stripe JS on my front end, and sending it to my backend, which is based on Django.
All of generating a subscription is working, except for the payment method. Here's the code:
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) customer.add_payment_method(payment_method) price = djstripe.models.Price.objects.get(nickname=price_name) customer.subscribe(price=price) return Response({"success": "eventual subscription data"})
My payment_method looks like this (all of this is fake card data):
{ "id":"pm_1Ia7gGJs57u3g5HDEpaI5Pv2", "object":"payment_method", "billing_details":{ "address":{ "city":"None", "country":"None", "line1":"None", "line2":"None", "postal_code":"None", "state":"None" }, "email":"None", "name":"None", "phone":"None" }, "card":{ "brand":"visa", "checks":{ "address_line1_check":"None", "address_postal_code_check":"None", "cvc_check":"None" }, "country":"US", "exp_month":2, "exp_year":2022, "funding":"credit", "generated_from":"None", "last4":"4242", "networks":{ "available":[ "visa" ], "preferred":"None" }, "three_d_secure_usage":{ "supported":true }, "wallet":"None" }, "created":1616972764, "customer":"None", "livemode":false, "type":"card" }
However upon this line:
customer.add_payment_method(payment_method)
I get the following error:
TypeError: quote_from_bytes() expected bytes
What exactly am I missing here? Is this not how I am supposed to use a payment method?
This is using the Djstripe library
https://stackoverflow.com/questions/66847920/django-stripe-library-is-having-trouble-with-payment-method March 29, 2021 at 10:04AM
没有评论:
发表评论