insert-affiliate-react-native-sdk 1.0.7 → 1.0.9

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.
@@ -5,7 +5,7 @@ type T_DEEPLINK_IAP_PROVIDER = {
5
5
  iapSkus: string[];
6
6
  iapticAppId: string;
7
7
  iapticAppName: string;
8
- iapticAppSecret: string;
8
+ iapticPublicKey: string;
9
9
  };
10
10
  type T_DEEPLINK_IAP_CONTEXT = {
11
11
  iapLoading: boolean;
@@ -16,6 +16,7 @@ type T_DEEPLINK_IAP_CONTEXT = {
16
16
  userId: string;
17
17
  isIapticValidated: boolean | undefined;
18
18
  handleBuySubscription: (productId: string, offerToken?: string) => void;
19
+ trackEvent: (eventName: string) => Promise<void>;
19
20
  };
20
21
  export declare const DeepLinkIapContext: React.Context<T_DEEPLINK_IAP_CONTEXT>;
21
22
  declare const _default: (props: T_DEEPLINK_IAP_PROVIDER) => React.JSX.Element;
@@ -40,6 +40,7 @@ const react_1 = __importStar(require("react"));
40
40
  const react_native_iap_1 = require("react-native-iap");
41
41
  const internal_1 = require("react-native-iap/src/internal");
42
42
  const react_native_branch_1 = __importDefault(require("react-native-branch"));
43
+ const react_native_1 = require("react-native");
43
44
  const axios_1 = __importDefault(require("axios"));
44
45
  const async_storage_1 = __importDefault(require("@react-native-async-storage/async-storage"));
45
46
  const ASYNC_KEYS = {
@@ -57,8 +58,9 @@ exports.DeepLinkIapContext = (0, react_1.createContext)({
57
58
  referrerLink: "",
58
59
  userId: "",
59
60
  handleBuySubscription: (productId, offerToken) => { },
61
+ trackEvent: (eventName) => __awaiter(void 0, void 0, void 0, function* () { }),
60
62
  });
61
- const DeepLinkIapProvider = ({ children, iapSkus, iapticAppId, iapticAppName, iapticAppSecret, }) => {
63
+ const DeepLinkIapProvider = ({ children, iapSkus, iapticAppId, iapticAppName, iapticPublicKey, }) => {
62
64
  // LOCAL STATES
63
65
  const [iapLoading, setIapLoading] = (0, react_1.useState)(false);
64
66
  const [alreadyPurchased, setAlreadyPurchased] = (0, react_1.useState)(false);
@@ -198,50 +200,60 @@ const DeepLinkIapProvider = ({ children, iapSkus, iapticAppId, iapticAppName, ia
198
200
  }, [connected]);
199
201
  const handlePurchaseValidation = (jsonIapPurchase) => __awaiter(void 0, void 0, void 0, function* () {
200
202
  try {
201
- if (!userId || !referrerLink) {
202
- errorLog(`WANR ~ handlePurchaseValidation: No Referrer Link or User ID for validation`);
203
- yield (0, axios_1.default)({
204
- url: `https://validator.iaptic.com/v1/validate`,
205
- method: "POST",
206
- headers: {
207
- Authorization: `Basic ${btoa(iapticAppName + ":" + iapticAppSecret)}`,
208
- },
209
- data: {
210
- id: iapticAppId,
211
- type: "application",
212
- transaction: {
213
- id: iapticAppId,
214
- type: "ios-appstore",
215
- appStoreReceipt: jsonIapPurchase.transactionReceipt,
216
- },
217
- },
218
- });
203
+ const baseRequestBody = {
204
+ id: iapticAppId,
205
+ type: "application",
206
+ };
207
+ let transaction;
208
+ if (react_native_1.Platform.OS === "ios") {
209
+ transaction = {
210
+ id: iapticAppId,
211
+ type: "ios-appstore",
212
+ appStoreReceipt: jsonIapPurchase.transactionReceipt,
213
+ };
214
+ }
215
+ else {
216
+ const receiptJson = JSON.parse(atob(jsonIapPurchase.transactionReceipt || ""));
217
+ transaction = {
218
+ id: receiptJson.orderId, // Extracted orderId
219
+ type: "android-playstore",
220
+ purchaseToken: receiptJson.purchaseToken, // Extracted purchase token
221
+ receipt: jsonIapPurchase.transactionReceipt, // Full receipt (Base64)
222
+ signature: receiptJson.signature, // Receipt signature
223
+ };
224
+ }
225
+ const requestBody = Object.assign(Object.assign({}, baseRequestBody), { transaction });
226
+ if (userId && referrerLink) {
227
+ requestBody.additionalData = {
228
+ applicationUsername: `${referrerLink}/${userId}`,
229
+ };
230
+ }
231
+ // Send validation request to server
232
+ const response = yield (0, axios_1.default)({
233
+ url: `https://validator.iaptic.com/v1/validate`,
234
+ method: "POST",
235
+ headers: {
236
+ Authorization: `Basic ${btoa(`${iapticAppName}:${iapticPublicKey}`)}`,
237
+ "Content-Type": "application/json",
238
+ },
239
+ data: requestBody,
240
+ });
241
+ if (response.status === 200) {
242
+ console.log("Validation successful:", response.data);
219
243
  setIapticValidated(true);
220
244
  }
221
245
  else {
222
- yield (0, axios_1.default)({
223
- url: `https://validator.iaptic.com/v1/validate`,
224
- method: "POST",
225
- headers: {
226
- Authorization: `Basic ${btoa(iapticAppName + ":" + iapticAppSecret)}`,
227
- },
228
- data: {
229
- id: iapticAppId,
230
- type: "application",
231
- transaction: {
232
- id: iapticAppId,
233
- type: "ios-appstore",
234
- appStoreReceipt: jsonIapPurchase.transactionReceipt,
235
- },
236
- additionalData: {
237
- applicationUsername: `${referrerLink}/${userId}`,
238
- },
239
- },
240
- });
246
+ console.error("Validation failed:", response.data);
247
+ setIapticValidated(false);
241
248
  }
242
249
  }
243
250
  catch (error) {
244
- errorLog(`handlePurchaseValidation: ${error}`, "error");
251
+ if (error instanceof Error) {
252
+ console.error(`handlePurchaseValidation Error: ${error.message}`);
253
+ }
254
+ else {
255
+ console.error(`handlePurchaseValidation Unknown Error: ${JSON.stringify(error)}`);
256
+ }
245
257
  setIapticValidated(false);
246
258
  }
247
259
  });
@@ -296,6 +308,30 @@ const DeepLinkIapProvider = ({ children, iapSkus, iapticAppId, iapticAppName, ia
296
308
  errorLog(`handleBuySubscription: ${error}`, "error");
297
309
  }
298
310
  });
311
+ const trackEvent = (eventName) => __awaiter(void 0, void 0, void 0, function* () {
312
+ try {
313
+ if (!referrerLink || !userId) {
314
+ console.warn("[Insert Affiliate] No affiliate identifier found. Please set one before tracking events.");
315
+ return;
316
+ }
317
+ const payload = {
318
+ eventName,
319
+ deepLinkParam: `${referrerLink}/${userId}`, // Similar to Swift SDK
320
+ };
321
+ const response = yield axios_1.default.post("https://api.insertaffiliate.com/v1/trackEvent", payload, {
322
+ headers: { "Content-Type": "application/json" },
323
+ });
324
+ if (response.status === 200) {
325
+ console.log("[Insert Affiliate] Event tracked successfully");
326
+ }
327
+ else {
328
+ console.error(`[Insert Affiliate] Failed to track event with status code: ${response.status}`);
329
+ }
330
+ }
331
+ catch (error) {
332
+ console.error("[Insert Affiliate] Error tracking event:", error);
333
+ }
334
+ });
299
335
  (0, react_1.useEffect)(() => {
300
336
  return () => {
301
337
  (0, react_native_iap_1.endConnection)();
@@ -310,6 +346,7 @@ const DeepLinkIapProvider = ({ children, iapSkus, iapticAppId, iapticAppName, ia
310
346
  referrerLink,
311
347
  userId,
312
348
  handleBuySubscription,
349
+ trackEvent,
313
350
  } }, children));
314
351
  };
315
352
  exports.default = (0, react_native_iap_1.withIAPContext)(DeepLinkIapProvider);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "insert-affiliate-react-native-sdk",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "A package that will give context having implementation of react-native-branch and react-native-iap and iaptic validate api.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -11,6 +11,7 @@ const useDeepLinkIapProvider = () => {
11
11
  subscriptions,
12
12
  userId,
13
13
  userPurchase,
14
+ trackEvent,
14
15
  } = useContext(DeepLinkIapContext);
15
16
 
16
17
  return {
@@ -22,6 +23,7 @@ const useDeepLinkIapProvider = () => {
22
23
  userId,
23
24
  isIapticValidated,
24
25
  userPurchase,
26
+ trackEvent
25
27
  };
26
28
  };
27
29
 
package/updateProcess.md CHANGED
@@ -1,6 +1,10 @@
1
1
  1. Update version number in package.json...
2
+ npm run build
3
+
2
4
  2. Make changes, push to main
3
5
  git tag v1.0...
4
6
  git push origin --tags
7
+
5
8
  3. Release version update on github
9
+
6
10
  4. Run npm publish to update - https://www.npmjs.com/package/insert-affiliate-react-native-sdk