Login

Paypal form with better sandbox support

Author:
seddonym
Posted:
February 26, 2014
Language:
Python
Version:
Not specified
Score:
0 (after 0 ratings)

This is a class I use instead of the default PayPalPaymentsForm in django-paypal.

I wanted to use the Paypal sandbox on my development site and the real Paypal site on my production site. Currently, if you want to output the Paypal form with the sandbox you have to call the sandbox() method on the form, rather than the render() method.

Using this class instead of the default PayPalPaymentsForm, you can just set PAYPAL_DEBUG to True in the settings file and the form will take you through to the sandbox instead. Don't forget to set the sandbox merchant account's business email address as PAYPAL_RECEIVER_EMAIL too.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
from paypal.standard.forms import PayPalPaymentsForm as BasePayPalPaymentsForm
from django.conf import settings


class PayPalPaymentsForm(BasePayPalPaymentsForm):
    """Better support for the sandbox.
    It will show the sandbox form upon rendering if PAYPAL_DEBUG is set to True."""

    def render(self):
        if settings.PAYPAL_DEBUG:
            return self.sandbox()
        return super(PayPalPaymentsForm, self).render()

More like this

  1. Template tag - list punctuation for a list of items by shapiromatron 11 months, 2 weeks ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months, 3 weeks ago
  3. Serializer factory with Django Rest Framework by julio 1 year, 6 months ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 7 months ago
  5. Help text hyperlinks by sa2812 1 year, 7 months ago

Comments

Please login first before commenting.