Skip to main content

Django DPO Gateway Integration

Project description

Django DPO Gateway

Django DPO Gateway is a Django app for integrating DPO payment gateway. Detailed documentation is in the "docs" directory.

Quick start

  1. Add django_dpo to your INSTALLED_APPS setting like this::
    INSTALLED_APPS = [
        ...,
        "django_dpo",
    ]
  1. Include DPO Settings in your project settings.py like this::
	
	DPO_END_POINT = "https://secure.3gdirectpay.com/API/v6/"
	DPO_PAYMENT_URL = "https://secure.3gdirectpay.com/payv2.php"
	DPO_COMPANY_TOKEN = "<your-company-token-from-dpo>"
	DPO_PAYMENT_CURRENCY = "<preferred currency>"
	DPO_PAYMENT_TIME_LIMIT = 5
	DPO_SERVICE_TYPE = 5525 

DPO Gateway Usage

Create Token

from django.shortcuts import resolve_url
from django_dpo import DPOGateway


def create_token(request):

    invoice_number = request.POST.get('invoice_number')
    amount = request.POST.get('amount')
    description = request.POST.get('description')

    redirect_url= request.build_absolute_uri(resolve_url('payment_url'))
    back_url = request.build_absolute_uri(resolve_url('back_url'))

    gateway = DPOGateway()

    gateway.set_redirect_url(redirect_url)
    gateway.set_back_url(back_url)

    response = gateway.create_token(
        company_ref=invoice_number,
        amount=float(amount),
        description=description
    )
    transaction_token = response.TransToken

    return gateway.make_payment(transaction_token)

Verify Token

from django.http import HttpResponseBadRequest
from django.contrib import messages
from django.shortcuts import redirect,reverse
from django_dpo import DPOGateway

def verify_payment(request):

    if not request.GET.get('TransID') and not request.GET.get('companyRef'):
        return HttpResponseBadRequest()
        
    transaction_token = request.GET.get('TransID')
    invoice_number = request.GET.get('PnrID')

    gateway = DPOGateway()

    response = gateway.verify_payment(transaction_token)

    amount = response.TransactionAmount
    currency = response.TransactionCurrency
    
    message = f"The payment of {currency} {amount} was successful"

    messages.success(request, message) 

    return redirect(reverse("index"))

Cancel Token

from django.http import HttpResponseBadRequest
from django.contrib import messages
from django.shortcuts import redirect, reverse
from django_dpo import DPOGateway

def cancel_token(request):

    if not request.GET.get('TransID') and not request.GET.get('companyRef'):
        return HttpResponseBadRequest()

    transaction_token = request.GET.get('TransID')
    gateway = DPOGateway()
    gateway.cancel_token(transaction_token)
    messages.success(request, "Transaction cancelled") 
    return redirect(reverse("index"))

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_dpo-0.0.2.tar.gz (4.1 kB view hashes)

Uploaded Source

Built Distribution

django_dpo-0.0.2-py3-none-any.whl (5.3 kB view hashes)

Uploaded Python 3

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