Skip to main content

DRF payments

Documentation Build Status Tests PyPI GitHub tag (latest SemVer pre-release)

Package to handle various payments provider inside your drf project

This package will allow you to create transactional payments on various payment providers:

  • Stripe
  • Paypal
  • Braintree
  • Authorize.net

Upon creation of your app Payment model this library will handle:

  • Creation of payment on selected provider
    • Direct charge
    • Checkout session
  • Handling webhook event from payment gateway to update Payment status
  • Handle Refund on the payment if payment was processed
  • Write along the way all payment gateway responses in extra_data json field of your Payment model

For example of usage please see example app inside repository.

Installation

  • pip install drf-payments
  • Add to INSTALLED_APPS
INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "drf_payments",
    ...
]
  • Add callback url
from django.contrib import admin
from django.urls import include, path

urlpatterns = [
    path("admin/", admin.site.urls),
    ...
    path("drf-payments/", include("drf_payments.urls")),
]
  • Provide required settings
PAYMENT_MODEL = "stripe_checkout.StripeCheckoutPayment"
PAYMENT_CALLBACK_URL = "http://localhost:8000/drf-payments/callback/"
PAYMENT_SUCCESS_URL = "http://localhost:3000/payments/success/"
PAYMENT_FAILURE_URL = "http://localhost:3000/payments/failure/"

PAYMENT_VARIANTS = {
    "stripe": (
        "drf_payments.stripe.StripeCheckoutProvider",
        {
            "secret_key": os.environ.get("STRIPE_SECRET_KEY"),
            "public_key": os.environ.get("STRIPE_PUBLIC_KEY"),
        },
    ),
    "paypal": (
        "drf_payments.paypal.PaypalProvider",
        {
            "client_id": os.environ.get("PAYPAL_CLIENT_ID"),
            "secret": os.environ.get("PAYPAL_SECRET_KEY"),
            "endpoint": os.environ.get("PAYPAL_URL", "https://api.sandbox.paypal.com"),
        },
    ),
}

Usage

For usage you can check example implementation in repo

  • Inherit drf_payments.models.BasePayment model in your app
from drf_payments.models import BasePayment

class StripeChargePayment(BasePayment):
    ...

    class Meta:
        db_table = "stripe_charge"
  • Use drf_payments.mixins.PaymentViewMixin in view that handles your payment model
from rest_framework.routers import SimpleRouter

from drf_payments.mixins import PaymentViewMixin

app_name = "shop"

router = SimpleRouter()
router.register("payment", PaymentViewMixin, basename="payment")

urlpatterns = [*router.urls]
  • Point your payments events to endpoint from settings PAYMENT_CALLBACK_URL

For more info please check example app inside repository

For even more detail check documentation

Metadata

Release files for drf-payments 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for drf-payments 0.0.2
File Size Uploaded Provenance Actions
drf_payments-0.0.2.tar.gz 13.9 kB Without provenance Details for drf_payments-0.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for drf-payments 0.0.2
File Interpreter ABI Platform Actions
drf_payments-0.0.2-py3-none-any.whl Python 3 none any Details for drf_payments-0.0.2-py3-none-any.whl

Total release size: 29.9 kB

Release files / drf_payments-0.0.2.tar.gz

Download URL drf_payments-0.0.2.tar.gz
Size 13.9 kB
Tags Source
SHA-256 checksum
How to use checksums
490a8b20efd7a3958869f3e5c9143e68fc42479e9f7052c2ea8bc2ac3299b7bc
BLAKE2b-256 checksum
How to use checksums
4b08f97e71d94a4bf79f4ed4eedd0812cd781c3717f0024a7c3e437d26337d32
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.11.4 Linux/5.15.0-1040-azure

Release files / drf_payments-0.0.2-py3-none-any.whl

Download URL drf_payments-0.0.2-py3-none-any.whl
Size 16.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f1c4ca8a389ffbbf53fa0ff08ff29bf2e20d9b3ccd68d402d904ab40987e4c2b
BLAKE2b-256 checksum
How to use checksums
08aa084d696d3794f90fc4983ab7249b8f0eecd2894e5ed036478d745e73c984
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.11.4 Linux/5.15.0-1040-azure

Security for drf-payments 0.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page