Skip to content

Commit

Permalink
Merge pull request #216 from prezly/feature/support-plan-api
Browse files Browse the repository at this point in the history
[DEV-10153] Feature - Support Plan API
  • Loading branch information
marko-ogg authored Feb 22, 2023
2 parents ca2cbef + 7240c89 commit 4ddb008
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/endpoints/Billing/Client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { DeferredJobsApiClient } from '../../api';
import { routing } from '../../routing';
import type { Plan } from '../../types';

import type { SignupRequest, SignupResponse } from './types';

Expand All @@ -14,4 +15,9 @@ export class Client {
const url = `${routing.billing}/signup`;
return this.apiClient.post<SignupResponse>(url, { payload });
}

async getPlan(): Promise<Plan> {
const { plan } = await this.apiClient.get<{ plan: Plan }>(`${routing.billing}/plan`);
return plan;
}
}
12 changes: 2 additions & 10 deletions src/types/License.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Currency } from './Currency';
import type { PlanLevel } from './Plan';
import type { PlanLevel, PlanReference } from './Plan';

export interface LicenseRef {
id: number;
Expand Down Expand Up @@ -62,7 +62,7 @@ export interface License extends LicenseRef {
* use "plan" instead.
*/
plan_level: PlanLevel | null;
plan: License.Plan | null;
plan: PlanReference | null;
status: License.Status;
subscription_lockout: boolean;
/**
Expand Down Expand Up @@ -112,12 +112,4 @@ export namespace License {
CANCELED = 'canceled',
UNPAID = 'unpaid',
}

export interface Plan {
display_name: string | null;
description: string | null;
is_legacy: boolean;
is_superior: boolean;
pricing_table_option_id: string | null;
}
}
24 changes: 24 additions & 0 deletions src/types/Plan.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
import type { Limit } from '../endpoints/PricingTables';

export interface PlanReference {
display_name: string;
description: string | null;
is_legacy: boolean;
is_deprecated: boolean;
is_superior: boolean;
is_trial: boolean;
pricing_table_option_id: string | null;
}

export interface Plan extends PlanReference {
billing_cycle: string;
currency: string;
usage: Usage[];
}

export interface Usage {
limit: Limit;
used: number;
}

/** @deprecated Will be dropped in future */
export enum PlanLevel {
BASIC = 'basic',
CORE = 'core',
Expand Down

0 comments on commit 4ddb008

Please sign in to comment.