Strapi plugin logo for Stripe Payment

Stripe Payment

The Stripe Payment plugin for Strapi enables seamless integration with the Stripe payment system. This plugin is inspired by GitHub's payment system for organizations, allowing users to create organizations, subscribe to plans, and manage their subscriptions. Administrators can create and manage products, plans, and subscriptions within the Strapi admin panel.

Strapi Plugin: Stripe Payment

Introduction

The Stripe Payment plugin for Strapi enables seamless integration with the Stripe payment system. This plugin is inspired by GitHub's payment system for organizations, allowing users to create organizations, subscribe to plans, and manage their subscriptions. Administrators can create and manage products, plans, and subscriptions within the Strapi admin panel.

How to Use

This plugin facilitates Stripe integration within your Strapi application, providing user and admin-facing functionalities. Users can subscribe to different plans, manage their billing details, and handle payments via Stripe. The administrator can configure products; and pricing plans; and oversee user subscriptions.

Installation

To install the plugin, run the following command:

  yarn add @dbbs/strapi-plugin-stripe-payment

Plugin Configuration

Enable and configure the Stripe Payment plugin in plugins.ts:

1'stripe-payment': {
2  enabled: true
3}

Environment Variables Setup

Configure the required environment variables in your .env file:

1STRIPE_API_KEY=your_stripe_secret_key
2STRIPE_WEBHOOK_SECRET=webhook_secrete_key
3STRIPE_SUCCESS_PAYMENT_URL=your_success_url
4STRIPE_SUCCESS_SETUP_URL=your_success_setup_url

server.ts file:

1export default ({ env }) => ({
2  stripe: {
3    apiKey: env('STRIPE_API_KEY', ''),
4    successPaymentUrl: env('STRIPE_SUCCESS_PAYMENT_URL', 'http://localhost:8080/success'),
5    successSetupUrl: env('STRIPE_SUCCESS_SETUP_URL', 'http://localhost:8080/success'),
6    webhookSecret: env('STRIPE_WEBHOOK_SECRET', ''),
7    domainUrl: env('DOMAIN_URL', '')
8  }
9})

Connecting Services

To use this plugin, you need to have two services set up:

Stripe (Payment System)

  1. Go to Stripe and sign up/log in.
  2. Navigate to the Developers section and obtain your Secret Key.
  3. Go to the Webhook section and create a new webhook route. Tutorial

    • Open create event destinagtion on stripe dashboard and pick events for new webhook Stripe Events

    • Choose webhook option (for now, the plugin supports webhook) Stripe Webhook

    • Provide stripe with your webhook url Stripe Webhook url

    • Save your webhook secret key Stripe Webhook url

  4. Copy the Webhook Secret Key and add it to your .env file.

Admin panel

On the admin panel, you can use 2 new paragraphs in Settings and Content Manager

Content manager page

On this page, you can do base CRUD operations for entities in your DB, without Stripe sync. This way, you can integrate your entities with the plugin.

  • Content Manager Content Manager

Settings page

On this page, you can perform manipulations with Stripe: do CRUD operations, manage entities, and make purchases; and subscriptions with Stripe sync.

  • Settings Settings

API

We can present our REST API, which allows your customers to manipulate Stripe via our plugin. Customers can create organizations, add other users to organizations, make purchases and transactions, and subscribe to products with specified plan types.

Content types

Here you can see the main entities that allow your customers to manipulate Stripe; you can collaborate your entities with the presented and extend the user’s logic as you want.

Organization

In our plugin terminology – a group of users, with one leader user – the owner, allows to sharing subscriptions or other rules between users. On stripe side, our organization is stripe-customer

The organization fields

AttributeTypeDescription
idnumberUnique organization id in database
namestringName of the organization
customer_idstringStripe customer ID associated with the organization
payment_method_idstringStripe payment method ID for the organization
owner_idstringUser ID of the organization's owner
usersrelation (oneToMany)List of users in the organization (linked to users-permissions.user)
subscriptionrelation (oneToOne)Subscription linked to the organization (linked to subscription)
purchasesrelation (oneToMany)Purchases made by the organization (linked to purchase)
quantityintegerQuantity related to the organization's subscription or purchases
transactionsrelation (oneToMany)Transactions associated with the organization (linked to transaction)

Plan

A plan or billing plan is an entity that describes how organizations should pay for products; it can be a one-time purchase or a monthly/yearly subscription.

AttributeTypeDescription
idnumberUnique plan ID in database
priceintegerPrice of the plan in smallest currency unit (e.g., cents)
stripe_idstringStripe plan ID associated with this plan
intervalenumerationBilling interval: month, year
typeenumerationPlan type: recurring (default) or one-time
productrelation (manyToOne)Linked product associated with this plan (linked to product)
Product

A product is an item that organizations can purchase or subscribe to. The product can have its own price and plan type on the Stripe side, but you can make it more functional by adding new fields and logic on your side.

AttributeTypeDescription
idnumberUnique product ID in database
namestringName of the product
stripe_idstringStripe product ID associated with this product
plansrelation (oneToMany)List of plans linked to this product (linked to plan)
Purchase

We have 2 kinds of payments - one-time and periodic. If an organization needs to buy a product with a one-time plan, that will be a purchase. Organization, as we saw above, can have multiple purchases.

AttributeTypeDescription
idnumberUnique purchase ID in database
stripe_idstringStripe purchase ID associated with this purchase
planrelation (oneToOne)Linked plan for this purchase (linked to plan)
organizationrelation (manyToOne)Organization that made the purchase (linked to organization)
Subscription

Periodic payment is a subscription that can withdraw money in a specified time period. Instead of purchases, an organization can have only one subscription, and it should replace an existing subscription if it wants a new one.

AttributeTypeDescription
idnumberUnique subscription ID in database
stripe_idstringStripe subscription ID associated with this subscription
organizationrelation (oneToOne)Organization linked to this subscription (linked to organization)
planrelation (oneToOne)Plan linked to this subscription (linked to plan)
statusenumerationSubscription status: trialing, active, cancelled, paused
Transaction

The transaction is an entity that describes how the payment was processed, as all payments need to be recorded. Transactions can be associated with purchases and subscriptions. An organization can have multiple transactions as purchases.

AttributeTypeDescription
idnumberUnique transaction ID in database
subscriptionIdintegerID of the subscription associated with the transaction
organizationrelation (manyToOne)Organization linked to the transaction (related to organization)
purchaseIdintegerID of the purchase associated with the transaction
statusenumerationTransaction status: pending, completed, failed
externalTransactionjsonData from the external payment system (e.g., Stripe)

User routes

MethodEndpoint
POST/stripe-payment/api/organizations
GET/stripe-payment/api/organizations/:id
GET/stripe-payment/api/organizations/:id/default-payment-method
PUT/stripe-payment/api/organizations/:id
DELETE/stripe-payment/api/organizations/:id
PATCH/stripe-payment/api/organizations/:id/owner
PATCH/stripe-payment/api/organizations/:id/users
PATCH/stripe-payment/api/organizations/:id/remove-user
PATCH/stripe-payment/api/organizations/:id/default-payment-method
GET/stripe-payment/api/plans/:id
POST/stripe-payment/api/subscriptions/checkout-session
GET/stripe-payment/api/subscriptions/:id
GET/stripe-payment/api/subscriptions
PATCH/stripe-payment/api/subscriptions/:id/pause
PATCH/stripe-payment/api/subscriptions/:id/cancel
PATCH/stripe-payment/api/subscriptions/:id/resume
DELETE/stripe-payment/api/subscriptions/:id
PATCH/stripe-payment/api/subscriptions/:id
PATCH/stripe-payment/api/subscriptions/:id/resubscribe
GET/stripe-payment/api/products
GET/stripe-payment/api/products/:id
GET/stripe-payment/api/transactions

Webhook

MethodEndpoint
POST/stripe-payment/api/webhook

License

DBBS Strapi-stripe payment is open-source software licensed under the MIT License.

Authors

Links

Install now

npm install @dbbs/strapi-stripe-payment

STATS

No GitHub star yet26 weekly downloads

Last updated

61 days ago

Strapi Version

4.25.8

Author

github profile image for DBB Software
DBB Software

Useful links

Create your own plugin

Check out the available plugin resources that will help you to develop your plugin or provider and get it listed on the marketplace.