Subscription Plans
Manage customer subscriptions through MoneyHash JS SDK starting from v2.3.0
Retrieve Subscription plans for a Customer
Get a list of subscription plans for a customer based on Plan Group ID
const subscriptionPlans = await moneyHash.getSubscriptionPlans({
planGroupId: "<plan-group-id>",
customerId: "<customer-id>",
});
console.log(subscriptionPlans);
subscriptionPlans
will be an array of SubscriptionPlan
with all details related to the plan & boolean flag for subscription made for the customer before for this plan.
export type SubscriptionPlan = {
id: string;
alreadySubscribed: boolean;
amount: number;
created: string;
currency: string;
description: string;
discountAmount: number | null;
discountCycles: number | null;
discountPercentage: number | null;
name: string;
oneTimeFee: number | null;
recurrency: number;
recurrencyUnit: "MONTH";
recurringCycles: number | null;
trialPeriod: number | null;
isLive: boolean;
};
You can render the list of plans in your application with your custom UI to allow customers to select from.
Subscribe a customer to a subscription plan
moneyHash.selectSubscriptionPlan
Let you select a plan from the list of plans to let the customer subscribe to it.
It will respond with payment intent details to complete the full payment cycle. You can check the full JS SDK guide for payment integration
const intentDetails = await moneyHash.selectSubscriptionPlan({
planGroupId: "<plan-group-id>",
customerId: "<customer-id>",
planId: "<selected-plan-id>",
});
Updated 13 days ago