Reputation: 545
Having issues getting the Stripe subscription working in my Django application. right now I have this as my view:
def subscribe(request):
customer = stripe.Customer.create(
description = 'This is the test customer',
)
if request.method=='POST':
stripe.Subscription.create(
customer= customer.id,
items = [{"Basic Plan": "prod_HHU1r1fphhhqLt"}]
)
return render(request, 'landing/charge.html')
Im getting the error:
Request req_69L7P1bcp8iZ1e: Received unknown parameter: items[0][Basic Plan]
which is confusing because the info is coming straight from my stripe plan so I know it exists
(edit) here is the traceback if it helps:
Traceback (most recent call last):
File "/Users/tobiasmuldoon/Dev/python/Environments/web1/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/Users/tobiasmuldoon/Dev/python/Environments/web1/lib/python3.8/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/tobiasmuldoon/Dev/python/Environments/web1/lib/python3.8/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/tobiasmuldoon/Dev/python/Environments/swapp/landing/views.py", line 79, in subscribe
stripe.Subscription.create(
File "/Users/tobiasmuldoon/Dev/python/Environments/web1/lib/python3.8/site-packages/stripe/api_resources/abstract/createable_api_resource.py", line 22, in create
response, api_key = requestor.request("post", url, params, headers)
File "/Users/tobiasmuldoon/Dev/python/Environments/web1/lib/python3.8/site-packages/stripe/api_requestor.py", line 122, in request
resp = self.interpret_response(rbody, rcode, rheaders)
File "/Users/tobiasmuldoon/Dev/python/Environments/web1/lib/python3.8/site-packages/stripe/api_requestor.py", line 373, in interpret_response
self.handle_error_response(rbody, rcode, resp.data, rheaders)
File "/Users/tobiasmuldoon/Dev/python/Environments/web1/lib/python3.8/site-packages/stripe/api_requestor.py", line 152, in handle_error_response
raise err
Exception Type: InvalidRequestError at /subscribe/
Exception Value: Request req_69L7P1bcp8iZ1e: Received unknown parameter: items[0][Basic Plan]```
Im pretty postitive its something simple but Im pretty new to django and cant seem to get it figured out. Thank you!
Upvotes: 1
Views: 158
Reputation: 542
You are passing the wrong parameter. the creation of the subscription takes a list of dictionaries having the ID of the plan with key 'plan'. There is no parameter named 'Basic Plan'. So to avoid the error please make following changes:
def subscribe(request):
customer = stripe.Customer.create(
description = 'This is the test customer',
)
if request.method=='POST':
stripe.Subscription.create(
customer= customer.id,
items = [{"plan": "prod_HHU1r1fphhhqLt"}]
)
return render(request, 'landing/charge.html')
Noice the Key 'Basic Plan' is changed to 'plan' in the items parameter. Hope this helps!!
Upvotes: 3