Skip to main content

No project description provided

Project description

DRF payments

Documentation GitHub release Build Status Tests

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

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

drf_payments-0.0.1.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

drf_payments-0.0.1-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: drf_payments-0.0.1.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.0 CPython/3.11.0 Darwin/22.5.0

File hashes

Hashes for drf_payments-0.0.1.tar.gz
Algorithm Hash digest
SHA256 d0b5bc74f83700d446fa5c350fc75d293ddf9f9d9d40d83ffbb8c9ef0432b127
MD5 17e338e03baf06f31325054c780980c3
BLAKE2b-256 92a816b6fac0d84f18ef45efd6d7a3b5c7abce4ede7103086fbc74af30272b16

See more details on using hashes here.

File details

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

File metadata

  • Download URL: drf_payments-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.0 CPython/3.11.0 Darwin/22.5.0

File hashes

Hashes for drf_payments-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 09b23f4f28ec62e09f9b3c490a632dd9e0c3988e11ff190f2466bddb627935fe
MD5 526f2ef440a9d624c0dd97253a3c0c85
BLAKE2b-256 9cffeacd44628fb6e637a94963e6a3020c3e43b484b5b0090faf765f99ca92c0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page