@adtrackify/at-service-common 1.0.46 → 1.0.47
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 +15 -20
- package/dist/index.js.map +2 -2
- package/package.json +1 -2
- package/src/clients/third-party/shopify-client.ts +15 -24
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.47",
|
|
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,29 @@ export class ShopifyClient {
|
|
|
80
79
|
return res;
|
|
81
80
|
};
|
|
82
81
|
|
|
83
|
-
static
|
|
82
|
+
static createAppSubscription = async (shop: string, accessToken: string,
|
|
84
83
|
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 = {
|
|
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
89
|
trial_days: trialDays
|
|
96
90
|
};
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
91
|
+
const res = await this.genericShopifyPost(url, accessToken, { recurring_application_charge });
|
|
92
|
+
if (res.status >= 400) {
|
|
93
|
+
log.error('Failed to create App Subscription', { shop, accessToken, url });
|
|
94
|
+
}
|
|
95
|
+
return res;
|
|
101
96
|
};
|
|
102
97
|
|
|
103
|
-
static
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
client.recurringApplicationCharge.list();
|
|
111
|
-
const response = await client.recurringApplicationCharge.list();
|
|
112
|
-
|
|
113
|
-
return response;
|
|
98
|
+
static listAppSubscriptions = async (shop: string, accessToken: string) => {
|
|
99
|
+
const url = `https://${shop}/admin/api/${this._shopify_api_version}/recurring_application_charges.json`;
|
|
100
|
+
const res = await this.genericShopifyGet(url, accessToken);
|
|
101
|
+
if (res.status >= 400) {
|
|
102
|
+
log.error('Failed to get App Subscriptions', { shop, accessToken, url });
|
|
103
|
+
}
|
|
104
|
+
return res;
|
|
114
105
|
};
|
|
115
106
|
|
|
116
107
|
static genericShopifyPost = async (url: string, accessToken: string, payload: any) => {
|