@adtrackify/at-service-common 1.0.46 → 1.0.48
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/.vscode/settings.json +10 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.js +17 -21
- package/dist/index.js.map +2 -2
- package/package.json +1 -2
- package/src/clients/third-party/shopify-client.ts +18 -26
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adtrackify/at-service-common",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.48",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -35,7 +35,6 @@
|
|
|
35
35
|
"joi": "^17.6.0",
|
|
36
36
|
"lambda-log": "^3.1.0",
|
|
37
37
|
"luxon": "^3.0.3",
|
|
38
|
-
"shopify-api-node": "^3.11.1",
|
|
39
38
|
"ua-parser-js": "^1.0.2"
|
|
40
39
|
},
|
|
41
40
|
"devDependencies": {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { axiosHttpService } from '../generic/http-client';
|
|
2
2
|
import * as log from 'lambda-log';
|
|
3
|
-
import Shopify, { IPublicShopifyConfig } from 'shopify-api-node';
|
|
4
3
|
|
|
5
4
|
export class ShopifyClient {
|
|
6
5
|
static _shopify_api_version = process.env.SHOPIFY_API_VERSION as string;
|
|
@@ -80,37 +79,30 @@ export class ShopifyClient {
|
|
|
80
79
|
return res;
|
|
81
80
|
};
|
|
82
81
|
|
|
83
|
-
static
|
|
84
|
-
planName: string, price: number, returnUrl: string, trialDays: number) => {
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
accessToken,
|
|
88
|
-
shopName: shop
|
|
89
|
-
};
|
|
90
|
-
const client = new Shopify(config);
|
|
91
|
-
const createSubscriptionParams: Shopify.ICreateRecurringApplicationCharge = {
|
|
82
|
+
static createAppSubscription = async (shop: string, accessToken: string,
|
|
83
|
+
planName: string, price: number, returnUrl: string, trialDays: number, test?: boolean) => {
|
|
84
|
+
const url = `https://${shop}/admin/api/${this._shopify_api_version}/recurring_application_charges.json`;
|
|
85
|
+
const recurring_application_charge = {
|
|
92
86
|
name: planName,
|
|
93
87
|
price,
|
|
94
88
|
return_url: returnUrl,
|
|
95
|
-
trial_days: trialDays
|
|
89
|
+
trial_days: trialDays,
|
|
90
|
+
test
|
|
96
91
|
};
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
92
|
+
const res = await this.genericShopifyPost(url, accessToken, { recurring_application_charge });
|
|
93
|
+
if (res.status >= 400) {
|
|
94
|
+
log.error('Failed to create App Subscription', { shop, accessToken, url });
|
|
95
|
+
}
|
|
96
|
+
return res;
|
|
101
97
|
};
|
|
102
98
|
|
|
103
|
-
static
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
client.recurringApplicationCharge.list();
|
|
111
|
-
const response = await client.recurringApplicationCharge.list();
|
|
112
|
-
|
|
113
|
-
return response;
|
|
99
|
+
static listAppSubscriptions = async (shop: string, accessToken: string) => {
|
|
100
|
+
const url = `https://${shop}/admin/api/${this._shopify_api_version}/recurring_application_charges.json`;
|
|
101
|
+
const res = await this.genericShopifyGet(url, accessToken);
|
|
102
|
+
if (res.status >= 400) {
|
|
103
|
+
log.error('Failed to get App Subscriptions', { shop, accessToken, url });
|
|
104
|
+
}
|
|
105
|
+
return res;
|
|
114
106
|
};
|
|
115
107
|
|
|
116
108
|
static genericShopifyPost = async (url: string, accessToken: string, payload: any) => {
|