django-paypal
django-paypal copied to clipboard
Customize payment button
I want to customize the pay now button to meed the theme of my template with icons and class like
<button class="btn btn-payment">
<i class="fa fa-paypal">
Get Started
</i>
</button>
In the documentation, I can only see how to change the image. Is there a way to customize it like described above.
There isn't a documented way at the moment to do that.
However, you can do it fairly simply by subclassing the payment form, and implementing the render
method according to your requirements. See https://github.com/spookylukey/django-paypal/blob/master/paypal/standard/forms.py#L163 - your version would need to replace the <input type="image">
with your code.
I assume spookylukey means something like this:
class MyPayPalPaymentsForm(PayPalPaymentsForm):
def render(self):
form_open = u'''<form action="%s" method="post">''' % (self.get_endpoint())
form_close = u'</form>'
# format html as you need
submit_elm = u'''<input type="submit" class="btn btn-success my-custom-class">'''
return format_html(form_open+self.as_p()+submit_elm+form_close)
I assume spookylukey means something like this:
class MyPayPalPaymentsForm(PayPalPaymentsForm): def render(self): form_open = u'''<form action="%s" method="post">''' % (self.get_endpoint()) form_close = u'</form>' # format html as you need submit_elm = u'''<input type="submit" class="btn btn-success my-custom-class">''' return format_html(form_open+self.as_p()+submit_elm+form_close)
@vassilisw This is highly useful when customizing the payment template that PayPal opens. Thank you!