如何在django中使用Stripe? 语言:Python 操作系统:Windows 10 框架-Django 3
我的网站包含三本书,每本书都有不同的价格标签,比如500、1000和2000卢比。当我直接指定金额时,金额字段工作正常(如下面代码所示,我使用了500卢比)。但是我想让amount字段成为动态的。这样我可以为其他书籍提供不同的价格标签 views.py如何在django中使用Stripe? 语言:Python 操作系统:Windows 10 框架-Django 3,django,Django,我的网站包含三本书,每本书都有不同的价格标签,比如500、1000和2000卢比。当我直接指定金额时,金额字段工作正常(如下面代码所示,我使用了500卢比)。但是我想让amount字段成为动态的。这样我可以为其他书籍提供不同的价格标签 views.py from django.shortcuts import render from django.views.generic.base import TemplateView from django.views.generic import Det
from django.shortcuts import render
from django.views.generic.base import TemplateView
from django.views.generic import DetailView
from django.conf import settings
from books.models import Book
import stripe
stripe.api_key = settings.STRIPE_SECRET_KEY
class PaymentsPage(DetailView):
model = Book
template_name = 'payments.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['key'] = settings.STRIPE_PUBLISHABLE_KEY
return context
def charge(request): # will handle our payments (via tokens)
if request.method == 'POST':
charge = stripe.Charge.create(
amount=500,
currency='inr',
description='A Django charge',
source=request.POST['stripeToken']
)
payment_intent = stripe.PaymentIntent.create(
amount=1099,
currency='inr',
description='Software development services',
)
customer = stripe.Customer.create(
name='Jenny Rosen',
address={
'line1': 'Delhi',
'postal_code': '110059',
'city': 'delhi',
'state': 'New Delhi',
'country': 'INDIA',
},
)
return render(request, 'charge.html')
amount=book.price
?amount=book.price
?