Skip to content

Commit cf94ec9

Browse files
Add plan service
1 parent 640f4f2 commit cf94ec9

File tree

6 files changed

+372
-0
lines changed

6 files changed

+372
-0
lines changed

EXAMPLES.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2426,6 +2426,66 @@ CrispClient.plugin.dispatchPluginEvent(websiteID, pluginID, payload);
24262426

24272427
=========================
24282428

2429+
https://docs.crisp.chat/references/rest-api/v1/#list-all-active-plan-subscriptions
2430+
2431+
var websiteID = "8c842203-7ed8-4e29-a608-7cf78a7d2fcc";
2432+
2433+
CrispClient.plan.listAllActiveSubscriptions();
2434+
2435+
=========================
2436+
2437+
https://docs.crisp.chat/references/rest-api/v1/#get-plan-subscription-for-a-website
2438+
2439+
var websiteID = "8c842203-7ed8-4e29-a608-7cf78a7d2fcc";
2440+
2441+
CrispClient.plan.getPlanSubscriptionForWebsite(websiteID);
2442+
2443+
=========================
2444+
2445+
https://docs.crisp.chat/references/rest-api/v1/#subscribe-website-to-plan
2446+
2447+
var websiteID = "8c842203-7ed8-4e29-a608-7cf78a7d2fcc";
2448+
var planID = "d678dbc1-e49d-47d3-92f2-c436f5b0e4a5";
2449+
2450+
CrispClient.plan.subscribeWebsiteToPlan(websiteID, planID);
2451+
2452+
=========================
2453+
2454+
https://docs.crisp.chat/references/rest-api/v1/#unsubscribe-plan-from-website
2455+
2456+
var websiteID = "8c842203-7ed8-4e29-a608-7cf78a7d2fcc";
2457+
2458+
CrispClient.plan.unsubscribePlanFromWebsite(websiteID);
2459+
2460+
=========================
2461+
2462+
https://docs.crisp.chat/references/rest-api/v1/#change-bill-period-for-website-plan-subscription
2463+
2464+
var websiteID = "8c842203-7ed8-4e29-a608-7cf78a7d2fcc";
2465+
var period = "yearly";
2466+
2467+
CrispClient.plan.changeBillPeriodForWebsitePlanSubscription(websiteID, period);
2468+
2469+
=========================
2470+
2471+
https://docs.crisp.chat/references/rest-api/v1/#check-coupon-availability-for-website-plan-subscription
2472+
2473+
var websiteID = "8c842203-7ed8-4e29-a608-7cf78a7d2fcc";
2474+
var code = "CRISP+AWESOME";
2475+
2476+
CrispClient.plan.checkCouponAvailabilityForWebsitePlanSubscription(websiteID, code);
2477+
2478+
=========================
2479+
2480+
https://docs.crisp.chat/references/rest-api/v1/#redeem-coupon-for-website-plan-subscription
2481+
2482+
var websiteID = "8c842203-7ed8-4e29-a608-7cf78a7d2fcc";
2483+
var code = "CRISP+AWESOME";
2484+
2485+
CrispClient.plan.redeemCouponForWebsitePlanSubscription(websiteID, code);
2486+
2487+
=========================
2488+
24292489
https://docs.crisp.chat/references/rest-api/v1/#list-animation-medias
24302490

24312491
var listID = "f7fb43da-1cd8-49c1-ade0-9f5b71d034e3";

README.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ All methods that you will most likely need when building a Crisp integration are
125125
<li><a href="#plugin-subscription">Plugin Subscription</a></li>
126126
</ul>
127127
</details>
128+
<details>
129+
<summary>
130+
<a href="#plan">Plan</a>
131+
</summary>
132+
<ul>
133+
<li><a href="#plan-subscription">Plan Subscription</a></li>
134+
</ul>
135+
</details>
128136
<details>
129137
<summary>
130138
<a href="#media">Media</a>
@@ -3461,6 +3469,96 @@ _👉 Notice: The `peopleID` argument can be an email or the `peopleID`._
34613469
</details>
34623470

34633471

3472+
### Plan
3473+
3474+
* #### **Plan Subscription**
3475+
* **List All Active Plan Subscriptions** [`user`]: [Reference](https://docs.crisp.chat/references/rest-api/v1/#list-all-active-plan-subscriptions)
3476+
* `CrispClient.plan.listAllActiveSubscriptions()`
3477+
* <details>
3478+
<summary>See Example</summary>
3479+
3480+
```javascript
3481+
CrispClient.plan.listAllActiveSubscriptions();
3482+
```
3483+
</details>
3484+
3485+
* **Get Plan Subscription For A Website** [`user`, `plugin`]: [Reference](https://docs.crisp.chat/references/rest-api/v1/#get-plan-subscription-for-a-website)
3486+
* `CrispClient.plan.getPlanSubscriptionForWebsite(websiteID)`
3487+
* <details>
3488+
<summary>See Example</summary>
3489+
3490+
```javascript
3491+
var websiteID = "8c842203-7ed8-4e29-a608-7cf78a7d2fcc";
3492+
3493+
CrispClient.plan.getPlanSubscriptionForWebsite(websiteID);
3494+
```
3495+
</details>
3496+
3497+
* **Subscribe Website To Plan** [`user`]: [Reference](https://docs.crisp.chat/references/rest-api/v1/#subscribe-website-to-plan)
3498+
* `CrispClient.plan.subscribeWebsiteToPlan(websiteID, planID)`
3499+
* <details>
3500+
<summary>See Example</summary>
3501+
3502+
```javascript
3503+
var websiteID = "8c842203-7ed8-4e29-a608-7cf78a7d2fcc";
3504+
var planID = "d678dbc1-e49d-47d3-92f2-c436f5b0e4a5";
3505+
3506+
CrispClient.plan.subscribeWebsiteToPlan(websiteID, planID);
3507+
```
3508+
</details>
3509+
3510+
* **Unsubscribe Plan From Website** [`user`]: [Reference](https://docs.crisp.chat/references/rest-api/v1/#unsubscribe-plan-from-website)
3511+
* `CrispClient.plan.unsubscribePlanFromWebsite(websiteID)`
3512+
* <details>
3513+
<summary>See Example</summary>
3514+
3515+
```javascript
3516+
var websiteID = "8c842203-7ed8-4e29-a608-7cf78a7d2fcc";
3517+
3518+
CrispClient.plan.unsubscribePlanFromWebsite(websiteID);
3519+
```
3520+
</details>
3521+
3522+
* **Change Bill Period For Website Plan Subscription** [`user`]: [Reference](https://docs.crisp.chat/references/rest-api/v1/#change-bill-period-for-website-plan-subscription)
3523+
* `CrispClient.plan.changeBillPeriodForWebsitePlanSubscription(websiteID, period)`
3524+
* <details>
3525+
<summary>See Example</summary>
3526+
3527+
```javascript
3528+
var websiteID = "8c842203-7ed8-4e29-a608-7cf78a7d2fcc";
3529+
var period = "yearly";
3530+
3531+
CrispClient.plan.changeBillPeriodForWebsitePlanSubscription(websiteID, period);
3532+
```
3533+
</details>
3534+
3535+
* **Check Coupon Availability For Website Plan Subscription** [`user`]: [Reference](https://docs.crisp.chat/references/rest-api/v1/#check-coupon-availability-for-website-plan-subscription)
3536+
* `CrispClient.plan.checkCouponAvailabilityForWebsitePlanSubscription(websiteID, code)`
3537+
* <details>
3538+
<summary>See Example</summary>
3539+
3540+
```javascript
3541+
var websiteID = "8c842203-7ed8-4e29-a608-7cf78a7d2fcc";
3542+
var code = "CRISP+AWESOME";
3543+
3544+
CrispClient.plan.checkCouponAvailabilityForWebsitePlanSubscription(websiteID, code);
3545+
```
3546+
</details>
3547+
3548+
* **Redeem Coupon For Website Plan Subscription** [`user`]: [Reference](https://docs.crisp.chat/references/rest-api/v1/#redeem-coupon-for-website-plan-subscription)
3549+
* `CrispClient.plan.redeemCouponForWebsitePlanSubscription(websiteID, code)`
3550+
* <details>
3551+
<summary>See Example</summary>
3552+
3553+
```javascript
3554+
var websiteID = "8c842203-7ed8-4e29-a608-7cf78a7d2fcc";
3555+
var code = "CRISP+AWESOME";
3556+
3557+
CrispClient.plan.redeemCouponForWebsitePlanSubscription(websiteID, code);
3558+
```
3559+
</details>
3560+
3561+
34643562
### Media
34653563

34663564
* #### **Media Animation**

lib/crisp.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import mitt, { Emitter } from "mitt";
2222
import Bucket, { BucketServiceInterface } from "@/services/bucket";
2323
import Media, { MediaServiceInterface } from "@/services/media";
2424
import Plugin, { PluginServiceInterface } from "@/services/plugin";
25+
import Plan, { PlanServiceInterface } from "@/services/plan";
2526
import Website, { WebsiteServiceInterface } from "@/services/website";
2627

2728
/**************************************************************************
@@ -175,6 +176,7 @@ const services = {
175176
Bucket: Bucket,
176177
Media: Media,
177178
Plugin: Plugin,
179+
Plan: Plan,
178180
Website: Website
179181
};
180182

@@ -209,6 +211,10 @@ class Crisp {
209211
new Plugin() as unknown as PluginServiceInterface
210212
);
211213

214+
public plan: PlanServiceInterface = (
215+
new Plan() as unknown as PlanServiceInterface
216+
);
217+
212218
public website: WebsiteServiceInterface = (
213219
new Website() as unknown as WebsiteServiceInterface
214220
);

lib/resources/PlanSubscription.ts

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
/*
2+
* This file is part of node-crisp-api
3+
*
4+
* Copyright (c) 2026 Crisp IM SAS
5+
* All rights belong to Crisp IM SAS
6+
*/
7+
8+
/**************************************************************************
9+
* IMPORTS
10+
***************************************************************************/
11+
12+
// PROJECT: RESOURCES
13+
import BaseResource from "./BaseResource";
14+
15+
/**************************************************************************
16+
* TYPES
17+
***************************************************************************/
18+
19+
export type PlanSubscription = {
20+
id?: string;
21+
name?: string;
22+
price?: number;
23+
since?: string;
24+
trialing?: boolean;
25+
trial_end?: string;
26+
trial_end_date?: string;
27+
bill_period?: PlanSubscriptionBillPeriod;
28+
bill_valid_until?: string;
29+
active?: boolean;
30+
sandbox?: boolean;
31+
website?: PlanSubscriptionWebsite;
32+
coupon_redeemed?: boolean;
33+
card_id?: string;
34+
owner?: PlanSubscriptionOwner;
35+
}
36+
37+
export type PlanSubscriptionBillPeriod = "monthly" | "yearly";
38+
39+
export type PlanSubscriptionWebsite = {
40+
id?: string;
41+
name?: string;
42+
domain?: string;
43+
logo?: string;
44+
}
45+
46+
export type PlanSubscriptionOwner = {
47+
user_id?: string;
48+
email?: string;
49+
first_name?: string;
50+
last_name?: string;
51+
}
52+
53+
export type PlanSubscriptionCoupon = {
54+
code?: string;
55+
policy?: PlanSubscriptionCouponPolicy;
56+
redeem_limit?: number;
57+
expire_at?: string;
58+
}
59+
60+
export type PlanSubscriptionCouponPolicy = {
61+
rebate_percent?: number;
62+
trial_days?: number;
63+
}
64+
65+
/**************************************************************************
66+
* CLASSES
67+
***************************************************************************/
68+
69+
/**
70+
* Crisp PlanSubscription Resource
71+
*/
72+
class PlanSubscriptionService extends BaseResource {
73+
/**
74+
* List All Active Plan Subscriptions
75+
*/
76+
listAllActiveSubscriptions(): Promise<PlanSubscription[]> {
77+
return this.crisp.get(
78+
this.crisp.prepareRestUrl(["plans", "subscription"])
79+
);
80+
};
81+
82+
/**
83+
* Get Plan Subscription For A Website
84+
*/
85+
getPlanSubscriptionForWebsite(websiteID: string): Promise<PlanSubscription> {
86+
return this.crisp.get(
87+
this.crisp.prepareRestUrl(["plans", "subscription", websiteID])
88+
);
89+
};
90+
91+
/**
92+
* Subscribe Website To Plan
93+
*/
94+
subscribeWebsiteToPlan(websiteID: string, planID: string) {
95+
return this.crisp.post(
96+
this.crisp.prepareRestUrl(["plans", "subscription", websiteID]),
97+
98+
null,
99+
100+
{
101+
plan_id: planID
102+
}
103+
);
104+
};
105+
106+
/**
107+
* Unsubscribe Plan From Website
108+
*/
109+
unsubscribePlanFromWebsite(websiteID: string) {
110+
return this.crisp.delete(
111+
this.crisp.prepareRestUrl(["plans", "subscription", websiteID])
112+
);
113+
};
114+
115+
/**
116+
* Change Bill Period For Website Plan Subscription
117+
*/
118+
changeBillPeriodForWebsitePlanSubscription(
119+
websiteID: string,
120+
period: PlanSubscriptionBillPeriod
121+
) {
122+
return this.crisp.patch(
123+
this.crisp.prepareRestUrl([
124+
"plans", "subscription", websiteID, "bill", "period"
125+
]),
126+
127+
null,
128+
129+
{
130+
period
131+
}
132+
);
133+
};
134+
135+
/**
136+
* Check Coupon Availability For Website Plan Subscription
137+
*/
138+
checkCouponAvailabilityForWebsitePlanSubscription(
139+
websiteID: string,
140+
code: string
141+
): Promise<PlanSubscriptionCoupon> {
142+
return this.crisp.get(
143+
this.crisp.prepareRestUrl(["plans", "subscription", websiteID, "coupon"]),
144+
145+
{
146+
code
147+
}
148+
);
149+
};
150+
151+
/**
152+
* Redeem Coupon For Website Plan Subscription
153+
*/
154+
redeemCouponForWebsitePlanSubscription(websiteID: string, code: string) {
155+
return this.crisp.patch(
156+
this.crisp.prepareRestUrl(["plans", "subscription", websiteID, "coupon"]),
157+
158+
null,
159+
160+
{
161+
code
162+
}
163+
);
164+
};
165+
}
166+
167+
/**************************************************************************
168+
* EXPORTS
169+
***************************************************************************/
170+
171+
export default PlanSubscriptionService;

lib/resources/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export * from "./BucketURL";
1414
export * from "./MediaAnimation";
1515
export * from "./PluginConnect";
1616
export * from "./PluginSubscription";
17+
export * from "./PlanSubscription";
1718
export * from "./WebsiteAnalytics";
1819
export * from "./WebsiteAvailability";
1920
export * from "./WebsiteBase";

0 commit comments

Comments
 (0)