django-paypal icon indicating copy to clipboard operation
django-paypal copied to clipboard

Customize payment button

Open anuj9196 opened this issue 6 years ago • 3 comments

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.

anuj9196 avatar Jan 02 '18 18:01 anuj9196

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.

spookylukey avatar Jan 03 '18 12:01 spookylukey

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 avatar Sep 13 '18 09:09 vassilisw

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!

hvitis avatar Nov 09 '19 21:11 hvitis