【发布时间】:2021-01-08 02:17:42
【问题描述】:
你好,
我发现在我的表单中添加 PayPal 智能支付按钮时遇到了困难。在我的项目中,有一些表单可以通过选择 Radio Button Stripe 或 Paypal 来选择所需的付款方式。
我不知道如何安排,以便在结帐页面显示本网站使用的信用卡和 PP 的标志:
https://developer.paypal.com/demo/checkout/#/pattern/radio
条纹支付方式运行良好,我只想添加 PayPal 支付选项。
我的项目是这样安排的: Forms.py
PAYMENT_CHOICES = (
('S', 'Stripe'),
('P', 'Paypal')
)
class CheckoutForm(forms.Form):
----address related forms-----------------------------------
payment_option = forms.ChoiceField(
widget=forms.RadioSelect, choices=PAYMENT_CHOICES)
这是结帐模板:
<h3>Payment option</h3>
<div class="d-block my-3">
{% for value, name in form.fields.payment_option.choices %}
<div class="custom-control custom-radio">
<input id="{{ name }}" name="payment_option" value="{{ value }}" type="radio" class="custom-control-input" required>
<label class="custom-control-label" for="{{ name }}">{{ name }}</label>
</div>
{% endfor %}
</div>
这里是views.py
class CheckoutView(View):
def get(self, *args, **kwargs):
try:
order = Order.objects.get(user=self.request.user, ordered=False)
form = CheckoutForm()
context = {
'form': form,
'couponform': CouponForm(),
'order': order,
'DISPLAY_COUPON_FORM': True
}
-----------------Shipping address codes-----------------------------
payment_option = form.cleaned_data.get('payment_option')
if payment_option == 'S':
return redirect('core:payment', payment_option='stripe')
elif payment_option == 'P':
return redirect('core:payment', payment_option='paypal')
else:
messages.warning(
self.request, "Invalid payment option selected")
return redirect('core:checkout')
except ObjectDoesNotExist:
messages.warning(self.request, "You do not have an active order")
return redirect("core:order-summary")
这是models.py
class Payment(models.Model):
stripe_charge_id = models.CharField(max_length=50)
user = models.ForeignKey(settings.AUTH_USER_MODEL,
on_delete=models.SET_NULL, blank=True, null=True)
amount = models.FloatField()
timestamp = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.user.username
我需要帮助将 PayPal 付款集成到我的结帐页面
【问题讨论】: