gomarketme-react-native 1.1.0 → 2.0.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/README.md CHANGED
@@ -10,19 +10,19 @@
10
10
  ### Using npm
11
11
 
12
12
  ```bash
13
- npm install gomarketme-react-native
13
+ npm install gomarketme-react-native@2.0.0
14
14
  ```
15
15
 
16
16
  ### Using yarn
17
17
 
18
18
  ```bash
19
- yarn add gomarketme-react-native
19
+ yarn add gomarketme-react-native@2.0.0
20
20
  ```
21
21
 
22
22
  ### Using pnpm
23
23
 
24
24
  ```bash
25
- pnpm add gomarketme-react-native
25
+ pnpm add gomarketme-react-native@2.0.0
26
26
  ```
27
27
 
28
28
 
@@ -34,14 +34,11 @@ To initialize GoMarketMe, import the `gomarketme` package and create a new insta
34
34
  import GoMarketMe from 'gomarketme-react-native';
35
35
 
36
36
  const App: React.FC = () => {
37
- const apiKey = 'YOUR_API_KEY_HERE';
38
37
 
39
38
  useEffect(() => {
40
- const initializeGoMarketMe = async () => {
41
- await GoMarketMe.initialize(apiKey);
42
- };
43
39
 
44
- initializeGoMarketMe();
40
+ GoMarketMe.initialize('API_KEY'); // Initialize with your API key
41
+
45
42
  }, []);
46
43
  };
47
44
  ```
package/dist/index.d.ts CHANGED
@@ -1,29 +1,69 @@
1
+ export declare class GoMarketMeAffiliateMarketingData {
2
+ campaign: Campaign;
3
+ affiliate: Affiliate;
4
+ saleDistribution: SaleDistribution;
5
+ affiliateCampaignCode: string;
6
+ deviceId: string;
7
+ offerCode?: string;
8
+ constructor(campaign: Campaign, affiliate: Affiliate, saleDistribution: SaleDistribution, affiliateCampaignCode: string, deviceId: string, offerCode?: string);
9
+ static fromJson(json: Record<string, any>): GoMarketMeAffiliateMarketingData | null;
10
+ }
11
+ export declare class Campaign {
12
+ id: string;
13
+ name: string;
14
+ status: string;
15
+ type: string;
16
+ publicLinkUrl?: string;
17
+ constructor(id: string, name: string, status: string, type: string, publicLinkUrl?: string);
18
+ static fromJson(json: Record<string, any>): Campaign;
19
+ }
20
+ export declare class Affiliate {
21
+ id: string;
22
+ firstName: string;
23
+ lastName: string;
24
+ countryCode: string;
25
+ instagramAccount: string;
26
+ tiktokAccount: string;
27
+ xAccount: string;
28
+ constructor(id: string, firstName: string, lastName: string, countryCode: string, instagramAccount: string, tiktokAccount: string, xAccount: string);
29
+ static fromJson(json: Record<string, any>): Affiliate;
30
+ }
31
+ export declare class SaleDistribution {
32
+ platformPercentage: string;
33
+ affiliatePercentage: string;
34
+ constructor(platformPercentage: string, affiliatePercentage: string);
35
+ static fromJson(json: Record<string, any>): SaleDistribution;
36
+ }
1
37
  declare class GoMarketMe {
2
38
  private static instance;
39
+ private sdkType;
40
+ private sdkVersion;
3
41
  private sdkInitializedKey;
4
- private affiliateCampaignCode;
5
- private deviceId;
6
42
  private sdkInitializationUrl;
7
43
  private systemInfoUrl;
8
44
  private eventUrl;
45
+ private _affiliateCampaignCode;
46
+ private _deviceId;
47
+ private _packageName;
48
+ affiliateMarketingData?: GoMarketMeAffiliateMarketingData | null;
9
49
  private constructor();
10
50
  static getInstance(): GoMarketMe;
11
51
  initialize(apiKey: string): Promise<void>;
12
- private addListener;
13
- private getSystemInfo;
14
- private postSDKInitialization;
15
- private postSystemInfo;
16
- private readAndroidDeviceInfo;
17
- private readIosDeviceInfo;
18
- private getTimeZone;
19
- private getLanguageCode;
20
- private fetchPurchases;
21
- private fetchPurchaseProducts;
22
- private sendEventToServer;
23
- private serializePurchaseDetails;
24
- private serializeProductDetails;
25
- private markSDKAsInitialized;
26
- private isSDKInitialized;
52
+ private _addListener;
53
+ private _getSystemInfo;
54
+ private _postSDKInitialization;
55
+ private _postSystemInfo;
56
+ private _readAndroidDeviceInfo;
57
+ private _readIosDeviceInfo;
58
+ private _getTimeZone;
59
+ private _getLanguageCode;
60
+ private _fetchConsolidatedPurchases;
61
+ private _sendEventToServer;
62
+ private _serializePurchaseDetails;
63
+ private _serializeProductDetails;
64
+ private _serializeSubscriptionDetails;
65
+ private _markSDKAsInitialized;
66
+ private _isSDKInitialized;
27
67
  }
28
68
  declare const _default: GoMarketMe;
29
69
  export default _default;
package/dist/index.js CHANGED
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
26
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
27
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -39,21 +62,85 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
62
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
63
  };
41
64
  Object.defineProperty(exports, "__esModule", { value: true });
65
+ exports.SaleDistribution = exports.Affiliate = exports.Campaign = exports.GoMarketMeAffiliateMarketingData = void 0;
42
66
  var react_native_1 = require("react-native");
43
67
  var react_native_device_info_1 = __importDefault(require("react-native-device-info"));
44
68
  var get_user_locale_1 = __importDefault(require("get-user-locale"));
45
69
  var async_storage_1 = __importDefault(require("@react-native-async-storage/async-storage"));
46
- var react_native_iap_1 = __importDefault(require("react-native-iap"));
70
+ var RNIap = __importStar(require("react-native-iap"));
47
71
  var axios_1 = __importDefault(require("axios"));
72
+ var GoMarketMeAffiliateMarketingData = /** @class */ (function () {
73
+ function GoMarketMeAffiliateMarketingData(campaign, affiliate, saleDistribution, affiliateCampaignCode, deviceId, offerCode) {
74
+ this.campaign = campaign;
75
+ this.affiliate = affiliate;
76
+ this.saleDistribution = saleDistribution;
77
+ this.affiliateCampaignCode = affiliateCampaignCode;
78
+ this.deviceId = deviceId;
79
+ this.offerCode = offerCode;
80
+ }
81
+ GoMarketMeAffiliateMarketingData.fromJson = function (json) {
82
+ // Check if the json is an empty object
83
+ if (Object.keys(json).length === 0) {
84
+ return null; // Return null or undefined, depending on your preference
85
+ }
86
+ return new GoMarketMeAffiliateMarketingData(Campaign.fromJson(json.campaign), Affiliate.fromJson(json.affiliate), SaleDistribution.fromJson(json.sale_distribution), json.affiliate_campaign_code || '', json.device_id || '', json.offer_code);
87
+ };
88
+ return GoMarketMeAffiliateMarketingData;
89
+ }());
90
+ exports.GoMarketMeAffiliateMarketingData = GoMarketMeAffiliateMarketingData;
91
+ var Campaign = /** @class */ (function () {
92
+ function Campaign(id, name, status, type, publicLinkUrl) {
93
+ this.id = id;
94
+ this.name = name;
95
+ this.status = status;
96
+ this.type = type;
97
+ this.publicLinkUrl = publicLinkUrl;
98
+ }
99
+ Campaign.fromJson = function (json) {
100
+ return new Campaign(json.id || '', json.name || '', json.status || '', json.type || '', json.public_link_url);
101
+ };
102
+ return Campaign;
103
+ }());
104
+ exports.Campaign = Campaign;
105
+ var Affiliate = /** @class */ (function () {
106
+ function Affiliate(id, firstName, lastName, countryCode, instagramAccount, tiktokAccount, xAccount) {
107
+ this.id = id;
108
+ this.firstName = firstName;
109
+ this.lastName = lastName;
110
+ this.countryCode = countryCode;
111
+ this.instagramAccount = instagramAccount;
112
+ this.tiktokAccount = tiktokAccount;
113
+ this.xAccount = xAccount;
114
+ }
115
+ Affiliate.fromJson = function (json) {
116
+ return new Affiliate(json.id || '', json.first_name || '', json.last_name || '', json.country_code || '', json.instagram_account || '', json.tiktok_account || '', json.x_account || '');
117
+ };
118
+ return Affiliate;
119
+ }());
120
+ exports.Affiliate = Affiliate;
121
+ var SaleDistribution = /** @class */ (function () {
122
+ function SaleDistribution(platformPercentage, affiliatePercentage) {
123
+ this.platformPercentage = platformPercentage;
124
+ this.affiliatePercentage = affiliatePercentage;
125
+ }
126
+ SaleDistribution.fromJson = function (json) {
127
+ return new SaleDistribution(json.platform_percentage || '', json.affiliate_percentage || '');
128
+ };
129
+ return SaleDistribution;
130
+ }());
131
+ exports.SaleDistribution = SaleDistribution;
48
132
  var GoMarketMe = /** @class */ (function () {
49
133
  function GoMarketMe() {
134
+ this.sdkType = 'ReactNative';
135
+ this.sdkVersion = '2.0.0';
50
136
  this.sdkInitializedKey = 'GOMARKETME_SDK_INITIALIZED';
51
- this.affiliateCampaignCode = '';
52
- this.deviceId = '';
53
- this.sdkInitializationUrl = 'https://api.gomarketme.net/v1/sdk-initialization';
54
- this.systemInfoUrl = 'https://api.gomarketme.net/v1/mobile/system-info';
55
- this.eventUrl = 'https://api.gomarketme.net/v1/event';
56
- this.getTimeZone = function () {
137
+ this.sdkInitializationUrl = 'https://4v9008q1a5.execute-api.us-west-2.amazonaws.com/prod/v1/sdk-initialization';
138
+ this.systemInfoUrl = 'https://4v9008q1a5.execute-api.us-west-2.amazonaws.com/prod/v1/mobile/system-info';
139
+ this.eventUrl = 'https://4v9008q1a5.execute-api.us-west-2.amazonaws.com/prod/v1/event';
140
+ this._affiliateCampaignCode = '';
141
+ this._deviceId = '';
142
+ this._packageName = '';
143
+ this._getTimeZone = function () {
57
144
  return Intl.DateTimeFormat().resolvedOptions().timeZone;
58
145
  };
59
146
  }
@@ -65,64 +152,68 @@ var GoMarketMe = /** @class */ (function () {
65
152
  };
66
153
  GoMarketMe.prototype.initialize = function (apiKey) {
67
154
  return __awaiter(this, void 0, void 0, function () {
68
- var isSDKInitialized, systemInfo, e_1;
69
- return __generator(this, function (_a) {
70
- switch (_a.label) {
155
+ var isSDKInitialized, systemInfo, _a, e_1;
156
+ return __generator(this, function (_b) {
157
+ switch (_b.label) {
71
158
  case 0:
72
- _a.trys.push([0, 7, , 8]);
73
- return [4 /*yield*/, this.isSDKInitialized()];
159
+ _b.trys.push([0, 7, , 8]);
160
+ return [4 /*yield*/, this._isSDKInitialized()];
74
161
  case 1:
75
- isSDKInitialized = _a.sent();
162
+ isSDKInitialized = _b.sent();
76
163
  if (!!isSDKInitialized) return [3 /*break*/, 3];
77
- return [4 /*yield*/, this.postSDKInitialization(apiKey)];
164
+ return [4 /*yield*/, this._postSDKInitialization(apiKey)];
78
165
  case 2:
79
- _a.sent();
80
- _a.label = 3;
81
- case 3: return [4 /*yield*/, this.getSystemInfo()];
166
+ _b.sent();
167
+ _b.label = 3;
168
+ case 3:
169
+ this._packageName = react_native_device_info_1.default.getBundleId();
170
+ return [4 /*yield*/, this._getSystemInfo()];
82
171
  case 4:
83
- systemInfo = _a.sent();
84
- return [4 /*yield*/, this.postSystemInfo(systemInfo, apiKey)];
172
+ systemInfo = _b.sent();
173
+ _a = this;
174
+ return [4 /*yield*/, this._postSystemInfo(systemInfo, apiKey)];
85
175
  case 5:
86
- _a.sent();
87
- return [4 /*yield*/, this.addListener(apiKey)];
176
+ _a.affiliateMarketingData = _b.sent();
177
+ return [4 /*yield*/, this._addListener(apiKey)];
88
178
  case 6:
89
- _a.sent();
179
+ _b.sent();
90
180
  return [3 /*break*/, 8];
91
181
  case 7:
92
- e_1 = _a.sent();
93
- console.error('Error initializing GoMarketMe:', e_1);
182
+ e_1 = _b.sent();
183
+ console.log('Error initializing GoMarketMe:', e_1);
94
184
  return [3 /*break*/, 8];
95
185
  case 8: return [2 /*return*/];
96
186
  }
97
187
  });
98
188
  });
99
189
  };
100
- GoMarketMe.prototype.addListener = function (apiKey) {
190
+ GoMarketMe.prototype._addListener = function (apiKey) {
101
191
  return __awaiter(this, void 0, void 0, function () {
102
192
  var _this = this;
103
193
  return __generator(this, function (_a) {
104
- react_native_iap_1.default.purchaseUpdatedListener(function (purchase) { return __awaiter(_this, void 0, void 0, function () {
105
- var productIds;
106
- return __generator(this, function (_a) {
107
- switch (_a.label) {
108
- case 0:
109
- if (!(this.affiliateCampaignCode != '')) return [3 /*break*/, 3];
110
- return [4 /*yield*/, this.fetchPurchases([purchase], apiKey)];
111
- case 1:
112
- productIds = _a.sent();
113
- return [4 /*yield*/, this.fetchPurchaseProducts(productIds, apiKey)];
114
- case 2:
115
- _a.sent();
116
- _a.label = 3;
117
- case 3: return [2 /*return*/];
118
- }
194
+ try {
195
+ RNIap.purchaseUpdatedListener(function (purchase) { return __awaiter(_this, void 0, void 0, function () {
196
+ return __generator(this, function (_a) {
197
+ switch (_a.label) {
198
+ case 0: return [4 /*yield*/, this._fetchConsolidatedPurchases([purchase], apiKey)];
199
+ case 1:
200
+ _a.sent();
201
+ return [2 /*return*/];
202
+ }
203
+ });
204
+ }); });
205
+ RNIap.purchaseErrorListener(function (error) {
206
+ console.log('Purchase error:', error);
119
207
  });
120
- }); });
208
+ }
209
+ catch (e) {
210
+ console.log('Error setting up IAP listeners:', e);
211
+ }
121
212
  return [2 /*return*/];
122
213
  });
123
214
  });
124
215
  };
125
- GoMarketMe.prototype.getSystemInfo = function () {
216
+ GoMarketMe.prototype._getSystemInfo = function () {
126
217
  return __awaiter(this, void 0, void 0, function () {
127
218
  var deviceData, _a, _b, devicePixelRatio, dimension, windowData;
128
219
  var _c;
@@ -131,13 +222,14 @@ var GoMarketMe = /** @class */ (function () {
131
222
  case 0:
132
223
  _b = (_a = react_native_1.Platform).select;
133
224
  _c = {};
134
- return [4 /*yield*/, this.readIosDeviceInfo()];
225
+ return [4 /*yield*/, this._readIosDeviceInfo()];
135
226
  case 1:
136
227
  _c.ios = _d.sent();
137
- return [4 /*yield*/, this.readAndroidDeviceInfo()];
228
+ return [4 /*yield*/, this._readAndroidDeviceInfo()];
138
229
  case 2:
139
230
  deviceData = _b.apply(_a, [(_c.android = _d.sent(),
140
231
  _c)]);
232
+ this._deviceId = deviceData['deviceId'];
141
233
  devicePixelRatio = react_native_1.PixelRatio.get();
142
234
  dimension = react_native_1.Dimensions.get('window');
143
235
  windowData = {
@@ -148,14 +240,14 @@ var GoMarketMe = /** @class */ (function () {
148
240
  return [2 /*return*/, {
149
241
  device_info: deviceData,
150
242
  window_info: windowData,
151
- time_zone: this.getTimeZone(),
152
- language_code: this.getLanguageCode(),
243
+ time_zone: this._getTimeZone(),
244
+ language_code: this._getLanguageCode(),
153
245
  }];
154
246
  }
155
247
  });
156
248
  });
157
249
  };
158
- GoMarketMe.prototype.postSDKInitialization = function (apiKey) {
250
+ GoMarketMe.prototype._postSDKInitialization = function (apiKey) {
159
251
  return __awaiter(this, void 0, void 0, function () {
160
252
  var response, e_2;
161
253
  return __generator(this, function (_a) {
@@ -171,61 +263,64 @@ var GoMarketMe = /** @class */ (function () {
171
263
  case 1:
172
264
  response = _a.sent();
173
265
  if (!(response.status === 200)) return [3 /*break*/, 3];
174
- return [4 /*yield*/, this.markSDKAsInitialized()];
266
+ return [4 /*yield*/, this._markSDKAsInitialized()];
175
267
  case 2:
176
268
  _a.sent();
177
269
  return [3 /*break*/, 4];
178
270
  case 3:
179
- console.error('Failed to mark SDK as Initialized. Status code:', response.status);
271
+ console.log('Failed to mark SDK as Initialized. Status code:', response.status);
180
272
  _a.label = 4;
181
273
  case 4: return [3 /*break*/, 6];
182
274
  case 5:
183
275
  e_2 = _a.sent();
184
- console.error('Error sending SDK information to server:', e_2);
276
+ console.log('Error sending SDK information to server:', e_2);
185
277
  return [3 /*break*/, 6];
186
278
  case 6: return [2 /*return*/];
187
279
  }
188
280
  });
189
281
  });
190
282
  };
191
- GoMarketMe.prototype.postSystemInfo = function (systemInfo, apiKey) {
283
+ GoMarketMe.prototype._postSystemInfo = function (data, apiKey) {
192
284
  return __awaiter(this, void 0, void 0, function () {
193
- var response, responseData, e_3;
285
+ var output, response, e_3;
194
286
  return __generator(this, function (_a) {
195
287
  switch (_a.label) {
196
288
  case 0:
197
- _a.trys.push([0, 2, , 3]);
198
- return [4 /*yield*/, axios_1.default.post(this.systemInfoUrl, systemInfo, {
289
+ output = null;
290
+ _a.label = 1;
291
+ case 1:
292
+ _a.trys.push([1, 3, , 4]);
293
+ data['sdk_type'] = this.sdkType;
294
+ data['sdk_version'] = this.sdkVersion;
295
+ data['package_name'] = this._packageName;
296
+ return [4 /*yield*/, axios_1.default.post(this.systemInfoUrl, data, {
199
297
  headers: {
200
298
  'Content-Type': 'application/json',
201
299
  'x-api-key': apiKey,
202
300
  },
203
301
  })];
204
- case 1:
302
+ case 2:
205
303
  response = _a.sent();
206
304
  if (response.status === 200) {
207
- responseData = response.data;
208
- if (responseData.affiliate_campaign_code) {
209
- this.affiliateCampaignCode = responseData.affiliate_campaign_code;
210
- }
211
- if (responseData.device_id) {
212
- this.deviceId = responseData.device_id;
305
+ output = GoMarketMeAffiliateMarketingData.fromJson(response.data);
306
+ if (output != null) {
307
+ this._affiliateCampaignCode = output.affiliateCampaignCode;
213
308
  }
214
309
  }
215
310
  else {
216
- console.error('Failed to send system info. Status code:', response.status);
311
+ console.log('Failed to send system info. Status code:', response.status);
217
312
  }
218
- return [3 /*break*/, 3];
219
- case 2:
313
+ return [3 /*break*/, 4];
314
+ case 3:
220
315
  e_3 = _a.sent();
221
- console.error('Error sending system info to server:', e_3);
222
- return [3 /*break*/, 3];
223
- case 3: return [2 /*return*/];
316
+ console.log('Error sending system info to server:', e_3);
317
+ return [3 /*break*/, 4];
318
+ case 4: return [2 /*return*/, output];
224
319
  }
225
320
  });
226
321
  });
227
322
  };
228
- GoMarketMe.prototype.readAndroidDeviceInfo = function () {
323
+ GoMarketMe.prototype._readAndroidDeviceInfo = function () {
229
324
  return __awaiter(this, void 0, void 0, function () {
230
325
  var androidId, uniqueId, deviceId, systemName, systemVersion, brand, model, manufacturer, isEmulator;
231
326
  return __generator(this, function (_a) {
@@ -272,7 +367,7 @@ var GoMarketMe = /** @class */ (function () {
272
367
  });
273
368
  });
274
369
  };
275
- GoMarketMe.prototype.readIosDeviceInfo = function () {
370
+ GoMarketMe.prototype._readIosDeviceInfo = function () {
276
371
  return __awaiter(this, void 0, void 0, function () {
277
372
  var uniqueId, deviceId, systemName, systemVersion, brand, model, manufacturer, isEmulator;
278
373
  return __generator(this, function (_a) {
@@ -315,78 +410,58 @@ var GoMarketMe = /** @class */ (function () {
315
410
  });
316
411
  });
317
412
  };
318
- GoMarketMe.prototype.getLanguageCode = function () {
413
+ GoMarketMe.prototype._getLanguageCode = function () {
319
414
  return (0, get_user_locale_1.default)();
320
415
  };
321
- GoMarketMe.prototype.fetchPurchases = function (purchaseDetailsList, apiKey) {
416
+ GoMarketMe.prototype._fetchConsolidatedPurchases = function (purchaseDetailsList, apiKey) {
322
417
  return __awaiter(this, void 0, void 0, function () {
323
- var productIds, _i, purchaseDetailsList_1, purchase;
324
- return __generator(this, function (_a) {
325
- switch (_a.label) {
418
+ var _i, purchaseDetailsList_1, purchase, data, products, _a, products_1, product0, products_3, _b, products_2, product0;
419
+ return __generator(this, function (_c) {
420
+ switch (_c.label) {
326
421
  case 0:
327
- productIds = [];
328
422
  _i = 0, purchaseDetailsList_1 = purchaseDetailsList;
329
- _a.label = 1;
423
+ _c.label = 1;
330
424
  case 1:
331
- if (!(_i < purchaseDetailsList_1.length)) return [3 /*break*/, 4];
425
+ if (!(_i < purchaseDetailsList_1.length)) return [3 /*break*/, 8];
332
426
  purchase = purchaseDetailsList_1[_i];
333
- if (!purchase.transactionReceipt) return [3 /*break*/, 3];
334
- return [4 /*yield*/, this.sendEventToServer(JSON.stringify(this.serializePurchaseDetails(purchase)), 'purchase', apiKey)];
427
+ if (!purchase.transactionReceipt) return [3 /*break*/, 7];
428
+ data = this._serializePurchaseDetails(purchase);
429
+ data['products'] = [];
430
+ if (!(data.productID != '')) return [3 /*break*/, 5];
431
+ return [4 /*yield*/, RNIap.getProducts({ skus: [data.productID] })];
335
432
  case 2:
336
- _a.sent();
337
- if (purchase.productId && !productIds.includes(purchase.productId)) {
338
- productIds.push(purchase.productId);
433
+ products = _c.sent();
434
+ if (!(products.length > 0)) return [3 /*break*/, 3];
435
+ for (_a = 0, products_1 = products; _a < products_1.length; _a++) {
436
+ product0 = products_1[_a];
437
+ data['products'].push(this._serializeProductDetails(product0));
339
438
  }
340
- _a.label = 3;
341
- case 3:
342
- _i++;
343
- return [3 /*break*/, 1];
344
- case 4: return [2 /*return*/, productIds];
345
- }
346
- });
347
- });
348
- };
349
- GoMarketMe.prototype.fetchPurchaseProducts = function (productIds, apiKey) {
350
- return __awaiter(this, void 0, void 0, function () {
351
- var products, _i, products_1, product, e_4;
352
- return __generator(this, function (_a) {
353
- switch (_a.label) {
354
- case 0:
355
- _a.trys.push([0, 9, , 10]);
356
- return [4 /*yield*/, react_native_iap_1.default.getProducts(productIds)];
357
- case 1:
358
- products = _a.sent();
359
- if (!(products.length > 0)) return [3 /*break*/, 6];
360
- _i = 0, products_1 = products;
361
- _a.label = 2;
362
- case 2:
363
- if (!(_i < products_1.length)) return [3 /*break*/, 5];
364
- product = products_1[_i];
365
- return [4 /*yield*/, this.sendEventToServer(JSON.stringify(this.serializeProductDetails(product)), 'product', apiKey)];
366
- case 3:
367
- _a.sent();
368
- _a.label = 4;
439
+ return [3 /*break*/, 5];
440
+ case 3: return [4 /*yield*/, RNIap.getSubscriptions({ skus: [data.productID] })];
369
441
  case 4:
370
- _i++;
371
- return [3 /*break*/, 2];
372
- case 5: return [3 /*break*/, 8];
373
- case 6: return [4 /*yield*/, this.sendEventToServer(JSON.stringify({ notFoundIDs: productIds.join(',') }), 'product', apiKey)];
442
+ products_3 = _c.sent();
443
+ if (products_3.length > 0) {
444
+ for (_b = 0, products_2 = products_3; _b < products_2.length; _b++) {
445
+ product0 = products_2[_b];
446
+ data['products'].push(this._serializeSubscriptionDetails(product0));
447
+ }
448
+ }
449
+ _c.label = 5;
450
+ case 5: return [4 /*yield*/, this._sendEventToServer(JSON.stringify(data), 'purchase', apiKey)];
451
+ case 6:
452
+ _c.sent();
453
+ _c.label = 7;
374
454
  case 7:
375
- _a.sent();
376
- _a.label = 8;
377
- case 8: return [3 /*break*/, 10];
378
- case 9:
379
- e_4 = _a.sent();
380
- console.error('Error fetching products:', e_4);
381
- return [3 /*break*/, 10];
382
- case 10: return [2 /*return*/];
455
+ _i++;
456
+ return [3 /*break*/, 1];
457
+ case 8: return [2 /*return*/];
383
458
  }
384
459
  });
385
460
  });
386
461
  };
387
- GoMarketMe.prototype.sendEventToServer = function (body, eventType, apiKey) {
462
+ GoMarketMe.prototype._sendEventToServer = function (body, eventType, apiKey) {
388
463
  return __awaiter(this, void 0, void 0, function () {
389
- var response, e_5;
464
+ var response, e_4;
390
465
  return __generator(this, function (_a) {
391
466
  switch (_a.label) {
392
467
  case 0:
@@ -394,8 +469,8 @@ var GoMarketMe = /** @class */ (function () {
394
469
  return [4 /*yield*/, axios_1.default.post(this.eventUrl, body, {
395
470
  headers: {
396
471
  'Content-Type': 'application/json',
397
- 'x-affiliate-campaign-code': this.affiliateCampaignCode,
398
- 'x-device-id': this.deviceId,
472
+ 'x-affiliate-campaign-code': this._affiliateCampaignCode,
473
+ 'x-device-id': this._deviceId,
399
474
  'x-event-type': eventType,
400
475
  'x-product-type': react_native_1.Platform.OS,
401
476
  'x-source-name': react_native_1.Platform.OS === 'android' ? 'google_play' : 'app_store',
@@ -408,20 +483,21 @@ var GoMarketMe = /** @class */ (function () {
408
483
  console.log("".concat(eventType, " sent successfully"));
409
484
  }
410
485
  else {
411
- console.error("Failed to send ".concat(eventType, ". Status code:"), response.status);
486
+ console.log("Failed to send ".concat(eventType, ". Status code:"), response.status);
412
487
  }
413
488
  return [3 /*break*/, 3];
414
489
  case 2:
415
- e_5 = _a.sent();
416
- console.error("Error sending ".concat(eventType, " to server:"), e_5);
490
+ e_4 = _a.sent();
491
+ console.log("Error sending ".concat(eventType, " to server:"), e_4);
417
492
  return [3 /*break*/, 3];
418
493
  case 3: return [2 /*return*/];
419
494
  }
420
495
  });
421
496
  });
422
497
  };
423
- GoMarketMe.prototype.serializePurchaseDetails = function (purchase) {
498
+ GoMarketMe.prototype._serializePurchaseDetails = function (purchase) {
424
499
  return {
500
+ packageName: this._packageName,
425
501
  productID: purchase.productId,
426
502
  purchaseID: purchase.transactionId || '',
427
503
  transactionDate: purchase.transactionDate || '',
@@ -431,22 +507,60 @@ var GoMarketMe = /** @class */ (function () {
431
507
  }),
432
508
  verificationData: {
433
509
  localVerificationData: purchase.transactionReceipt,
510
+ serverVerificationData: purchase.transactionReceipt,
511
+ source: react_native_1.Platform.OS === 'android' ? 'google_play' : 'app_store',
434
512
  },
513
+ pendingCompletePurchase: '',
514
+ error: {},
515
+ hashCode: '',
516
+ _purchase: purchase
435
517
  };
436
518
  };
437
- GoMarketMe.prototype.serializeProductDetails = function (product) {
519
+ GoMarketMe.prototype._serializeProductDetails = function (product) {
438
520
  return {
521
+ packageName: this._packageName,
439
522
  productID: product.productId,
440
523
  productTitle: product.title,
441
524
  productDescription: product.description,
442
- productPrice: product.price,
525
+ productPrice: product.localizedPrice,
443
526
  productRawPrice: product.price,
527
+ productCurrencySymbol: product.localizedPrice.replace('product.price', ''),
444
528
  productCurrencyCode: product.currency,
529
+ hashCode: '',
530
+ _product: product
445
531
  };
446
532
  };
447
- GoMarketMe.prototype.markSDKAsInitialized = function () {
533
+ GoMarketMe.prototype._serializeSubscriptionDetails = function (subscription) {
534
+ var _a;
535
+ var output = {
536
+ productID: subscription.productId,
537
+ productTitle: subscription.title,
538
+ productDescription: subscription.description,
539
+ hashCode: '',
540
+ };
541
+ if (react_native_1.Platform.OS === 'ios') {
542
+ var subscriptionIOS = subscription;
543
+ output.productPrice = subscriptionIOS.localizedPrice;
544
+ output.productRawPrice = subscriptionIOS.price;
545
+ output.productCurrencyCode = subscriptionIOS.currency;
546
+ output._subscription = subscriptionIOS;
547
+ }
548
+ else if (react_native_1.Platform.OS === 'android') {
549
+ var subscriptionAndroid = subscription;
550
+ if ((_a = subscriptionAndroid.subscriptionOfferDetails) === null || _a === void 0 ? void 0 : _a.length) {
551
+ var offerDetails = subscriptionAndroid.subscriptionOfferDetails[0];
552
+ var priceAmountMicros = parseInt(offerDetails.pricingPhases.pricingPhaseList[0].priceAmountMicros, 10) || 0;
553
+ output.productPrice = offerDetails.pricingPhases.pricingPhaseList[0].formattedPrice;
554
+ output.productRawPrice = String(priceAmountMicros / 1000000);
555
+ output.productCurrencyCode = offerDetails.pricingPhases.pricingPhaseList[0].priceCurrencyCode;
556
+ }
557
+ output._subscription = subscriptionAndroid;
558
+ }
559
+ return output;
560
+ };
561
+ GoMarketMe.prototype._markSDKAsInitialized = function () {
448
562
  return __awaiter(this, void 0, void 0, function () {
449
- var e_6;
563
+ var e_5;
450
564
  return __generator(this, function (_a) {
451
565
  switch (_a.label) {
452
566
  case 0:
@@ -456,17 +570,17 @@ var GoMarketMe = /** @class */ (function () {
456
570
  _a.sent();
457
571
  return [2 /*return*/, true];
458
572
  case 2:
459
- e_6 = _a.sent();
460
- console.error('Failed to save SDK initialization:', e_6);
573
+ e_5 = _a.sent();
574
+ console.log('Failed to save SDK initialization:', e_5);
461
575
  return [2 /*return*/, false];
462
576
  case 3: return [2 /*return*/];
463
577
  }
464
578
  });
465
579
  });
466
580
  };
467
- GoMarketMe.prototype.isSDKInitialized = function () {
581
+ GoMarketMe.prototype._isSDKInitialized = function () {
468
582
  return __awaiter(this, void 0, void 0, function () {
469
- var value, e_7;
583
+ var value, e_6;
470
584
  return __generator(this, function (_a) {
471
585
  switch (_a.label) {
472
586
  case 0:
@@ -476,8 +590,8 @@ var GoMarketMe = /** @class */ (function () {
476
590
  value = _a.sent();
477
591
  return [2 /*return*/, value === 'true'];
478
592
  case 2:
479
- e_7 = _a.sent();
480
- console.error('Failed to load SDK initialization:', e_7);
593
+ e_6 = _a.sent();
594
+ console.log('Failed to load SDK initialization:', e_6);
481
595
  return [2 /*return*/, false];
482
596
  case 3: return [2 /*return*/];
483
597
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gomarketme-react-native",
3
- "version": "1.1.0",
3
+ "version": "2.0.0",
4
4
  "description": "Affiliate Marketing for React Native-Based iOS and Android Apps.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -22,7 +22,7 @@
22
22
  "axios": "^0.21.1",
23
23
  "get-user-locale": "^2.3.2",
24
24
  "react-native-device-info": "^14.0.0",
25
- "react-native-iap": "^7.0.0"
25
+ "react-native-iap": "^12.16.0"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/node": "^15.12.5",
package/src/index.tsx CHANGED
@@ -2,19 +2,146 @@ import { Platform, Dimensions, PixelRatio } from 'react-native';
2
2
  import DeviceInfo from 'react-native-device-info';
3
3
  import getUserLocale from 'get-user-locale'
4
4
  import AsyncStorage from '@react-native-async-storage/async-storage';
5
- import InAppPurchase, { Purchase, Product, ProductPurchase } from 'react-native-iap';
5
+ import * as RNIap from 'react-native-iap';
6
6
  import axios from 'axios';
7
+ export class GoMarketMeAffiliateMarketingData {
8
+ campaign: Campaign;
9
+ affiliate: Affiliate;
10
+ saleDistribution: SaleDistribution;
11
+ affiliateCampaignCode: string;
12
+ deviceId: string;
13
+ offerCode?: string;
14
+
15
+ constructor(
16
+ campaign: Campaign,
17
+ affiliate: Affiliate,
18
+ saleDistribution: SaleDistribution,
19
+ affiliateCampaignCode: string,
20
+ deviceId: string,
21
+ offerCode?: string
22
+ ) {
23
+ this.campaign = campaign;
24
+ this.affiliate = affiliate;
25
+ this.saleDistribution = saleDistribution;
26
+ this.affiliateCampaignCode = affiliateCampaignCode;
27
+ this.deviceId = deviceId;
28
+ this.offerCode = offerCode;
29
+ }
30
+
31
+ static fromJson(json: Record<string, any>): GoMarketMeAffiliateMarketingData | null {
32
+ // Check if the json is an empty object
33
+ if (Object.keys(json).length === 0) {
34
+ return null; // Return null or undefined, depending on your preference
35
+ }
36
+
37
+ return new GoMarketMeAffiliateMarketingData(
38
+ Campaign.fromJson(json.campaign),
39
+ Affiliate.fromJson(json.affiliate),
40
+ SaleDistribution.fromJson(json.sale_distribution),
41
+ json.affiliate_campaign_code || '',
42
+ json.device_id || '',
43
+ json.offer_code
44
+ );
45
+ }
46
+ }
47
+
48
+ export class Campaign {
49
+ id: string;
50
+ name: string;
51
+ status: string;
52
+ type: string;
53
+ publicLinkUrl?: string;
54
+
55
+ constructor(id: string, name: string, status: string, type: string, publicLinkUrl?: string) {
56
+ this.id = id;
57
+ this.name = name;
58
+ this.status = status;
59
+ this.type = type;
60
+ this.publicLinkUrl = publicLinkUrl;
61
+ }
62
+
63
+ static fromJson(json: Record<string, any>): Campaign {
64
+ return new Campaign(
65
+ json.id || '',
66
+ json.name || '',
67
+ json.status || '',
68
+ json.type || '',
69
+ json.public_link_url
70
+ );
71
+ }
72
+ }
73
+
74
+ export class Affiliate {
75
+ id: string;
76
+ firstName: string;
77
+ lastName: string;
78
+ countryCode: string;
79
+ instagramAccount: string;
80
+ tiktokAccount: string;
81
+ xAccount: string;
82
+
83
+ constructor(
84
+ id: string,
85
+ firstName: string,
86
+ lastName: string,
87
+ countryCode: string,
88
+ instagramAccount: string,
89
+ tiktokAccount: string,
90
+ xAccount: string
91
+ ) {
92
+ this.id = id;
93
+ this.firstName = firstName;
94
+ this.lastName = lastName;
95
+ this.countryCode = countryCode;
96
+ this.instagramAccount = instagramAccount;
97
+ this.tiktokAccount = tiktokAccount;
98
+ this.xAccount = xAccount;
99
+ }
100
+
101
+ static fromJson(json: Record<string, any>): Affiliate {
102
+ return new Affiliate(
103
+ json.id || '',
104
+ json.first_name || '',
105
+ json.last_name || '',
106
+ json.country_code || '',
107
+ json.instagram_account || '',
108
+ json.tiktok_account || '',
109
+ json.x_account || ''
110
+ );
111
+ }
112
+ }
113
+
114
+ export class SaleDistribution {
115
+ platformPercentage: string;
116
+ affiliatePercentage: string;
117
+
118
+ constructor(platformPercentage: string, affiliatePercentage: string) {
119
+ this.platformPercentage = platformPercentage;
120
+ this.affiliatePercentage = affiliatePercentage;
121
+ }
122
+
123
+ static fromJson(json: Record<string, any>): SaleDistribution {
124
+ return new SaleDistribution(
125
+ json.platform_percentage || '',
126
+ json.affiliate_percentage || ''
127
+ );
128
+ }
129
+ }
7
130
 
8
131
  class GoMarketMe {
9
132
  private static instance: GoMarketMe;
133
+ private sdkType = 'ReactNative';
134
+ private sdkVersion = '2.0.0';
10
135
  private sdkInitializedKey = 'GOMARKETME_SDK_INITIALIZED';
11
- private affiliateCampaignCode = '';
12
- private deviceId = '';
13
- private sdkInitializationUrl = 'https://api.gomarketme.net/v1/sdk-initialization';
14
- private systemInfoUrl = 'https://api.gomarketme.net/v1/mobile/system-info';
15
- private eventUrl = 'https://api.gomarketme.net/v1/event';
136
+ private sdkInitializationUrl = 'https://4v9008q1a5.execute-api.us-west-2.amazonaws.com/prod/v1/sdk-initialization';
137
+ private systemInfoUrl = 'https://4v9008q1a5.execute-api.us-west-2.amazonaws.com/prod/v1/mobile/system-info';
138
+ private eventUrl = 'https://4v9008q1a5.execute-api.us-west-2.amazonaws.com/prod/v1/event';
139
+ private _affiliateCampaignCode = '';
140
+ private _deviceId = '';
141
+ private _packageName = ''
142
+ public affiliateMarketingData?: GoMarketMeAffiliateMarketingData | null;
16
143
 
17
- private constructor() {}
144
+ private constructor() { }
18
145
 
19
146
  public static getInstance(): GoMarketMe {
20
147
  if (!GoMarketMe.instance) {
@@ -25,51 +152,59 @@ class GoMarketMe {
25
152
 
26
153
  public async initialize(apiKey: string): Promise<void> {
27
154
  try {
28
- const isSDKInitialized = await this.isSDKInitialized();
155
+ const isSDKInitialized = await this._isSDKInitialized();
29
156
  if (!isSDKInitialized) {
30
- await this.postSDKInitialization(apiKey);
157
+ await this._postSDKInitialization(apiKey);
31
158
  }
32
- const systemInfo = await this.getSystemInfo();
33
- await this.postSystemInfo(systemInfo, apiKey);
34
- await this.addListener(apiKey);
159
+ this._packageName = DeviceInfo.getBundleId();
160
+ const systemInfo = await this._getSystemInfo();
161
+ this.affiliateMarketingData = await this._postSystemInfo(systemInfo, apiKey);
162
+ await this._addListener(apiKey);
35
163
  } catch (e) {
36
- console.error('Error initializing GoMarketMe:', e);
164
+ console.log('Error initializing GoMarketMe:', e);
37
165
  }
38
166
  }
39
167
 
40
- private async addListener(apiKey: string): Promise<void> {
41
- InAppPurchase.purchaseUpdatedListener(async (purchase: Purchase) => {
42
- if (this.affiliateCampaignCode != '') {
43
- const productIds = await this.fetchPurchases([purchase], apiKey);
44
- await this.fetchPurchaseProducts(productIds, apiKey);
45
- }
46
- });
168
+ private async _addListener(apiKey: string): Promise<void> {
169
+ try {
170
+ RNIap.purchaseUpdatedListener(async (purchase: RNIap.Purchase) => {
171
+ await this._fetchConsolidatedPurchases([purchase], apiKey);
172
+ });
173
+
174
+ RNIap.purchaseErrorListener((error) => {
175
+ console.log('Purchase error:', error);
176
+ });
177
+ } catch (e) {
178
+ console.log('Error setting up IAP listeners:', e);
179
+ }
47
180
  }
48
181
 
49
- private async getSystemInfo(): Promise<any> {
182
+ private async _getSystemInfo(): Promise<any> {
50
183
  const deviceData = Platform.select({
51
- ios: await this.readIosDeviceInfo(),
52
- android: await this.readAndroidDeviceInfo(),
184
+ ios: await this._readIosDeviceInfo(),
185
+ android: await this._readAndroidDeviceInfo(),
53
186
  });
54
-
187
+
188
+ this._deviceId = deviceData['deviceId'];
189
+
55
190
  const devicePixelRatio = PixelRatio.get();
56
191
  const dimension = Dimensions.get('window');
57
-
192
+
58
193
  const windowData = {
59
194
  devicePixelRatio: devicePixelRatio,
60
195
  width: dimension.width * devicePixelRatio,
61
196
  height: dimension.height * devicePixelRatio,
62
197
  };
63
-
198
+
64
199
  return {
65
200
  device_info: deviceData,
66
201
  window_info: windowData,
67
- time_zone: this.getTimeZone(),
68
- language_code: this.getLanguageCode(),
202
+ time_zone: this._getTimeZone(),
203
+ language_code: this._getLanguageCode(),
69
204
  };
70
205
  }
71
206
 
72
- private async postSDKInitialization(apiKey: string): Promise<void> {
207
+ private async _postSDKInitialization(apiKey: string): Promise<void> {
73
208
  try {
74
209
  const response = await axios.post(this.sdkInitializationUrl, {}, {
75
210
  headers: {
@@ -78,41 +213,42 @@ class GoMarketMe {
78
213
  },
79
214
  });
80
215
  if (response.status === 200) {
81
- await this.markSDKAsInitialized();
216
+ await this._markSDKAsInitialized();
82
217
  } else {
83
- console.error('Failed to mark SDK as Initialized. Status code:', response.status);
218
+ console.log('Failed to mark SDK as Initialized. Status code:', response.status);
84
219
  }
85
220
  } catch (e) {
86
- console.error('Error sending SDK information to server:', e);
221
+ console.log('Error sending SDK information to server:', e);
87
222
  }
88
223
  }
89
224
 
90
- private async postSystemInfo(systemInfo: any, apiKey: string): Promise<void> {
225
+ private async _postSystemInfo(data: any, apiKey: string): Promise<GoMarketMeAffiliateMarketingData | null> {
226
+ let output: GoMarketMeAffiliateMarketingData | null = null;
91
227
  try {
92
- const response = await axios.post(this.systemInfoUrl, systemInfo, {
228
+ data['sdk_type'] = this.sdkType;
229
+ data['sdk_version'] = this.sdkVersion;
230
+ data['package_name'] = this._packageName;
231
+ const response = await axios.post(this.systemInfoUrl, data, {
93
232
  headers: {
94
233
  'Content-Type': 'application/json',
95
234
  'x-api-key': apiKey,
96
235
  },
97
236
  });
98
237
  if (response.status === 200) {
99
- const responseData = response.data;
100
- if (responseData.affiliate_campaign_code) {
101
- this.affiliateCampaignCode = responseData.affiliate_campaign_code;
102
- }
103
- if (responseData.device_id) {
104
- this.deviceId = responseData.device_id;
238
+ output = GoMarketMeAffiliateMarketingData.fromJson(response.data);
239
+ if (output != null) {
240
+ this._affiliateCampaignCode = output.affiliateCampaignCode;
105
241
  }
106
-
107
242
  } else {
108
- console.error('Failed to send system info. Status code:', response.status);
243
+ console.log('Failed to send system info. Status code:', response.status);
109
244
  }
110
245
  } catch (e) {
111
- console.error('Error sending system info to server:', e);
246
+ console.log('Error sending system info to server:', e);
112
247
  }
248
+ return output;
113
249
  }
114
250
 
115
- private async readAndroidDeviceInfo(): Promise<any> {
251
+ private async _readAndroidDeviceInfo(): Promise<any> {
116
252
 
117
253
  let androidId = await DeviceInfo.getAndroidId();
118
254
  let uniqueId = await DeviceInfo.getUniqueId();
@@ -137,7 +273,7 @@ class GoMarketMe {
137
273
  };
138
274
  }
139
275
 
140
- private async readIosDeviceInfo(): Promise<any> {
276
+ private async _readIosDeviceInfo(): Promise<any> {
141
277
 
142
278
  let uniqueId = await DeviceInfo.getUniqueId();
143
279
  let deviceId = await DeviceInfo.getDeviceId(); // model
@@ -160,49 +296,47 @@ class GoMarketMe {
160
296
  };
161
297
  }
162
298
 
163
- private getTimeZone = (): string => {
299
+ private _getTimeZone = (): string => {
164
300
  return Intl.DateTimeFormat().resolvedOptions().timeZone;
165
- };
301
+ };
166
302
 
167
- private getLanguageCode(): string {
303
+ private _getLanguageCode(): string {
168
304
  return getUserLocale();
169
305
  }
170
306
 
171
- private async fetchPurchases(purchaseDetailsList: Purchase[], apiKey: string): Promise<string[]> {
172
- const productIds: string[] = [];
307
+ private async _fetchConsolidatedPurchases(purchaseDetailsList: RNIap.Purchase[], apiKey: string): Promise<void> {
173
308
  for (const purchase of purchaseDetailsList) {
174
309
  if (purchase.transactionReceipt) {
175
- await this.sendEventToServer(JSON.stringify(this.serializePurchaseDetails(purchase)), 'purchase', apiKey);
176
- if (purchase.productId && !productIds.includes(purchase.productId)) {
177
- productIds.push(purchase.productId);
310
+ var data = this._serializePurchaseDetails(purchase);
311
+ data['products'] = []
312
+ if (data.productID != '') {
313
+ const products = await RNIap.getProducts({ skus: [data.productID] })
314
+ if (products.length > 0) {
315
+ for (const product0 of products) {
316
+ data['products'].push(this._serializeProductDetails(product0))
317
+ }
318
+ }
319
+ else {
320
+ const products = await RNIap.getSubscriptions({ skus: [data.productID] });
321
+ if (products.length > 0) {
322
+ for (const product0 of products) {
323
+ data['products'].push(this._serializeSubscriptionDetails(product0))
324
+ }
325
+ }
326
+ }
178
327
  }
328
+ await this._sendEventToServer(JSON.stringify(data), 'purchase', apiKey);
179
329
  }
180
330
  }
181
- return productIds;
182
331
  }
183
332
 
184
- private async fetchPurchaseProducts(productIds: string[], apiKey: string): Promise<void> {
185
- try {
186
- const products = await InAppPurchase.getProducts(productIds);
187
- if (products.length > 0) {
188
- for (const product of products) {
189
- await this.sendEventToServer(JSON.stringify(this.serializeProductDetails(product)), 'product', apiKey);
190
- }
191
- } else {
192
- await this.sendEventToServer(JSON.stringify({ notFoundIDs: productIds.join(',') }), 'product', apiKey);
193
- }
194
- } catch (e) {
195
- console.error('Error fetching products:', e);
196
- }
197
- }
198
-
199
- private async sendEventToServer(body: string, eventType: string, apiKey: string): Promise<void> {
333
+ private async _sendEventToServer(body: string, eventType: string, apiKey: string): Promise<void> {
200
334
  try {
201
335
  const response = await axios.post(this.eventUrl, body, {
202
336
  headers: {
203
337
  'Content-Type': 'application/json',
204
- 'x-affiliate-campaign-code': this.affiliateCampaignCode,
205
- 'x-device-id': this.deviceId,
338
+ 'x-affiliate-campaign-code': this._affiliateCampaignCode,
339
+ 'x-device-id': this._deviceId,
206
340
  'x-event-type': eventType,
207
341
  'x-product-type': Platform.OS,
208
342
  'x-source-name': Platform.OS === 'android' ? 'google_play' : 'app_store',
@@ -212,15 +346,16 @@ class GoMarketMe {
212
346
  if (response.status === 200) {
213
347
  console.log(`${eventType} sent successfully`);
214
348
  } else {
215
- console.error(`Failed to send ${eventType}. Status code:`, response.status);
349
+ console.log(`Failed to send ${eventType}. Status code:`, response.status);
216
350
  }
217
351
  } catch (e) {
218
- console.error(`Error sending ${eventType} to server:`, e);
352
+ console.log(`Error sending ${eventType} to server:`, e);
219
353
  }
220
354
  }
221
355
 
222
- private serializePurchaseDetails(purchase: Purchase): any {
356
+ private _serializePurchaseDetails(purchase: RNIap.Purchase): any {
223
357
  return {
358
+ packageName: this._packageName,
224
359
  productID: purchase.productId,
225
360
  purchaseID: purchase.transactionId || '',
226
361
  transactionDate: purchase.transactionDate || '',
@@ -230,37 +365,76 @@ class GoMarketMe {
230
365
  }),
231
366
  verificationData: {
232
367
  localVerificationData: purchase.transactionReceipt,
368
+ serverVerificationData: purchase.transactionReceipt,
369
+ source: Platform.OS === 'android' ? 'google_play' : 'app_store',
233
370
  },
371
+ pendingCompletePurchase: '',
372
+ error: {},
373
+ hashCode: '',
374
+ _purchase: purchase
234
375
  };
235
376
  }
236
377
 
237
- private serializeProductDetails(product: Product): any {
378
+ private _serializeProductDetails(product: RNIap.Product): any {
238
379
  return {
380
+ packageName: this._packageName,
239
381
  productID: product.productId,
240
382
  productTitle: product.title,
241
383
  productDescription: product.description,
242
- productPrice: product.price,
384
+ productPrice: product.localizedPrice,
243
385
  productRawPrice: product.price,
386
+ productCurrencySymbol: product.localizedPrice.replace('product.price', ''),
244
387
  productCurrencyCode: product.currency,
388
+ hashCode: '',
389
+ _product: product
245
390
  };
246
391
  }
247
392
 
248
- private async markSDKAsInitialized(): Promise<boolean> {
393
+ private _serializeSubscriptionDetails(subscription: RNIap.Subscription): any {
394
+ let output: any = {
395
+ productID: subscription.productId,
396
+ productTitle: subscription.title,
397
+ productDescription: subscription.description,
398
+ hashCode: '',
399
+ };
400
+
401
+ if (Platform.OS === 'ios') {
402
+ const subscriptionIOS = subscription as RNIap.SubscriptionIOS;
403
+ output.productPrice = subscriptionIOS.localizedPrice;
404
+ output.productRawPrice = subscriptionIOS.price;
405
+ output.productCurrencyCode = subscriptionIOS.currency;
406
+ output._subscription = subscriptionIOS;
407
+ } else if (Platform.OS === 'android') {
408
+ const subscriptionAndroid = subscription as RNIap.SubscriptionAndroid;
409
+ if (subscriptionAndroid.subscriptionOfferDetails?.length) {
410
+ const offerDetails = subscriptionAndroid.subscriptionOfferDetails[0];
411
+ const priceAmountMicros = parseInt(offerDetails.pricingPhases.pricingPhaseList[0].priceAmountMicros, 10) || 0;
412
+ output.productPrice = offerDetails.pricingPhases.pricingPhaseList[0].formattedPrice;
413
+ output.productRawPrice = String(priceAmountMicros / 1_000_000);
414
+ output.productCurrencyCode = offerDetails.pricingPhases.pricingPhaseList[0].priceCurrencyCode;
415
+ }
416
+ output._subscription = subscriptionAndroid;
417
+ }
418
+
419
+ return output;
420
+ }
421
+
422
+ private async _markSDKAsInitialized(): Promise<boolean> {
249
423
  try {
250
424
  await AsyncStorage.setItem(this.sdkInitializedKey, 'true');
251
425
  return true;
252
426
  } catch (e) {
253
- console.error('Failed to save SDK initialization:', e);
427
+ console.log('Failed to save SDK initialization:', e);
254
428
  return false;
255
429
  }
256
430
  }
257
431
 
258
- private async isSDKInitialized(): Promise<boolean> {
432
+ private async _isSDKInitialized(): Promise<boolean> {
259
433
  try {
260
434
  const value = await AsyncStorage.getItem(this.sdkInitializedKey);
261
435
  return value === 'true';
262
436
  } catch (e) {
263
- console.error('Failed to load SDK initialization:', e);
437
+ console.log('Failed to load SDK initialization:', e);
264
438
  return false;
265
439
  }
266
440
  }