HomePaymentsNo-codeDevelopersContribute
Safepay Home PageLive DashboardTest Dashboard

Subscriptions

Implement recurring payments with Safepay.


Safepay supports recurring billing through its Subscriptions feature, which allows you to automatically charge your customers on a defined schedule. This can be used for SaaS platforms, memberships, or any service with regular billing needs.

How it works

You create a subscription plan and attach it to a customer. The Safepay system then handles automatic charges based on the frequency you define.

Step-by-step guide

1

Create a Plan

Safepay offers a lightweight way to manage recurring payments using its Subscriptions API. You can create a subscription plan, define billing intervals, and automatically charge customers at recurring intervals.

Use the POST https://sandbox.api.getsafepay.com/client/plans/v1/ endpoint to create a subscription plan with your defined amount, billing frequency, and currency.

Create a Subscription Plan in NodeJS
const safepay = require('@sfpy/node-core')({
  api_key: 'YOUR_SERVER_API_KEY',
  authType: 'jwt',
  host: 'https://sandbox.api.getsafepay.com'
});

(async () => {
  try {
    const response = await safepay.client.plans.create({
      payload: {
        amount: "100",
        currency: "PKR",
        interval: "MONTH",
        type: "RECURRING",
        interval_count: 1,
        product: "bananas",
        active: true
      }
    });
    console.log(response);
  } catch (error) {
    console.error(error);
  }
})();

2

Create a Subscription

Subscriptions cannot be created using APIs since a customer has to subscribe to a plan. Subscriptions are created by a customer interacting with Safepay Checkout. You can however, use our SDKs to generate a Checkout URL that a customer can be redirected to so that they are able to subscribe to one of your plans. Refer to our Integration Guides to learn more.

Subscription Statuses

  • active: The subscription is billing normally.
  • paused: Temporarily stopped.
  • cancelled: Permanently stopped.
  • pending: Awaiting first charge.
  • failed: Payment attempts failed.

3

Handle Webhooks

Once a subscription is active, Safepay will automatically attempt to charge the customer on the scheduled interval. You will receive webhook notifications for subscription.payment_succeeded or subscription.payment_failed events. Handle these in your backend to update customer access, retry, or notify the customer.

Make sure to verify webhook signatures to ensure authenticity and log failed attempts for reconciliation.

Webhooks

Safepay sends webhooks for recurring charges:

  • subscription.created
  • subscription.payment_succeeded
  • subscription.payment_failed
  • subscription.cancelled

Be sure to handle these events to update your internal billing system or notify customers.

Subscriptions heavily rely on webhooks. Ensure your server handles them reliably.

Next Steps

  • Learn how to save cards using tokenization.
  • Understand how webhooks work with subscriptions.