Package: django-trustpay
Django app for TrustPayClient payment gateway API.Tested on Django 1.4.5.RequirementsDjangoRecommendationsdjango-detective (It is useful, but no necessary. It tracks all site requests.)InstallationInstall python library using pip:pip installdjango-trustpayAddtrustpaytoINSTALLED_APPSin your Django settings fileAddtrustpay.urlstourls.pyin your Django projectSetHOST_URLto be your host name with http/https protocol prefix. For example:https://www.mysite.comSet TrustPay settings. See below.Sync your databaseSettingsTRUSTPAY_AID_TESTClient’s AID for TEST environment.TRUSTPAY_AID_LIVEClient’s AID for LIVE environment.TRUSTPAY_SECRET_KEY_TESTClient’s Secret key for TEST environment.TRUSTPAY_SECRET_KEY_LIVEClient’s Secret key for LIVE environment.TRUSTPAY_PAYMENT_SERVICE_URL_TESTTrustPay PAYMENT SERVICE URL for TEST environment. Default:'https://test.trustpay.eu/mapi/paymentservice.aspx'TRUSTPAY_PAYMENT_SERVICE_URL_LIVETrustPay PAYMENT SERVICE URL for LIVE environment. Default:'https://ib.trustpay.eu/mapi/paymentservice.aspx'TRUSTPAY_CLIENT_REDIRECT_URL_TESTTrustPay CLIENT REDIRECT URL for TEST environment. Default:'https://test.trustpay.eu/mapi/pay.aspx'TRUSTPAY_CLIENT_REDIRECT_URL_LIVETrustPay CLIENT REDIRECT URL for LIVE environment. Default:'https://ib.trustpay.eu/mapi/pay.aspx'TRUSTPAY_SUCCESS_RETURN_URLSuccess return URL. Default:u'%s%s'% (settings.HOST_URL,reverse_lazy('trustpay_success_return'))TRUSTPAY_ERROR_RETURN_URLError return URL. Default:u'%s%s'% (settings.HOST_URL,reverse_lazy('trustpay_error_return'))TRUSTPAY_CANCEL_RETURN_URLCancel return URL. Default:u'%s%s'% (settings.HOST_URL,reverse_lazy('trustpay_cancel_return'))TRUSTPAY_NOTIFICATION_URLNotification URL. Default:u'%s%s'% (settings.HOST_URL,reverse_lazy('trustpay_notification'))TRUSTPAY_NOTIFICATION_EMAILNotification email. Default:ADMINS[0][0]or NoneUsagePrepare payment dataIn 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'example@example.net'
}and create TrustPay form with hidden fields and ‘Pay’ submit button:trustpayform = TrustPayClient(is_test=settings.DEBUG).get_form(**trustpay_payment_data)Render payment formPut TrustPay form to your template:{% include 'trustpay/helpers/form.html' with form=trustpayform submit_label='Pay with TrustPay' %}Handle return viewsBy default,SuccessReturnView,ErrorReturnView,CancelReturnViewsimply print request data and error message if any.
You should override templatestrustpay/success_return.html,trustpay/error_return.htmlandtrustpay/cancel_return.htmlor define your own return views. If you decide to use your own return views,
don’t forget to setTRUSTPAY_SUCCESS_RETURN_URL,TRUSTPAY_ERROR_RETURN_URLandTRUSTPAY_CANCEL_RETURN_URLsettings.Handle notification viewtrustpay.views.NotificationViewstores 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 flagis_safe- it means
the payment request from merchant was signed and return signature is correct).Helpersget_result_message(result_code)returns result message by result codeget_language_code(request)returns TrustPay supported language code by requestConstantstrustpaypackage contains all TrustPay supported currencies and countries.AuthorsLibrary is byErik TelepovskyfromPragmatic Mates. Seeour other libraries.