#koolknow

1 messages · Page 1 of 1 (latest)

full lilyBOT
unique dome
#

that's the issue

open peak
#

myapp/views.py

from django.shortcuts import render, redirect
from django.conf import settings
import stripe
from .models import Product

def product_list(request):
products = Product.objects.all()
return render(request, 'product_list.html', {'products': products})

def checkout(request, product_id):
product = Product.objects.get(pk=product_id)
return render(request, 'checkout.html', {'product': product})

def charge(request, product_id):
product = Product.objects.get(pk=product_id)
if request.method == 'POST':
stripe.api_key = settings.STRIPE_SECRET_KEY
token = request.POST['stripeToken']

    try:
        charge = stripe.Charge.create(
            amount=int(product.price * 100),  # Convert to cents
            currency='usd',
            source=token
        )
        if charge.paid:
            return redirect('success')
        else:
            return render(request, 'payment_failed.html')
    except stripe.error.CardError as e:
        return render(request, 'payment_failed.html')
return redirect('product_list')

this is my views code

#

in the models i have the name and the price

#

and i have created the templates

unique dome
#

Not sure I follow. The issue is that you're making an API request to Stripe without the source parameter set.

So most likely the token you're setting in this code is just an empty string

                amount=int(product.price * 100),  # Convert to cents
                currency='usd',
                source=token
            )```
open peak
#

can you write me the complete code??

unique dome
#

No

#

That's not something we do on this server. We help you figure out what's wrong and then you need to fix the issue

#

We can't help write your code

open peak
#

okay then can you please tell , from where i can get help