UNPKG

@bebapps/rapyd-sdk

Version:

An un-official [Rapyd](https://rapyd.net) SDK for Node.js.

59 lines (52 loc) 2.35 kB
import { RapydClient } from '../../../core/RapydClient'; import { Plan } from '../types/Plan'; import { PlanError } from '../enums/PlanError'; import { CreatePlanRequest } from '../requests/CreatePlanRequest'; import { UpdatePlanRequest } from '../requests/UpdatePlanRequest'; import { RetrievePlanRequest } from '../requests/RetrievePlanRequest'; import { ListPlansRequest } from '../requests/ListPlansRequest'; import { DeletePlanRequest } from '../requests/DeletePlanRequest'; export async function createPlan<R = Plan>(client: RapydClient, request: CreatePlanRequest): Promise<R> { const response = await client.post('/v1/plans', { aggregate_usage: request.aggregate_usage, amount: request.amount, billing_scheme: request.billing_scheme, currency: request.currency, id: request.id, interval: request.interval, interval_count: request.interval_count, metadata: request.metadata, nickname: request.nickname, trial_period_days: request.trial_period_days, product: request.product, tiers: request.tiers, tiers_mode: request.tiers_mode, transform_usage: request.transform_usage, usage_type: request.usage_type, }); return await response.data<R, PlanError>(); } export async function updatePlan<R = Plan>(client: RapydClient, request: UpdatePlanRequest): Promise<R> { const response = await client.post('/v1/plans/{}', request.plan, { nickname: request.nickname, metadata: request.metadata, }); return await response.data<R, PlanError>(); } export async function retrievePlan<R = Plan>(client: RapydClient, request: RetrievePlanRequest): Promise<R> { const response = await client.get('/v1/plans/{}', request.plan); return await response.data<R, PlanError>(); } export async function listPlans<R = Plan>(client: RapydClient, request: ListPlansRequest): Promise<R> { const queryParams = client.queryParams({ ending_before: request.ending_before, limit: request.limit, starting_after: request.starting_after, }); const response = await client.get('/v1/plans' + queryParams); return await response.data<R, PlanError>(); } export async function deletePlan<R = Plan>(client: RapydClient, request: DeletePlanRequest): Promise<R> { const response = await client.delete('/v1/plans/{}', request.plan); return await response.data<R, PlanError>(); }