univapay-node 2.1.2 → 3.0.2
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/dist/cjs/api/RestAPI.d.ts +44 -39
- package/dist/cjs/api/RestAPI.js +136 -232
- package/dist/cjs/api/RestAPI.js.map +1 -1
- package/dist/cjs/api/index.js +1 -1
- package/dist/cjs/api/utils/JWT.js +11 -12
- package/dist/cjs/api/utils/JWT.js.map +1 -1
- package/dist/cjs/api/utils/payload.js +16 -23
- package/dist/cjs/api/utils/payload.js.map +1 -1
- package/dist/cjs/api/utils/userAgent.js +14 -16
- package/dist/cjs/api/utils/userAgent.js.map +1 -1
- package/dist/cjs/common/index.js +1 -1
- package/dist/cjs/errors/APIError.d.ts +7 -5
- package/dist/cjs/errors/APIError.js +8 -12
- package/dist/cjs/errors/APIError.js.map +1 -1
- package/dist/cjs/errors/JWTError.js +5 -9
- package/dist/cjs/errors/JWTError.js.map +1 -1
- package/dist/cjs/errors/PathParameterError.js +6 -10
- package/dist/cjs/errors/PathParameterError.js.map +1 -1
- package/dist/cjs/errors/RequestParameterError.js +6 -10
- package/dist/cjs/errors/RequestParameterError.js.map +1 -1
- package/dist/cjs/errors/RequestResponseError.js +32 -48
- package/dist/cjs/errors/RequestResponseError.js.map +1 -1
- package/dist/cjs/errors/TimeoutError.js +7 -11
- package/dist/cjs/errors/TimeoutError.js.map +1 -1
- package/dist/cjs/errors/index.js +1 -1
- package/dist/cjs/errors/parser.js +5 -5
- package/dist/cjs/errors/parser.js.map +1 -1
- package/dist/cjs/index.js +28 -31
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/resources/BankAccounts.d.ts +13 -7
- package/dist/cjs/resources/BankAccounts.js +29 -29
- package/dist/cjs/resources/BankAccounts.js.map +1 -1
- package/dist/cjs/resources/CRUDResource.d.ts +6 -6
- package/dist/cjs/resources/CRUDResource.js +22 -26
- package/dist/cjs/resources/CRUDResource.js.map +1 -1
- package/dist/cjs/resources/Cancels.d.ts +8 -12
- package/dist/cjs/resources/Cancels.js +22 -33
- package/dist/cjs/resources/Cancels.js.map +1 -1
- package/dist/cjs/resources/Captures.d.ts +9 -4
- package/dist/cjs/resources/Captures.js +8 -13
- package/dist/cjs/resources/Captures.js.map +1 -1
- package/dist/cjs/resources/Charges.d.ts +9 -13
- package/dist/cjs/resources/Charges.js +28 -45
- package/dist/cjs/resources/Charges.js.map +1 -1
- package/dist/cjs/resources/CheckoutInfo.d.ts +3 -2
- package/dist/cjs/resources/CheckoutInfo.js +7 -12
- package/dist/cjs/resources/CheckoutInfo.js.map +1 -1
- package/dist/cjs/resources/ECFormLinks.d.ts +3 -2
- package/dist/cjs/resources/ECFormLinks.js +7 -12
- package/dist/cjs/resources/ECFormLinks.js.map +1 -1
- package/dist/cjs/resources/ECForms.d.ts +3 -2
- package/dist/cjs/resources/ECForms.js +8 -13
- package/dist/cjs/resources/ECForms.js.map +1 -1
- package/dist/cjs/resources/ECInfo.d.ts +3 -2
- package/dist/cjs/resources/ECInfo.js +7 -12
- package/dist/cjs/resources/ECInfo.js.map +1 -1
- package/dist/cjs/resources/Emails.d.ts +11 -2
- package/dist/cjs/resources/Emails.js +16 -13
- package/dist/cjs/resources/Emails.js.map +1 -1
- package/dist/cjs/resources/ExchangeRates.d.ts +3 -2
- package/dist/cjs/resources/ExchangeRates.js +7 -12
- package/dist/cjs/resources/ExchangeRates.js.map +1 -1
- package/dist/cjs/resources/Ledgers.d.ts +5 -3
- package/dist/cjs/resources/Ledgers.js +12 -16
- package/dist/cjs/resources/Ledgers.js.map +1 -1
- package/dist/cjs/resources/Merchants.d.ts +3 -2
- package/dist/cjs/resources/Merchants.js +7 -12
- package/dist/cjs/resources/Merchants.js.map +1 -1
- package/dist/cjs/resources/Platforms.d.ts +3 -2
- package/dist/cjs/resources/Platforms.js +8 -12
- package/dist/cjs/resources/Platforms.js.map +1 -1
- package/dist/cjs/resources/Products.d.ts +3 -2
- package/dist/cjs/resources/Products.js +7 -12
- package/dist/cjs/resources/Products.js.map +1 -1
- package/dist/cjs/resources/Refunds.d.ts +10 -13
- package/dist/cjs/resources/Refunds.js +26 -36
- package/dist/cjs/resources/Refunds.js.map +1 -1
- package/dist/cjs/resources/Resource.d.ts +9 -3
- package/dist/cjs/resources/Resource.js +27 -38
- package/dist/cjs/resources/Resource.js.map +1 -1
- package/dist/cjs/resources/Stores.d.ts +11 -6
- package/dist/cjs/resources/Stores.js +24 -25
- package/dist/cjs/resources/Stores.js.map +1 -1
- package/dist/cjs/resources/Subscriptions.d.ts +24 -24
- package/dist/cjs/resources/Subscriptions.js +82 -116
- package/dist/cjs/resources/Subscriptions.js.map +1 -1
- package/dist/cjs/resources/TemporaryTokenAlias.d.ts +8 -6
- package/dist/cjs/resources/TemporaryTokenAlias.js +25 -20
- package/dist/cjs/resources/TemporaryTokenAlias.js.map +1 -1
- package/dist/cjs/resources/TransactionTokens.d.ts +12 -7
- package/dist/cjs/resources/TransactionTokens.js +28 -32
- package/dist/cjs/resources/TransactionTokens.js.map +1 -1
- package/dist/cjs/resources/Transfers.d.ts +7 -4
- package/dist/cjs/resources/Transfers.js +17 -21
- package/dist/cjs/resources/Transfers.js.map +1 -1
- package/dist/cjs/resources/Verification.d.ts +7 -4
- package/dist/cjs/resources/Verification.js +23 -26
- package/dist/cjs/resources/Verification.js.map +1 -1
- package/dist/cjs/resources/WebHooks.d.ts +11 -6
- package/dist/cjs/resources/WebHooks.js +24 -25
- package/dist/cjs/resources/WebHooks.js.map +1 -1
- package/dist/cjs/resources/common/enums.d.ts +3 -0
- package/dist/cjs/resources/common/enums.js +3 -0
- package/dist/cjs/resources/common/enums.js.map +1 -1
- package/dist/cjs/resources/common/ignoreDescriptor.d.ts +2 -2
- package/dist/cjs/resources/common/ignoreDescriptor.js +18 -25
- package/dist/cjs/resources/common/ignoreDescriptor.js.map +1 -1
- package/dist/cjs/resources/index.js +1 -1
- package/dist/cjs/sdk/PaymentsSDK.js +10 -14
- package/dist/cjs/sdk/PaymentsSDK.js.map +1 -1
- package/dist/cjs/sdk/index.js +1 -1
- package/dist/cjs/sdk/index.js.map +1 -1
- package/dist/cjs/utils/fetch.js +13 -32
- package/dist/cjs/utils/fetch.js.map +1 -1
- package/dist/cjs/utils/index.js +1 -1
- package/dist/cjs/utils/object.js +18 -24
- package/dist/cjs/utils/object.js.map +1 -1
- package/dist/esm/api/RestAPI.d.ts +44 -39
- package/dist/esm/api/RestAPI.js +121 -219
- package/dist/esm/api/RestAPI.js.map +1 -1
- package/dist/esm/api/utils/JWT.js +7 -8
- package/dist/esm/api/utils/JWT.js.map +1 -1
- package/dist/esm/api/utils/payload.js +13 -20
- package/dist/esm/api/utils/payload.js.map +1 -1
- package/dist/esm/api/utils/userAgent.js +11 -13
- package/dist/esm/api/utils/userAgent.js.map +1 -1
- package/dist/esm/common/constants.js +9 -9
- package/dist/esm/common/constants.js.map +1 -1
- package/dist/esm/errors/APIError.d.ts +7 -5
- package/dist/esm/errors/APIError.js +8 -13
- package/dist/esm/errors/APIError.js.map +1 -1
- package/dist/esm/errors/JWTError.js +5 -10
- package/dist/esm/errors/JWTError.js.map +1 -1
- package/dist/esm/errors/PathParameterError.js +6 -11
- package/dist/esm/errors/PathParameterError.js.map +1 -1
- package/dist/esm/errors/RequestParameterError.js +6 -11
- package/dist/esm/errors/RequestParameterError.js.map +1 -1
- package/dist/esm/errors/RequestResponseError.js +29 -49
- package/dist/esm/errors/RequestResponseError.js.map +1 -1
- package/dist/esm/errors/TimeoutError.js +7 -12
- package/dist/esm/errors/TimeoutError.js.map +1 -1
- package/dist/esm/errors/parser.js +1 -1
- package/dist/esm/errors/parser.js.map +1 -1
- package/dist/esm/index.js +26 -31
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/resources/BankAccounts.d.ts +13 -7
- package/dist/esm/resources/BankAccounts.js +27 -28
- package/dist/esm/resources/BankAccounts.js.map +1 -1
- package/dist/esm/resources/CRUDResource.d.ts +6 -6
- package/dist/esm/resources/CRUDResource.js +20 -25
- package/dist/esm/resources/CRUDResource.js.map +1 -1
- package/dist/esm/resources/Cancels.d.ts +8 -12
- package/dist/esm/resources/Cancels.js +21 -33
- package/dist/esm/resources/Cancels.js.map +1 -1
- package/dist/esm/resources/Captures.d.ts +9 -4
- package/dist/esm/resources/Captures.js +7 -13
- package/dist/esm/resources/Captures.js.map +1 -1
- package/dist/esm/resources/Charges.d.ts +9 -13
- package/dist/esm/resources/Charges.js +25 -43
- package/dist/esm/resources/Charges.js.map +1 -1
- package/dist/esm/resources/CheckoutInfo.d.ts +3 -2
- package/dist/esm/resources/CheckoutInfo.js +5 -11
- package/dist/esm/resources/CheckoutInfo.js.map +1 -1
- package/dist/esm/resources/ECFormLinks.d.ts +3 -2
- package/dist/esm/resources/ECFormLinks.js +6 -12
- package/dist/esm/resources/ECFormLinks.js.map +1 -1
- package/dist/esm/resources/ECForms.d.ts +3 -2
- package/dist/esm/resources/ECForms.js +7 -13
- package/dist/esm/resources/ECForms.js.map +1 -1
- package/dist/esm/resources/ECInfo.d.ts +3 -2
- package/dist/esm/resources/ECInfo.js +6 -12
- package/dist/esm/resources/ECInfo.js.map +1 -1
- package/dist/esm/resources/Emails.d.ts +11 -2
- package/dist/esm/resources/Emails.js +14 -12
- package/dist/esm/resources/Emails.js.map +1 -1
- package/dist/esm/resources/ExchangeRates.d.ts +3 -2
- package/dist/esm/resources/ExchangeRates.js +5 -11
- package/dist/esm/resources/ExchangeRates.js.map +1 -1
- package/dist/esm/resources/Ledgers.d.ts +5 -3
- package/dist/esm/resources/Ledgers.js +10 -15
- package/dist/esm/resources/Ledgers.js.map +1 -1
- package/dist/esm/resources/Merchants.d.ts +3 -2
- package/dist/esm/resources/Merchants.js +5 -11
- package/dist/esm/resources/Merchants.js.map +1 -1
- package/dist/esm/resources/Platforms.d.ts +3 -2
- package/dist/esm/resources/Platforms.js +6 -11
- package/dist/esm/resources/Platforms.js.map +1 -1
- package/dist/esm/resources/Products.d.ts +3 -2
- package/dist/esm/resources/Products.js +6 -12
- package/dist/esm/resources/Products.js.map +1 -1
- package/dist/esm/resources/Refunds.d.ts +10 -13
- package/dist/esm/resources/Refunds.js +25 -36
- package/dist/esm/resources/Refunds.js.map +1 -1
- package/dist/esm/resources/Resource.d.ts +9 -3
- package/dist/esm/resources/Resource.js +23 -35
- package/dist/esm/resources/Resource.js.map +1 -1
- package/dist/esm/resources/Stores.d.ts +11 -6
- package/dist/esm/resources/Stores.js +23 -25
- package/dist/esm/resources/Stores.js.map +1 -1
- package/dist/esm/resources/Subscriptions.d.ts +24 -24
- package/dist/esm/resources/Subscriptions.js +78 -114
- package/dist/esm/resources/Subscriptions.js.map +1 -1
- package/dist/esm/resources/TemporaryTokenAlias.d.ts +8 -6
- package/dist/esm/resources/TemporaryTokenAlias.js +23 -19
- package/dist/esm/resources/TemporaryTokenAlias.js.map +1 -1
- package/dist/esm/resources/TransactionTokens.d.ts +12 -7
- package/dist/esm/resources/TransactionTokens.js +26 -31
- package/dist/esm/resources/TransactionTokens.js.map +1 -1
- package/dist/esm/resources/Transfers.d.ts +7 -4
- package/dist/esm/resources/Transfers.js +15 -20
- package/dist/esm/resources/Transfers.js.map +1 -1
- package/dist/esm/resources/Verification.d.ts +7 -4
- package/dist/esm/resources/Verification.js +21 -25
- package/dist/esm/resources/Verification.js.map +1 -1
- package/dist/esm/resources/WebHooks.d.ts +11 -6
- package/dist/esm/resources/WebHooks.js +23 -25
- package/dist/esm/resources/WebHooks.js.map +1 -1
- package/dist/esm/resources/common/enums.d.ts +3 -0
- package/dist/esm/resources/common/enums.js +3 -0
- package/dist/esm/resources/common/enums.js.map +1 -1
- package/dist/esm/resources/common/ignoreDescriptor.d.ts +2 -2
- package/dist/esm/resources/common/ignoreDescriptor.js +17 -24
- package/dist/esm/resources/common/ignoreDescriptor.js.map +1 -1
- package/dist/esm/sdk/PaymentsSDK.js +8 -13
- package/dist/esm/sdk/PaymentsSDK.js.map +1 -1
- package/dist/esm/utils/fetch.js +10 -29
- package/dist/esm/utils/fetch.js.map +1 -1
- package/dist/esm/utils/object.js +15 -22
- package/dist/esm/utils/object.js.map +1 -1
- package/package.json +8 -8
|
@@ -4,10 +4,16 @@
|
|
|
4
4
|
* @module Resources
|
|
5
5
|
*/
|
|
6
6
|
import { EventEmitter } from "events";
|
|
7
|
-
import { AuthParams, HTTPMethod, RestAPI } from "../api/RestAPI.js";
|
|
8
|
-
export declare type DefinedRoute = (data?:
|
|
7
|
+
import { ApiSendOptions, AuthParams, HTTPMethod, RestAPI } from "../api/RestAPI.js";
|
|
8
|
+
export declare type DefinedRoute = (data?: unknown, auth?: AuthParams, pathParams?: Record<string, string>) => Promise<any>;
|
|
9
|
+
export declare type DefineRouteOptions = ApiSendOptions & {
|
|
10
|
+
/**
|
|
11
|
+
* Parameters required for the route to be called.
|
|
12
|
+
*/
|
|
13
|
+
requiredParams?: string[];
|
|
14
|
+
};
|
|
9
15
|
export declare abstract class Resource extends EventEmitter {
|
|
10
16
|
protected api: RestAPI;
|
|
11
17
|
constructor(api: RestAPI);
|
|
12
|
-
protected defineRoute(method: HTTPMethod, path: string,
|
|
18
|
+
protected defineRoute(method: HTTPMethod, path: string, options?: DefineRouteOptions): DefinedRoute;
|
|
13
19
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __assign, __extends } from "tslib";
|
|
2
1
|
/**
|
|
3
2
|
* @internal
|
|
4
3
|
* @module Resources
|
|
@@ -7,7 +6,7 @@ import { EventEmitter } from "events";
|
|
|
7
6
|
import { fromError } from "../errors/parser.js";
|
|
8
7
|
import { PathParameterError } from "../errors/PathParameterError.js";
|
|
9
8
|
import { RequestParameterError } from "../errors/RequestParameterError.js";
|
|
10
|
-
import { isBlob
|
|
9
|
+
import { isBlob } from "../utils/object.js";
|
|
11
10
|
/**
|
|
12
11
|
* Returns a path with pathParams filled into `:paramName`.
|
|
13
12
|
*
|
|
@@ -30,15 +29,15 @@ import { isBlob, toSnakeCase } from "../utils/object.js";
|
|
|
30
29
|
*/
|
|
31
30
|
function compilePath(path, pathParams) {
|
|
32
31
|
return path
|
|
33
|
-
.replace(/\((\w|:|\/)+\)/gi,
|
|
34
|
-
|
|
32
|
+
.replace(/\((\w|:|\/)+\)/gi, (o) => {
|
|
33
|
+
const part = o.replace(/:(\w+)/gi, (s, p) => {
|
|
35
34
|
return pathParams[p] || s;
|
|
36
35
|
});
|
|
37
36
|
return part.indexOf(":") === -1 ? part.replace(/\(|\)/g, "") : "";
|
|
38
37
|
})
|
|
39
|
-
.replace(/:(\w+)/gi,
|
|
38
|
+
.replace(/:(\w+)/gi, (s, p) => pathParams[p] || s);
|
|
40
39
|
}
|
|
41
|
-
|
|
40
|
+
const getObjectType = (data) => {
|
|
42
41
|
switch (true) {
|
|
43
42
|
case data === null:
|
|
44
43
|
return "null";
|
|
@@ -50,28 +49,21 @@ var getObjectType = function (data) {
|
|
|
50
49
|
return typeof data;
|
|
51
50
|
}
|
|
52
51
|
};
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
_this.on("newListener", function (event, listener) {
|
|
52
|
+
export class Resource extends EventEmitter {
|
|
53
|
+
constructor(api) {
|
|
54
|
+
super();
|
|
55
|
+
this.api = api;
|
|
56
|
+
this.on("newListener", (event, listener) => {
|
|
59
57
|
if (event === "newListener" || event === "removeListener") {
|
|
60
58
|
return;
|
|
61
59
|
}
|
|
62
60
|
api.on(event, listener);
|
|
63
61
|
});
|
|
64
|
-
|
|
65
|
-
return _this;
|
|
62
|
+
this.on("removeListener", (event, listener) => api.removeListener(event, listener));
|
|
66
63
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (requireAuth === void 0) { requireAuth = true; }
|
|
71
|
-
if (keyFormatter === void 0) { keyFormatter = toSnakeCase; }
|
|
72
|
-
return function (originalData, callback, auth, pathParams) {
|
|
73
|
-
var _a, _b;
|
|
74
|
-
if (pathParams === void 0) { pathParams = {}; }
|
|
64
|
+
defineRoute(method, path, options = {}) {
|
|
65
|
+
return (originalData, auth, pathParams = {}) => {
|
|
66
|
+
const { requiredParams = [], ...sendOptions } = options;
|
|
75
67
|
/**
|
|
76
68
|
* Sanitizes and ensures that the data is recreated as an object with default prototypes.
|
|
77
69
|
* In rare cases if the data was created with `Object.create(null)` (no prototypes),
|
|
@@ -79,26 +71,22 @@ var Resource = /** @class */ (function (_super) {
|
|
|
79
71
|
*
|
|
80
72
|
* Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create#custom_and_null_objects
|
|
81
73
|
*/
|
|
82
|
-
|
|
83
|
-
|
|
74
|
+
const data = getObjectType(originalData) === "object" ? { ...originalData } : originalData;
|
|
75
|
+
const url = compilePath(path, pathParams);
|
|
84
76
|
// Validate required path parameters
|
|
85
|
-
|
|
77
|
+
const firstMissingPathParam = url.match(/:([a-z]+)/gi)?.[0]?.replace(":", "");
|
|
86
78
|
if (firstMissingPathParam) {
|
|
87
|
-
|
|
88
|
-
callback === null || callback === void 0 ? void 0 : callback(error);
|
|
79
|
+
const error = fromError(new PathParameterError(firstMissingPathParam));
|
|
89
80
|
return Promise.reject(error);
|
|
90
81
|
}
|
|
91
82
|
// Validate required body parameters
|
|
92
|
-
|
|
83
|
+
const firstMissingParam = data ? requiredParams.find((key) => data[key] === undefined) : requiredParams[0];
|
|
93
84
|
if (firstMissingParam) {
|
|
94
|
-
|
|
95
|
-
callback === null || callback === void 0 ? void 0 : callback(error);
|
|
85
|
+
const error = fromError(new RequestParameterError(firstMissingParam));
|
|
96
86
|
return Promise.reject(error);
|
|
97
87
|
}
|
|
98
|
-
return
|
|
88
|
+
return this.api.send(method, url, data, auth, sendOptions);
|
|
99
89
|
};
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
}(EventEmitter));
|
|
103
|
-
export { Resource };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
104
92
|
//# sourceMappingURL=Resource.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Resource.js","sourceRoot":"","sources":["../../../src/resources/Resource.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Resource.js","sourceRoot":"","sources":["../../../src/resources/Resource.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGtC,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAI5C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAS,WAAW,CAAC,IAAY,EAAE,UAAkC;IACjE,OAAO,IAAI;SACN,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAS,EAAE,EAAE;QACvC,MAAM,IAAI,GAAW,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAS,EAAE,CAAS,EAAE,EAAE;YAChE,OAAO,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAC9B,CAAC,CAAC,CAAC;QACH,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACtE,CAAC,CAAC;SACD,OAAO,CAAC,UAAU,EAAE,CAAC,CAAS,EAAE,CAAS,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AAC3E,CAAC;AAeD,MAAM,aAAa,GAAG,CAAC,IAAa,EAAc,EAAE;IAChD,QAAQ,IAAI,EAAE;QACV,KAAK,IAAI,KAAK,IAAI;YACd,OAAO,MAAM,CAAC;QAElB,KAAK,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;YACpB,OAAO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AC9E,IAAI,qBAAqB,EAAE;gBACvB,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,kBAAkB,CAAC,qBAAqB,CAAC,CAAC,CAAC;gBACvE,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;aAChC;YAED,oCAAoC;YACpC,MAAM,iBAAiB,GAAG,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;YAC3G,IAAI,iBAAiB,EAAE;gBACnB,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,qBAAqB,CAAC,iBAAiB,CAAC,CAAC,CAAC;gBACtE,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;aAChC;YAED,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,CAAe,CAAC;QAC7E,CAAC,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Resources/Stores
|
|
3
3
|
*/
|
|
4
|
-
import { AuthParams,
|
|
4
|
+
import { AuthParams, SendData } from "../api/RestAPI.js";
|
|
5
5
|
import { ConfigurationCreateParams, ConfigurationItem, ConfigurationUpdateParams } from "./common/Configuration.js";
|
|
6
6
|
import { WithMerchantName } from "./common/types.js";
|
|
7
7
|
import { CRUDItemsResponse, CRUDPaginationParams, CRUDResource } from "./CRUDResource.js";
|
|
@@ -31,9 +31,14 @@ export declare type ResponseStores = CRUDItemsResponse<StoreListItem>;
|
|
|
31
31
|
export declare class Stores extends CRUDResource {
|
|
32
32
|
static requiredParams: string[];
|
|
33
33
|
static routeBase: string;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
private _list?;
|
|
35
|
+
list(data?: SendData<StoresListParams>, auth?: AuthParams): Promise<ResponseStores>;
|
|
36
|
+
private _create?;
|
|
37
|
+
create(data: SendData<StoreCreateParams>, auth?: AuthParams): Promise<ResponseStore>;
|
|
38
|
+
private _get?;
|
|
39
|
+
get(id: string, data?: SendData<void>, auth?: AuthParams): Promise<ResponseStore>;
|
|
40
|
+
private _update?;
|
|
41
|
+
update(id: string, data?: SendData<StoreUpdateParams>, auth?: AuthParams): Promise<ResponseStore>;
|
|
42
|
+
private _delete?;
|
|
43
|
+
delete(id: string, data?: SendData<void>, auth?: AuthParams): Promise<void>;
|
|
39
44
|
}
|
|
@@ -1,31 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Resources/Stores
|
|
3
3
|
*/
|
|
4
|
-
import { __extends } from "tslib";
|
|
5
4
|
import { CRUDResource } from "./CRUDResource.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return
|
|
5
|
+
export class Stores extends CRUDResource {
|
|
6
|
+
list(data, auth) {
|
|
7
|
+
this._list = this._list ?? this._listRoute();
|
|
8
|
+
return this._list(data, auth);
|
|
10
9
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return this.
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
export { Stores };
|
|
10
|
+
create(data, auth) {
|
|
11
|
+
this._create = this._create ?? this._createRoute({ requiredParams: Stores.requiredParams });
|
|
12
|
+
return this._create(data, auth);
|
|
13
|
+
}
|
|
14
|
+
get(id, data, auth) {
|
|
15
|
+
this._get = this._get ?? this._getRoute();
|
|
16
|
+
return this._get(data, auth, { id });
|
|
17
|
+
}
|
|
18
|
+
update(id, data, auth) {
|
|
19
|
+
this._update = this._update ?? this._updateRoute();
|
|
20
|
+
return this._update(data, auth, { id });
|
|
21
|
+
}
|
|
22
|
+
delete(id, data, auth) {
|
|
23
|
+
this._delete = this._delete ?? this._deleteRoute();
|
|
24
|
+
return this._delete(data, auth, { id });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
Stores.requiredParams = ["name"];
|
|
28
|
+
Stores.routeBase = "/stores";
|
|
31
29
|
//# sourceMappingURL=Stores.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Stores.js","sourceRoot":"","sources":["../../../src/resources/Stores.ts"],"names":[],"mappings":"AAAA;;GAEG
|
|
1
|
+
{"version":3,"file":"Stores.js","sourceRoot":"","sources":["../../../src/resources/Stores.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,OAAO,EAA2C,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAgC1F,MAAM,OAAO,MAAO,SAAQ,YAAY;IAKpC,IAAI,CAAC,IAAiC,EAAE,IAAiB;QACrD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;QAC7C,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAClC,CAAC;IAGD,MAAM,CAAC,IAAiC,EAAE,IAAiB;QACvD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,EAAE,cAAc,EAAE,MAAM,CAAC,cAAc,EAAE,CAAC,CAAC;QAC5F,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACpC,CAAC;IAGD,GAAG,CAAC,EAAU,EAAE,IAAqB,EAAE,IAAiB;QACpD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;QAC1C,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IACzC,CAAC;IAGD,MAAM,CAAC,EAAU,EAAE,IAAkC,EAAE,IAAiB;QACpE,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;QACnD,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IAC5C,CAAC;IAGD,MAAM,CAAC,EAAU,EAAE,IAAqB,EAAE,IAAiB;QACvD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;QACnD,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IAC5C,CAAC;;AA/BM,qBAAc,GAAa,CAAC,MAAM,CAAC,CAAC;AACpC,gBAAS,GAAG,SAAS,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Resources/Subscriptions
|
|
3
3
|
*/
|
|
4
|
-
import { AuthParams,
|
|
4
|
+
import { AuthParams, PollData, PollParams, RestAPI, SendData } from "../api/RestAPI.js";
|
|
5
5
|
import { ProcessingMode } from "./common/enums.js";
|
|
6
6
|
import { Metadata, WithStoreMerchantName } from "./common/types.js";
|
|
7
7
|
import { ChargesListParams, ResponseCharges } from "./Charges.js";
|
|
@@ -163,10 +163,14 @@ export declare type ResponsePayment = ScheduledPaymentItem;
|
|
|
163
163
|
export declare type ResponsePayments = CRUDItemsResponse<SchedulePaymentListItem>;
|
|
164
164
|
export declare class ScheduledPayments extends CRUDResource {
|
|
165
165
|
static routeBase: string;
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
166
|
+
private _list?;
|
|
167
|
+
list(storeId: string, subscriptionsId: string, data?: SendData<ScheduledPaymentsListParams>, auth?: AuthParams): Promise<ResponsePayments>;
|
|
168
|
+
private _get?;
|
|
169
|
+
get(storeId: string, subscriptionsId: string, id: string, data?: SendData<void>, auth?: AuthParams): Promise<ResponsePayment>;
|
|
170
|
+
private _update?;
|
|
171
|
+
update(storeId: string, subscriptionsId: string, id: string, data?: SendData<PaymentUpdateParams>, auth?: AuthParams): Promise<ResponsePayment>;
|
|
172
|
+
private _listCharges?;
|
|
173
|
+
listCharges(storeId: string, subscriptionsId: string, paymentId: string, data?: SendData<ChargesListParams>, auth?: AuthParams): Promise<ResponseCharges>;
|
|
170
174
|
}
|
|
171
175
|
export declare class Subscriptions extends CRUDResource {
|
|
172
176
|
static requiredParams: string[];
|
|
@@ -175,27 +179,23 @@ export declare class Subscriptions extends CRUDResource {
|
|
|
175
179
|
payments: ScheduledPayments;
|
|
176
180
|
private chargesResource;
|
|
177
181
|
constructor(api: RestAPI);
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}): Promise<ResponseSubscription>;
|
|
192
|
-
pollSubscriptionWithFirstCharge(storeId: string, id: string, data?: SendData<PollParams>, auth?: AuthParams, callback?: ResponseCallback<{
|
|
193
|
-
subscription: ResponseSubscription;
|
|
194
|
-
charge?: ResponseCharge;
|
|
195
|
-
}>): Promise<{
|
|
182
|
+
private _list;
|
|
183
|
+
list(data?: SendData<SubscriptionsListParams>, auth?: AuthParams, storeId?: string): Promise<ResponseSubscriptions>;
|
|
184
|
+
create(data: SubscriptionCreateParams, auth?: AuthParams): Promise<ResponseSubscription>;
|
|
185
|
+
private _get;
|
|
186
|
+
get(storeId: string, id: string, data?: SendData<PollData>, auth?: AuthParams): Promise<ResponseSubscription>;
|
|
187
|
+
private _update;
|
|
188
|
+
update(storeId: string, id: string, data?: SendData<SubscriptionUpdateParams>, auth?: AuthParams): Promise<ResponseSubscription>;
|
|
189
|
+
private _delete;
|
|
190
|
+
delete(storeId: string, id: string, data?: SendData<void>, auth?: AuthParams): Promise<void>;
|
|
191
|
+
private _charges;
|
|
192
|
+
charges(storeId: string, id: string, data?: SendData<ChargesListParams>, auth?: AuthParams): Promise<ResponseCharges>;
|
|
193
|
+
poll(storeId: string, id: string, data?: SendData<PollData>, auth?: AuthParams, pollParams?: Partial<PollParams<ResponseSubscription>>): Promise<ResponseSubscription>;
|
|
194
|
+
pollSubscriptionWithFirstCharge(storeId: string, id: string, data?: SendData<PollData>, auth?: AuthParams): Promise<{
|
|
196
195
|
subscription: ResponseSubscription;
|
|
197
196
|
charge?: ResponseCharge;
|
|
198
197
|
}>;
|
|
199
|
-
|
|
198
|
+
private _simulation;
|
|
199
|
+
simulation<InstallmentPlanData extends InstallmentBaseParams>(data: SendData<SubscriptionSimulationParams<InstallmentPlanData>>, auth?: AuthParams, storeId?: string): Promise<SimulationInstallmentPayment[]>;
|
|
200
200
|
}
|
|
201
201
|
export {};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Resources/Subscriptions
|
|
3
3
|
*/
|
|
4
|
-
import { __assign, __awaiter, __extends, __generator } from "tslib";
|
|
5
4
|
import { HTTPMethod } from "../api/RestAPI.js";
|
|
6
5
|
import { ignoreDescriptor } from "./common/ignoreDescriptor.js";
|
|
7
6
|
import { Charges } from "./Charges.js";
|
|
@@ -33,121 +32,86 @@ export var InstallmentPlan;
|
|
|
33
32
|
InstallmentPlan["FIXED_CYCLES"] = "fixed_cycles";
|
|
34
33
|
InstallmentPlan["FIXED_CYCLE_AMOUNT"] = "fixed_cycle_amount";
|
|
35
34
|
})(InstallmentPlan = InstallmentPlan || (InstallmentPlan = {}));
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return
|
|
35
|
+
export class ScheduledPayments extends CRUDResource {
|
|
36
|
+
list(storeId, subscriptionsId, data, auth) {
|
|
37
|
+
this._list = this._list ?? this.defineRoute(HTTPMethod.GET, `${ScheduledPayments.routeBase}`);
|
|
38
|
+
return this._list(data, auth, { storeId, subscriptionsId });
|
|
40
39
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
});
|
|
59
|
-
};
|
|
60
|
-
ScheduledPayments.routeBase = "/stores/:storeId/subscriptions/:subscriptionsId/payments";
|
|
61
|
-
return ScheduledPayments;
|
|
62
|
-
}(CRUDResource));
|
|
63
|
-
export { ScheduledPayments };
|
|
64
|
-
var hasImmediateCharge = function (subscription) {
|
|
65
|
-
var initialAmount = subscription.initialAmount, scheduleSettings = subscription.scheduleSettings;
|
|
40
|
+
get(storeId, subscriptionsId, id, data, auth) {
|
|
41
|
+
this._get = this._get ?? this._getRoute();
|
|
42
|
+
return this._get(data, auth, { storeId, subscriptionsId, id });
|
|
43
|
+
}
|
|
44
|
+
update(storeId, subscriptionsId, id, data, auth) {
|
|
45
|
+
this._update = this._update ?? this._updateRoute();
|
|
46
|
+
return this._update(data, auth, { storeId, subscriptionsId, id });
|
|
47
|
+
}
|
|
48
|
+
listCharges(storeId, subscriptionsId, paymentId, data, auth) {
|
|
49
|
+
this._listCharges =
|
|
50
|
+
this._listCharges ?? this.defineRoute(HTTPMethod.GET, `${ScheduledPayments.routeBase}/:paymentId/charges`);
|
|
51
|
+
return this._listCharges(data, auth, { storeId, subscriptionsId, paymentId });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
ScheduledPayments.routeBase = "/stores/:storeId/subscriptions/:subscriptionsId/payments";
|
|
55
|
+
const hasImmediateCharge = (subscription) => {
|
|
56
|
+
const { initialAmount, scheduleSettings } = subscription;
|
|
66
57
|
return !!initialAmount || !scheduleSettings || new Date(scheduleSettings.startOn) <= new Date();
|
|
67
58
|
};
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
59
|
+
export class Subscriptions extends CRUDResource {
|
|
60
|
+
constructor(api) {
|
|
61
|
+
super(api);
|
|
62
|
+
this.payments = new ScheduledPayments(api);
|
|
63
|
+
this.chargesResource = new Charges(api);
|
|
64
|
+
}
|
|
65
|
+
list(data, auth, storeId) {
|
|
66
|
+
this._list = this._list ?? this.defineRoute(HTTPMethod.GET, "(/stores/:storeId)/subscriptions");
|
|
67
|
+
return this._list(data, auth, { storeId });
|
|
68
|
+
}
|
|
69
|
+
create(data, auth) {
|
|
70
|
+
return ignoreDescriptor((updatedData) => this.defineRoute(HTTPMethod.POST, "/subscriptions", { requiredParams: Subscriptions.requiredParams })(updatedData, auth), data);
|
|
71
|
+
}
|
|
72
|
+
get(storeId, id, data, auth) {
|
|
73
|
+
this._get = this._get ?? this._getRoute();
|
|
74
|
+
return this._get(data, auth, { storeId, id });
|
|
75
|
+
}
|
|
76
|
+
update(storeId, id, data, auth) {
|
|
77
|
+
this._update = this._update ?? this._updateRoute();
|
|
78
|
+
return this._update(data, auth, { storeId, id });
|
|
79
|
+
}
|
|
80
|
+
delete(storeId, id, data, auth) {
|
|
81
|
+
this._delete = this._delete ?? this._deleteRoute();
|
|
82
|
+
return this._delete(data, auth, { storeId, id });
|
|
83
|
+
}
|
|
84
|
+
charges(storeId, id, data, auth) {
|
|
85
|
+
this._charges = this._charges ?? this.defineRoute(HTTPMethod.GET, `${Subscriptions.routeBase}/:id/charges`);
|
|
86
|
+
return this._charges(data, auth, { storeId, id });
|
|
87
|
+
}
|
|
88
|
+
poll(storeId, id, data, auth, pollParams) {
|
|
89
|
+
const pollData = { ...data, polling: true };
|
|
90
|
+
const promise = () => this.get(storeId, id, pollData, auth);
|
|
91
|
+
const successCondition = pollParams?.successCondition ?? (({ status }) => status !== SubscriptionStatus.UNVERIFIED);
|
|
92
|
+
return this.api.longPolling(promise, { ...pollParams, successCondition });
|
|
93
|
+
}
|
|
94
|
+
async pollSubscriptionWithFirstCharge(storeId, id, data, auth) {
|
|
95
|
+
const subscription = await this.poll(storeId, id, data, auth);
|
|
96
|
+
const charge = hasImmediateCharge(subscription)
|
|
97
|
+
? await this.api
|
|
98
|
+
.longPolling(() => this.charges(storeId, id, undefined, auth), {
|
|
99
|
+
successCondition: (charges) => !!charges.items.length,
|
|
100
|
+
})
|
|
101
|
+
.then(({ items: charges }) => this.chargesResource.poll(charges[0].storeId, charges[0].id, data, auth))
|
|
102
|
+
: null;
|
|
103
|
+
return { subscription, charge };
|
|
104
|
+
}
|
|
105
|
+
simulation(data, auth, storeId) {
|
|
106
|
+
this._simulation =
|
|
107
|
+
this._simulation ??
|
|
108
|
+
this.defineRoute(HTTPMethod.POST, "(/stores/:storeId)/subscriptions/simulate_plan", {
|
|
109
|
+
requiredParams: Subscriptions.requiredSimulationParams,
|
|
110
|
+
});
|
|
111
|
+
return this._simulation(data, auth, { storeId });
|
|
75
112
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
var _this = this;
|
|
81
|
-
return ignoreDescriptor(function (updatedData) {
|
|
82
|
-
return _this.defineRoute(HTTPMethod.POST, "/subscriptions", Subscriptions.requiredParams)(updatedData, callback, auth);
|
|
83
|
-
}, data);
|
|
84
|
-
};
|
|
85
|
-
Subscriptions.prototype.get = function (storeId, id, data, auth, callback) {
|
|
86
|
-
return this._getRoute()(data, callback, auth, { storeId: storeId, id: id });
|
|
87
|
-
};
|
|
88
|
-
Subscriptions.prototype.update = function (storeId, id, data, auth, callback) {
|
|
89
|
-
return this._updateRoute()(data, callback, auth, { storeId: storeId, id: id });
|
|
90
|
-
};
|
|
91
|
-
Subscriptions.prototype.delete = function (storeId, id, data, auth, callback) {
|
|
92
|
-
return this._deleteRoute()(data, callback, auth, { storeId: storeId, id: id });
|
|
93
|
-
};
|
|
94
|
-
Subscriptions.prototype.charges = function (storeId, id, data, auth, callback) {
|
|
95
|
-
return this.defineRoute(HTTPMethod.GET, "".concat(Subscriptions.routeBase, "/:id/charges"))(data, callback, auth, {
|
|
96
|
-
storeId: storeId,
|
|
97
|
-
id: id,
|
|
98
|
-
});
|
|
99
|
-
};
|
|
100
|
-
Subscriptions.prototype.poll = function (storeId, id, data, auth, callback,
|
|
101
|
-
/**
|
|
102
|
-
* Condition for the resource to be successfully loaded. Default to pending status check.
|
|
103
|
-
*/
|
|
104
|
-
cancelCondition, successCondition, iterationCallback, pollOptions) {
|
|
105
|
-
var _this = this;
|
|
106
|
-
if (successCondition === void 0) { successCondition = function (_a) {
|
|
107
|
-
var status = _a.status;
|
|
108
|
-
return status !== SubscriptionStatus.UNVERIFIED;
|
|
109
|
-
}; }
|
|
110
|
-
var pollData = __assign(__assign({}, data), { polling: true });
|
|
111
|
-
var promise = function () { return _this.get(storeId, id, pollData, auth); };
|
|
112
|
-
return this.api.longPolling(promise, successCondition, cancelCondition, callback, pollOptions === null || pollOptions === void 0 ? void 0 : pollOptions.interval, pollOptions === null || pollOptions === void 0 ? void 0 : pollOptions.timeout, iterationCallback);
|
|
113
|
-
};
|
|
114
|
-
Subscriptions.prototype.pollSubscriptionWithFirstCharge = function (storeId, id, data, auth, callback) {
|
|
115
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
116
|
-
var subscription, charge, _a;
|
|
117
|
-
var _this = this;
|
|
118
|
-
return __generator(this, function (_b) {
|
|
119
|
-
switch (_b.label) {
|
|
120
|
-
case 0: return [4 /*yield*/, this.poll(storeId, id, data, auth)];
|
|
121
|
-
case 1:
|
|
122
|
-
subscription = _b.sent();
|
|
123
|
-
if (!hasImmediateCharge(subscription)) return [3 /*break*/, 3];
|
|
124
|
-
return [4 /*yield*/, this.api
|
|
125
|
-
.longPolling(function () { return _this.charges(storeId, id); }, function (charges) { return !!charges.items.length; })
|
|
126
|
-
.then(function (_a) {
|
|
127
|
-
var charges = _a.items;
|
|
128
|
-
return _this.chargesResource.poll(charges[0].storeId, charges[0].id, data, auth);
|
|
129
|
-
})];
|
|
130
|
-
case 2:
|
|
131
|
-
_a = _b.sent();
|
|
132
|
-
return [3 /*break*/, 4];
|
|
133
|
-
case 3:
|
|
134
|
-
_a = null;
|
|
135
|
-
_b.label = 4;
|
|
136
|
-
case 4:
|
|
137
|
-
charge = _a;
|
|
138
|
-
callback === null || callback === void 0 ? void 0 : callback({ subscription: subscription, charge: charge });
|
|
139
|
-
return [2 /*return*/, { subscription: subscription, charge: charge }];
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
};
|
|
144
|
-
Subscriptions.prototype.simulation = function (data, auth, callback, storeId) {
|
|
145
|
-
return this.defineRoute(HTTPMethod.POST, "(/stores/:storeId)/subscriptions/simulate_plan", Subscriptions.requiredSimulationParams)(data, callback, auth, { storeId: storeId });
|
|
146
|
-
};
|
|
147
|
-
Subscriptions.requiredParams = ["transactionTokenId", "amount", "currency", "period"];
|
|
148
|
-
Subscriptions.requiredSimulationParams = ["installmentPlan", "paymentType", "currency", "period"];
|
|
149
|
-
Subscriptions.routeBase = "/stores/:storeId/subscriptions";
|
|
150
|
-
return Subscriptions;
|
|
151
|
-
}(CRUDResource));
|
|
152
|
-
export { Subscriptions };
|
|
113
|
+
}
|
|
114
|
+
Subscriptions.requiredParams = ["transactionTokenId", "amount", "currency", "period"];
|
|
115
|
+
Subscriptions.requiredSimulationParams = ["installmentPlan", "paymentType", "currency", "period"];
|
|
116
|
+
Subscriptions.routeBase = "/stores/:storeId/subscriptions";
|
|
153
117
|
//# sourceMappingURL=Subscriptions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Subscriptions.js","sourceRoot":"","sources":["../../../src/resources/Subscriptions.ts"],"names":[],"mappings":"AAAA;;GAEG
|
|
1
|
+
{"version":3,"file":"Subscriptions.js","sourceRoot":"","sources":["../../../src/resources/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EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;AAClF,sCAAwB,GAAa,CAAC,iBAAiB,EAAE,aAAa,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;AAE9F,uBAAS,GAAG,gCAAgC,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Resources/TemporaryTokenAlias
|
|
3
3
|
*/
|
|
4
|
-
import { AuthParams,
|
|
4
|
+
import { AuthParams, SendData } from "../api/RestAPI.js";
|
|
5
5
|
import { ProcessingMode } from "./common/enums.js";
|
|
6
6
|
import { Metadata } from "./common/types.js";
|
|
7
7
|
import { CRUDResource } from "./CRUDResource.js";
|
|
@@ -52,12 +52,14 @@ export interface TemporaryTokenAliasQrOptions {
|
|
|
52
52
|
color?: string;
|
|
53
53
|
}
|
|
54
54
|
export declare type ResponseTemporaryTokenAlias = TemporaryTokenAliasItem;
|
|
55
|
-
export declare type MethodGet<P, R> = (storeId: string, id: string, data?: SendData<P
|
|
55
|
+
export declare type MethodGet<P, R> = (storeId: string, id: string, data?: SendData<P>) => Promise<R>;
|
|
56
56
|
export declare class TemporaryTokenAlias extends CRUDResource {
|
|
57
57
|
static requiredParams: string[];
|
|
58
58
|
static routeBase: string;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
private _create?;
|
|
60
|
+
create(data: SendData<TemporaryTokenAliasCreateParams>, auth?: AuthParams): Promise<ResponseTemporaryTokenAlias>;
|
|
61
|
+
private _get?;
|
|
62
|
+
get(storeId: string, id: string, data?: SendData<TemporaryTokenAliasParams>, auth?: AuthParams): Promise<any>;
|
|
63
|
+
private _delete?;
|
|
64
|
+
delete(storeId: string, id: string, data?: SendData<void>, auth?: AuthParams): Promise<void>;
|
|
63
65
|
}
|