bkper-js 2.26.1 → 2.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -12,8 +12,11 @@ See what's new and what has changed in bkper-js
12
12
  - Added `Config.agentIdProvider`
13
13
  - Added `Billing`
14
14
  - Added `Billing.getAdminEmail`
15
+ - Added `Billing.getCheckoutUrl`
15
16
  - Added `Billing.getCounts`
16
17
  - Added `Billing.getDaysLeftInTrial`
18
+ - Added `Billing.getEmail`
19
+ - Added `Billing.getHostedDomain`
17
20
  - Added `Billing.getPlan`
18
21
  - Added `Billing.getPortalUrl`
19
22
  - Added `Billing.getTotalTransactionsThisMonth`
package/lib/index.d.ts CHANGED
@@ -1176,6 +1176,18 @@ export declare class Billing extends Resource<bkper.Billing> {
1176
1176
  * @returns True if billing is enabled for the User
1177
1177
  */
1178
1178
  isEnabled(): boolean | undefined;
1179
+ /**
1180
+ * Gets the email for the User.
1181
+ *
1182
+ * @returns The User's email
1183
+ */
1184
+ getEmail(): string | undefined;
1185
+ /**
1186
+ * Gets the hosted domain for the User.
1187
+ *
1188
+ * @returns The User's hosted domain
1189
+ */
1190
+ getHostedDomain(): string | undefined;
1179
1191
  /**
1180
1192
  * Gets the current plan of the User.
1181
1193
  *
@@ -1232,6 +1244,14 @@ export declare class Billing extends Resource<bkper.Billing> {
1232
1244
  * @returns The URL to redirect the User to the billing portal
1233
1245
  */
1234
1246
  getPortalUrl(returnUrl: string): Promise<string | undefined>;
1247
+ /**
1248
+ * Gets the URL to redirect the User to the billing checkout.
1249
+ *
1250
+ * @param plan - The plan to checkout
1251
+ *
1252
+ * @returns The URL to redirect the User to the billing checkout
1253
+ */
1254
+ getCheckoutUrl(plan: string, successUrl?: string, cancelUrl?: string): Promise<string | undefined>;
1235
1255
  }
1236
1256
 
1237
1257
  /**
@@ -34,6 +34,22 @@ export class Billing extends Resource {
34
34
  isEnabled() {
35
35
  return this.payload.enabled;
36
36
  }
37
+ /**
38
+ * Gets the email for the User.
39
+ *
40
+ * @returns The User's email
41
+ */
42
+ getEmail() {
43
+ return this.payload.email;
44
+ }
45
+ /**
46
+ * Gets the hosted domain for the User.
47
+ *
48
+ * @returns The User's hosted domain
49
+ */
50
+ getHostedDomain() {
51
+ return this.payload.hostedDomain;
52
+ }
37
53
  /**
38
54
  * Gets the current plan of the User.
39
55
  *
@@ -111,7 +127,20 @@ export class Billing extends Resource {
111
127
  getPortalUrl(returnUrl) {
112
128
  return __awaiter(this, void 0, void 0, function* () {
113
129
  const urlPayload = yield UserService.getBillingPortalUrl(returnUrl, this.getConfig());
114
- return urlPayload.url;
130
+ return urlPayload === null || urlPayload === void 0 ? void 0 : urlPayload.url;
131
+ });
132
+ }
133
+ /**
134
+ * Gets the URL to redirect the User to the billing checkout.
135
+ *
136
+ * @param plan - The plan to checkout
137
+ *
138
+ * @returns The URL to redirect the User to the billing checkout
139
+ */
140
+ getCheckoutUrl(plan, successUrl, cancelUrl) {
141
+ return __awaiter(this, void 0, void 0, function* () {
142
+ const urlPayload = yield UserService.getBillingCheckoutUrl(plan, successUrl, cancelUrl, this.getConfig());
143
+ return urlPayload === null || urlPayload === void 0 ? void 0 : urlPayload.url;
115
144
  });
116
145
  }
117
146
  }
@@ -94,8 +94,6 @@ export class HttpApiRequest extends HttpRequest {
94
94
  return yield this.fetch();
95
95
  }
96
96
  }
97
- // Other errors
98
- console.log("Error", error);
99
97
  throw this.handleError(error);
100
98
  }
101
99
  });
@@ -32,4 +32,17 @@ export function getBillingPortalUrl(returnUrl, config) {
32
32
  return res.data;
33
33
  });
34
34
  }
35
+ export function getBillingCheckoutUrl(plan, successUrl, cancelUrl, config) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ const request = new HttpApiV5Request(`user/billing/checkout`, config).addParam('plan', plan);
38
+ if (successUrl) {
39
+ request.addParam('successUrl', successUrl);
40
+ }
41
+ if (cancelUrl) {
42
+ request.addParam('cancelUrl', cancelUrl);
43
+ }
44
+ const res = yield request.fetch();
45
+ return res.data;
46
+ });
47
+ }
35
48
  //# sourceMappingURL=user-service.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bkper-js",
3
- "version": "2.26.1",
3
+ "version": "2.27.0",
4
4
  "description": "Javascript client for Bkper REST API",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",
@@ -35,7 +35,7 @@
35
35
  "postversion": "git push --tags && yarn publish --new-version $npm_package_version && git push && echo \"Successfully released version $npm_package_version!\""
36
36
  },
37
37
  "dependencies": {
38
- "@bkper/bkper-api-types": "^5.34.0",
38
+ "@bkper/bkper-api-types": "^5.35.0",
39
39
  "big.js": "^6.0.3",
40
40
  "dayjs": "^1.10.3",
41
41
  "luxon": "^1.25.0",