I am using Stripe to process payments from my website. Yesterday it was 
working ok. That was before I changed code my code so It can process 
payments using a customer_id. I am using test keys

 My code below. Help I'm still a beginner in django. I'm sorry my English 
is bad. 

from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from django.conf import settings
import stripe


stripe.api_key =  settings.STRIPE_SECRET_KEY
# Create your views here.
@login_required
def checkout(request):
     publishKey = settings.STRIPE_PUBLISHABLE_KEY
   customer_id = request.user.userstripe.stripe_id
        print(customer_id)
     if request.method == 'POST':
           customer = stripe.Customer.retrieve(customer_id)
               token = request.POST['stripeToken']
            charge = stripe.Charge.create(
                 amount = 1000,
                 currency = 'usd',
                      customer = customer,
                   description = 'Example Charge',
                )
      context = {'publishKey':publishKey}
    template = 'checkout.html'
     return render(request, template, context)


The error I am getting is below

File "C:\Program 
Files\Python37-32\lib\site-packages\django\core\handlers\exception.py" in 
inner
  34.             response = get_response(request)

File "C:\Program 
Files\Python37-32\lib\site-packages\django\core\handlers\base.py" in 
_get_response
  126.                 response = self.process_exception_by_middleware(e, 
request)

File "C:\Program 
Files\Python37-32\lib\site-packages\django\core\handlers\base.py" in 
_get_response
  124.                 response = wrapped_callback(request, *callback_args, 
**callback_kwargs)

File "C:\Program 
Files\Python37-32\lib\site-packages\django\contrib\auth\decorators.py" in 
_wrapped_view
  21.                 return view_func(request, *args, **kwargs)

File "C:\Users\Patrice\Desktop\ecommerce web\ecommerce\checkout\views.py" 
in checkout
  22. description = 'Example Charge',

File "C:\Program 
Files\Python37-32\lib\site-packages\stripe\api_resources\abstract\createable_api_resource.py"
 
in create
  22.         response, api_key = requestor.request("post", url, params, 
headers)

File "C:\Program 
Files\Python37-32\lib\site-packages\stripe\api_requestor.py" in request
  121.         resp = self.interpret_response(rbody, rcode, rheaders)

File "C:\Program 
Files\Python37-32\lib\site-packages\stripe\api_requestor.py" in 
interpret_response
  372.             self.handle_error_response(rbody, rcode, resp.data, 
rheaders)

File "C:\Program 
Files\Python37-32\lib\site-packages\stripe\api_requestor.py" in 
handle_error_response
  151.         raise err

Exception Type: CardError at /checkout/
Exception Value: Request req_En9Ipi3bygWUWY: Cannot charge a customer that 
has no active card





-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/04423272-5bf9-4b26-9963-c180b926c909%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to