gomarketme-react-native 1.0.12 → 1.0.14

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/src/index.tsx CHANGED
@@ -1,7 +1,8 @@
1
1
  import { Platform, Dimensions, PixelRatio } from 'react-native';
2
2
  import DeviceInfo from 'react-native-device-info';
3
3
  import * as RNLocalize from 'react-native-localize';
4
- import InAppPurchase, { Purchase, Product } from 'react-native-iap';
4
+ import AsyncStorage from '@react-native-async-storage/async-storage';
5
+ import InAppPurchase, { Purchase, Product, ProductPurchase } from 'react-native-iap';
5
6
  import axios from 'axios';
6
7
 
7
8
  class GoMarketMe {
@@ -24,7 +25,7 @@ class GoMarketMe {
24
25
 
25
26
  public async initialize(apiKey: string): Promise<void> {
26
27
  try {
27
- const isSDKInitialized = this.isSDKInitialized();
28
+ const isSDKInitialized = await this.isSDKInitialized();
28
29
  if (!isSDKInitialized) {
29
30
  await this.postSDKInitialization(apiKey);
30
31
  }
@@ -38,7 +39,7 @@ class GoMarketMe {
38
39
 
39
40
  private async addListener(apiKey: string): Promise<void> {
40
41
  InAppPurchase.purchaseUpdatedListener(async (purchase: Purchase) => {
41
- if (this.affiliateCampaignCode) {
42
+ if (this.affiliateCampaignCode != '') {
42
43
  const productIds = await this.fetchPurchases([purchase], apiKey);
43
44
  await this.fetchPurchaseProducts(productIds, apiKey);
44
45
  }
@@ -54,7 +55,7 @@ class GoMarketMe {
54
55
  const devicePixelRatio = PixelRatio.get();
55
56
 
56
57
  const windowData = {
57
- devicePixelRatio,
58
+ devicePixelRatio: devicePixelRatio,
58
59
  width: Dimensions.get('window').width * devicePixelRatio,
59
60
  height: Dimensions.get('window').height * devicePixelRatio,
60
61
  };
@@ -76,7 +77,7 @@ class GoMarketMe {
76
77
  },
77
78
  });
78
79
  if (response.status === 200) {
79
- this.markSDKAsInitialized();
80
+ await this.markSDKAsInitialized();
80
81
  } else {
81
82
  console.error('Failed to mark SDK as Initialized. Status code:', response.status);
82
83
  }
@@ -95,8 +96,12 @@ class GoMarketMe {
95
96
  });
96
97
  if (response.status === 200) {
97
98
  const responseData = response.data;
98
- this.affiliateCampaignCode = responseData.affiliate_campaign_code || this.affiliateCampaignCode;
99
- this.deviceId = responseData.device_id || this.deviceId;
99
+ if (responseData.affiliate_campaign_code) {
100
+ this.affiliateCampaignCode = responseData.affiliate_campaign_code;
101
+ }
102
+ if (responseData.device_id) {
103
+ this.deviceId = responseData.device_id;
104
+ }
100
105
  } else {
101
106
  console.error('Failed to send system info. Status code:', response.status);
102
107
  }
@@ -108,6 +113,7 @@ class GoMarketMe {
108
113
  private async readAndroidDeviceInfo(): Promise<any> {
109
114
  return {
110
115
  deviceId: await DeviceInfo.getAndroidId(),
116
+ _deviceId: await DeviceInfo.getDeviceId(),
111
117
  systemName: await DeviceInfo.getSystemName(),
112
118
  systemVersion: await DeviceInfo.getSystemVersion(),
113
119
  brand: await DeviceInfo.getBrand(),
@@ -119,8 +125,9 @@ class GoMarketMe {
119
125
  }
120
126
 
121
127
  private async readIosDeviceInfo(): Promise<any> {
122
- return {
128
+ var info = {
123
129
  deviceId: await DeviceInfo.getUniqueId(),
130
+ _deviceId: await DeviceInfo.getDeviceId(),
124
131
  systemName: await DeviceInfo.getSystemName(),
125
132
  systemVersion: await DeviceInfo.getSystemVersion(),
126
133
  brand: await DeviceInfo.getBrand(),
@@ -132,17 +139,21 @@ class GoMarketMe {
132
139
  }
133
140
 
134
141
  private getTimeZoneCode(): string {
135
- const timezoneOffset = new Date().getTimezoneOffset();
142
+ // Convert the time zone to GMT format (e.g., "GMT+2")
143
+ const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
144
+ const date = new Date();
145
+ const timezoneOffset = date.getTimezoneOffset(); // in minutes
136
146
  const absOffset = Math.abs(timezoneOffset);
137
147
  const hours = Math.floor(absOffset / 60);
138
148
  const minutes = absOffset % 60;
139
149
  const sign = timezoneOffset > 0 ? '-' : '+';
140
- return `GMT${sign}${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}`;
150
+ return `GMT${sign}${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}`; // Return GMT format
141
151
  }
142
152
 
143
153
  private getLanguageCode(): string {
144
154
  const locales = RNLocalize.getLocales();
145
- return locales.length > 0 ? locales[0].languageTag : 'en-US';
155
+ // Check if there are any locales available and return the first one or default to 'en-US'
156
+ return locales.length > 0 ? locales[0].languageTag : 'en-US';
146
157
  }
147
158
 
148
159
  private async fetchPurchases(purchaseDetailsList: Purchase[], apiKey: string): Promise<string[]> {
@@ -202,7 +213,7 @@ class GoMarketMe {
202
213
  purchaseID: purchase.transactionId || '',
203
214
  transactionDate: purchase.transactionDate || '',
204
215
  status: Platform.select({
205
- ios: (purchase as any).transactionStateIOS,
216
+ ios: (purchase as any).transactionStateIOS, // Removed non-existent properties
206
217
  android: (purchase as any).purchaseStateAndroid,
207
218
  }),
208
219
  verificationData: {
@@ -215,16 +226,31 @@ class GoMarketMe {
215
226
  return {
216
227
  productID: product.productId,
217
228
  productTitle: product.title,
229
+ productDescription: product.description,
218
230
  productPrice: product.price,
231
+ productRawPrice: product.price,
232
+ productCurrencyCode: product.currency,
219
233
  };
220
234
  }
221
235
 
222
- private isSDKInitialized(): boolean {
223
- return false;
236
+ private async markSDKAsInitialized(): Promise<boolean> {
237
+ try {
238
+ await AsyncStorage.setItem(this.sdkInitializedKey, 'true');
239
+ return true;
240
+ } catch (e) {
241
+ console.error('Failed to save SDK initialization:', e);
242
+ return false;
243
+ }
224
244
  }
225
245
 
226
- private markSDKAsInitialized(): boolean {
227
- return true;
246
+ private async isSDKInitialized(): Promise<boolean> {
247
+ try {
248
+ const value = await AsyncStorage.getItem(this.sdkInitializedKey);
249
+ return value === 'true';
250
+ } catch (e) {
251
+ console.error('Failed to load SDK initialization:', e);
252
+ return false;
253
+ }
228
254
  }
229
255
  }
230
256
 
package/tsconfig.json CHANGED
@@ -16,4 +16,4 @@
16
16
  },
17
17
  "include": ["src/**/*.ts", "src/**/*.tsx"],
18
18
  "exclude": ["node_modules", "dist", "**/__tests__/*"]
19
- }
19
+ }