Skip to content
PayU integration for Django.
Branch: master
Clone or download
Michal Werner
Latest commit 860ba43 May 31, 2016
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE init Feb 5, 2016
README.rst handle payment with total=0 May 31, 2016 version bump, pep8 fixes May 15, 2016



  1. Install via pip:

    pip install django-payu-payments
  2. Add payu to INSTALLED_APPS:

  3. Add URLs to URLConf:

    url(r'^payments/', include('payu.urls', namespace='payu')),
  4. Run migrations:

    python migrate


Configuration is done via Django's file.


    Your POS ID. If not provided the test payment value will be used.


    Your MD5 key. If not provided the test payment value will be used.


    Your second MD5 key. If not provided the test payment value will be used.


    Specifies path on your website, where user should be redirected after payment (successful, or not). May be absolute path, like /some-page/ or reverse('some:thing'). This view should handle GET parameters error=501 in case of failed payment and no_payment=1 in case of payment with total equals 0, which is registered, but actually sent to PayU.


    Payment validity time (in seconds), after which it's canceled, if user did not take action. If not provided 600 will be used.

Create payment

To create payment object you have to call Payment.create method:

from payu.models import Payment

description = 'Some stuff'
products = [
        'name': 'Some product',
        'unitPrice': 14.99,
        'quantity': 1
        'name': 'Some other product',
        'unitPrice': 3.19,
        'quantity': 4
buyer = {
    'email': '',
    'firstName': 'John',
    'lastName': 'Doe'
notes = 'This client is important for us, we should prioritize him.'

payment = Payment.create(request, description, products, buyer, validity_time=300, notes)

request is just Django HTTP request object, we need it to get buyer IP, and absolute URLs.

validity_time is optional and overrides PAYU_VALIDITY_TIME setting.

notes is optional, and used for storing internal information about payment.

Payment.create will return two-key dictionary, containing Payment object and URL where buyer should be redirected, or False if not successful.

    'object': <Payment object>,
    'redirect_url': 'https://...'

Fetch payment's data

To get data associated with payment you just need to retrieve Payment object:


There are also few helpful methods, which you can call on Payment object:

  • get_total_display()

    Returns pretty formatted total value.

  • get_products_table()

    Returns pretty formatted table of products associated with payment.

  • is_successful()

    For status equal COMPLETED returns True, otherwise False.

  • is_not_successful()

    For status equal CANCELED or REJECTED returns True, otherwise False.



  • PEP8 fixes


  • changelog added
  • get_total_display(), get_products_table(), is_successful() and is_not_successful() methods added
  • JSONField is not Postgres-only anymore
  • Payment.create() now returns two-key dictionary instead of just redirect URL
  • Payment objects are now ordered from newest to oldest, by default
  • compiled translation is now included in package
  • settings moved to
  • settings is not dictionary anymore
  • validity time added

JSONField and ordering related changes requires you to take some action when upgrading.

  1. run migrations: python migrate payu.

  2. run following code, using Django shell (python shell):

    import json
    from payu.models import Payment
    for p in Payment.objects.all():
        if isinstance(p.products, str):
             p.products = json.loads(p.products)


  • sum added to products table


  • initial version
You can’t perform that action at this time.