Skip to main content

Django app for Trustpay payment gateway API.

Project description

Django app for TrustPayClient payment gateway API.

Tested on Django 1.4.5.


  • Django


  • django-detective (It is useful, but no necessary. It tracks all site requests.)


  1. Install python library using pip: pip install django-trustpay

  2. Add trustpay to INSTALLED_APPS in your Django settings file

  3. Add trustpay.urls to in your Django project

  4. Set HOST_URL to be your host name with http/https protocol prefix. For example:

  5. Set TrustPay settings. See below.

  6. Sync your database



Client’s AID for TEST environment.


Client’s AID for LIVE environment.


Client’s Secret key for TEST environment.


Client’s Secret key for LIVE environment.


TrustPay PAYMENT SERVICE URL for TEST environment. Default: ''


TrustPay PAYMENT SERVICE URL for LIVE environment. Default: ''


TrustPay CLIENT REDIRECT URL for TEST environment. Default: ''


TrustPay CLIENT REDIRECT URL for LIVE environment. Default: ''


Success return URL. Default: u'%s%s' % (settings.HOST_URL, reverse_lazy('trustpay_success_return'))


Error return URL. Default: u'%s%s' % (settings.HOST_URL, reverse_lazy('trustpay_error_return'))


Cancel return URL. Default: u'%s%s' % (settings.HOST_URL, reverse_lazy('trustpay_cancel_return'))


Notification URL. Default: u'%s%s' % (settings.HOST_URL, reverse_lazy('trustpay_notification'))


Notification email. Default: ADMINS[0][0] or None


Prepare payment data

In your checkout view prepare TrustPay payment data:

trustpay_payment_data = {
    # required
    'amount': 123.45,
    'currency': trustpay.CURRENCY_EUR,
    'reference': u'ORDER-123',  # Don't put # sign in reference. It will be returned back as GET parameter.

    # not required
    'language': get_language_code(request),
    'country': trustpay.COUNTRY_SLOVAK_REPUBLIC,
    'description': u'This is Trustpay test payment',
    'customer_email': u''

and create TrustPay form with hidden fields and ‘Pay’ submit button:

trustpayform = TrustPayClient(is_test=settings.DEBUG).get_form(**trustpay_payment_data)

Render payment form

Put TrustPay form to your template:

{% include 'trustpay/helpers/form.html' with form=trustpayform submit_label='Pay with TrustPay' %}

Handle return views

By default, SuccessReturnView, ErrorReturnView, CancelReturnView simply print request data and error message if any. You should override templates trustpay/success_return.html, trustpay/error_return.html and trustpay/cancel_return.html or define your own return views. If you decide to use your own return views, don’t forget to set TRUSTPAY_SUCCESS_RETURN_URL, TRUSTPAY_ERROR_RETURN_URL and TRUSTPAY_CANCEL_RETURN_URL settings.

Handle notification view

trustpay.views.NotificationView stores every notification from TrustPay service to database. You shouldn’t have set BasicAuth or any other authentication on this view (reverse('trustpay_notification')), because TrustPay won’t be able to access it.

I recommend you to create a cron job which will handle each safe notification (with flag is_safe - it means the payment request from merchant was signed and return signature is correct).



returns result message by result code


returns TrustPay supported language code by request


trustpay package contains all TrustPay supported currencies and countries.


Library is by Erik Telepovsky from Pragmatic Mates. See our other libraries.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-trustpay-0.3.0.tar.gz (8.9 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page