#diezler
1 messages · Page 1 of 1 (latest)
Hello! We'll be with you shortly. Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- diezler-webhook-signature-django, 3 hours ago, 18 messages
Products represent a good you are selling. Prices are how much you charge for that good. You can have multiple price per product (ie price per month and a one-time price for example)
Okay lets say I save a product in my database...
like this
class Product(models.Model):
name = models.CharField(max_length=100)
price = models.DecimalField(decimal_places=2)
product_type = models.CharField(max_length=100)
price_id = models.CharField(max_length=100)
product_id = models.CharField(max_length=100)
and then create a checkout for one of the products (in my case in game tokens)
class StripeCheckoutView(APIView):
def post(self, request):
try:
product = "price_1OKQuZEfrxFmu5w6qd3e5dDK" # get product here
checkout_session = stripe.checkout.Session.create(
line_items=[
{
'price': product,
'quantity': 1,
},
],
payment_method_types=['card', ],
mode='payment',
success_url=os.getenv('SITE_URL') + '/shop/?success=true&session_id={CHECKOUT_SESSION_ID}',
cancel_url=os.getenv('SITE_URL') + '/shop/?canceled=true',
payment_intent_data={
"metadata": {
'session_id': '{CHECKOUT_SESSION_ID}',
'user': request.user,
'product': product
}
},
)
print(checkout_session.url)
return Response({'url': checkout_session.url}, status=status.HTTP_201_CREATED)
except:
return Response(
{'error': 'Something went wrong when creating stripe checkout session'},
status=status.HTTP_500_INTERNAL_SERVER_ERROR
)
Would i get this product by its price? Like I do in this enpoint?
Why did you call your price variable product?
You pass a price not a product to the checkout session
No idea what you mean by this question
I pass the the price to the line items, right? And the stripe checkout view shows the related product, that is related to the price?
yeah done that, just confused that i pass a price to the line items and not a product id
Yeah because products can have multiple prices
You need to be specific on how much to charge the customer
Okay, so I can just pass the price id to the line items, when the user slected this specific price / product?
yep
and when i later check the webhook I can just activate the product by its id?
for example adding the amount of tokens ordered to the user account