/django-getpaid

Django payments processor.

Primary LanguagePythonMIT LicenseMIT

Latest PyPI version https://api.codacy.com/project/badge/Coverage/d25ba81e2e4740d6aac356f4ac90b16d https://api.codacy.com/project/badge/Grade/d25ba81e2e4740d6aac356f4ac90b16d

Welcome to django-getpaid

django-getpaid is payment processing framework for Django

Documentation

The full documentation is at https://django-getpaid.readthedocs.io.

Features

  • support for multiple payment brokers at the same time
  • very flexible architecture
  • support for asynchronous status updates - both push and pull
  • support for modern REST-based broker APIs
  • support for multiple currencies (but one per payment)
  • support for global and per-plugin validators
  • easy customization with provided base abstract models and swappable mechanic (same as with Django's User model)

Quickstart

Install django-getpaid and at least one payment backend:

pip install django-getpaid

Add them to your INSTALLED_APPS:

INSTALLED_APPS = [
    ...
    'getpaid',
    'getpaid.backends.payu',  # one of plugins
    ...
]

Add getpaid to URL patterns:

urlpatterns = [
    ...
    path('payments/', include('getpaid.urls')),
    ...
]

Define an Order model by subclassing getpaid.models.AbstractOrder and define some required methods:

from getpaid.models import AbstractOrder

class MyCustomOrder(AbstractOrder):
    amount = models.DecimalField(decimal_places=2, max_digits=8)
    description = models.CharField(max_length=128)
    buyer = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)

    def get_absolute_url(self):
        return reverse('order-detail', kwargs={"pk": self.pk})

    def get_total_amount(self):
        return self.amount

    def get_buyer_info(self):
        return {"email": self.buyer.email}

    def get_currency(self):
        return "EUR"

    def get_description(self):
        return self.description

Note

If you already have an Order model and don't want to subclass AbstractOrder just make sure you implement all methods.

Inform getpaid of your Order model in settings.py and provide settings for payment backends:

GETPAID_ORDER_MODEL = 'yourapp.MyCustomOrder'
GETPAID_PAYU_SLUG = "getpaid.backends.payu"

GETPAID_BACKEND_SETTINGS = {
    GETPAID_PAYU_SLUG: {
        # take these from your merchant panel:
        "pos_id": 12345,
        "second_key": "91ae651578c5b5aa93f2d38a9be8ce11",
        "oauth_id": 12345,
        "oauth_secret": "12f071174cb7eb79d4aac5bc2f07563f",
    },
}

Write a view that will create the Payment.

An example view and its hookup to urls.py can look like this:

# main urls.py

urlpatterns = [
    # ...
    path("gp/", include("getpaid.urls")),
]

You can optionally override callback handler. Example for PayU backend:

from getpaid.backends.payu.processor import PaymentProcessor as GetpaidPayuProcessor

class PayuCallbackHandler:
    def __init__(self, payment):
        self.payment = payment

    def handle(self, data):
        pass

class PayuPaymentProcessor(GetpaidPayuProcessor):
    callback_handler_class = PayuCallbackHandler

PAYU

TODO: improve docs

Running Tests

poetry install
poetry run tox

Alternatives

Credits

Created by Krzysztof Dorosz. Redesigned and rewritten by Dominik Kozaczko.

Proudly sponsored by SUNSCRAPERS

Redesigned to be compatible with rest-framework by Panowie Programiści

Disclaimer

This project has nothing in common with getpaid plone project.