Skip to main content

A 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.1.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

django_dpo-0.0.1-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file django_dpo-0.0.1.tar.gz.

File metadata

  • Download URL: django_dpo-0.0.1.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.12

File hashes

Hashes for django_dpo-0.0.1.tar.gz
Algorithm Hash digest
SHA256 3f56b435cf0a40033638525d0d06cc5172215a7574d28e8afa79258aef8748a6
MD5 76af7b71fbd66138f5147094108be259
BLAKE2b-256 5898a0d5ff4812fa0d250e75090f70bbc8b37226ea61005f82a0984b24d5bb7a

See more details on using hashes here.

File details

Details for the file django_dpo-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: django_dpo-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.12

File hashes

Hashes for django_dpo-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9361ca9b20853391714a9517fa2b15270be9877e53ac6c23f689b6ab0771cf2b
MD5 ac010da1c95a57fad4e400e2f90d8020
BLAKE2b-256 4a7e757bc56b55f26d01bad542b19142aa390dd77928181624a0106e7b0e046b

See more details on using hashes here.

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