Helloo,
I am finding difficultly in proceeding with adding the PayPal smart payment buttons in my forms. In my project, there are forms to choose the required payment method through selecting Radio Button Stripe or Paypal.
I don't know how to arrange it so that the logos of credit cards and PP used in this website to be shown in the check out page:
https://developer.paypal.com/demo/checkout/#/pattern/radio
The stripe payment method is working perfectly fine I just want to add the PayPal payment option.
This is how my project is arranged: 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)
here is the checkout template:
<h3>Payment option</h3>
<div class="d-block my-3">
</div>
Here is the 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")
Here is the 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
I need help to integrate the PayPal payment in my checkout page
from How to add the PayPal Smart Payment Buttons to my forms.py
No comments:
Post a Comment