Subscriptions

Manage recurring payments with Plans and Subscriptions.

from djpaystack import PaystackClient
client = PaystackClient()

Plans

Create a Plan

response = client.plans.create(
    name='Monthly Pro',
    amount=500000,       # 5,000 NGN
    interval='monthly',  # daily, weekly, monthly, quarterly, biannually, annually
    description='Pro plan with all features',
)
plan_code = response['data']['plan_code']

List / Fetch Plans

response = client.plans.list(page=1, per_page=50)
response = client.plans.fetch(id_or_code=plan_code)

Update a Plan

response = client.plans.update(
    id_or_code=plan_code,
    name='Monthly Pro v2',
    amount=600000,
)

Subscriptions

Create a Subscription

response = client.subscriptions.create(
    customer='CUS_xxxxx',
    plan=plan_code,
    authorization='AUTH_xxxxx',
)
sub_code = response['data']['subscription_code']

List / Fetch Subscriptions

response = client.subscriptions.list()
response = client.subscriptions.fetch(id_or_code=sub_code)

Enable / Disable

response = client.subscriptions.enable(code=sub_code, token=email_token)
response = client.subscriptions.disable(code=sub_code, token=email_token)

Webhook Events

Subscription-related webhook events:

  • subscription.create — New subscription created

  • subscription.disable — Subscription disabled

  • subscription.not_renew — Subscription will not renew

  • subscription.expiring_cards — Cards about to expire

  • invoice.create — Invoice created for subscription

  • invoice.payment_failed — Subscription payment failed

Listen via Django signals:

from django.dispatch import receiver
from djpaystack.signals import paystack_subscription_created, paystack_subscription_cancelled

@receiver(paystack_subscription_created)
def on_sub_created(sender, transaction_data, **kwargs):
    print(f"New subscription: {transaction_data}")

@receiver(paystack_subscription_cancelled)
def on_sub_cancelled(sender, transaction_data, **kwargs):
    print(f"Subscription cancelled: {transaction_data}")