Superface

Create Subscription

payments/create-subscription@1.0.0
2 providers

Create Subscription

Creates a subscription for a subscription plan in a payment system.

Input
Plan ID
Customer Identificator
Result
ID
Status

1.Choose a provider

2.Use CreateSubscription with mock in your code

Below instructions are for our Node.js SDK. Use OneService for other languages.
npm i @superfaceai/one-sdk
const { SuperfaceClient } = require('@superfaceai/one-sdk');

// You can manage tokens here: https://superface.ai/insights
const sdk = new SuperfaceClient({ sdkAuthToken: '<< Login to get your token >>' });

async function run() {
  // Load the profile
  const profile = await sdk.getProfile('payments/create-subscription@1.0.0');

  // Use the profile
  const result = await profile
    .getUseCase('CreateSubscription')
    .perform({
      planId: 'PLAN-89101829211',
      customer: 'joe@example.com'
    }, {
      provider: 'mock'
    });

  // Handle the result
  try {
    const data = result.unwrap();
    console.log(data);
  } catch (error) {
    console.error(error);
  }
}

run();

Structure details

Input (object)

planId
ID of the plan to create a subscription for.
customer
Unique customer identficator specific to payment system (e.g. e-mail)

Example

{
  "planId": "PLAN-89101829211",
  "customer": "joe@example.com"
}

Result (object)

subscriptionId
Unique identifier of the subscription.
status
Status of the subscription. Possible values: - `pending` - The subscription has been created, but not yet approved. - `approved` - The subscription has been approved by the buyer. - `active` - The subscription is active. - `trialing` - The subscription is currently in its trial period. - `past_due` - The subscription failed to be paid. - `suspended` - The subscription has been suspended. - `unpaid` - The subscription failed to be paid, and all retry attempts have been exhausted. - `cancelled` - The subscription has been cancelled. - `expired` - The subscription has expired.

Example

{
  "subscriptionId": "91273981273918273",
  "status": "active"
}

Implementation details

Provider
mock
Use case
CreateSubscription
Author
@superface
Source
Verified