insert-affiliate-react-native-sdk 1.0.4 → 1.0.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "insert-affiliate-react-native-sdk",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
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",
package/readme.md CHANGED
@@ -2,14 +2,13 @@
2
2
 
3
3
  ## Overview
4
4
 
5
- The **InsertAffiliateReactNative SDK** is designed for React Native applications, providing seamless integration with the [Insert Affiliate platform](https://insertaffiliate.com). This SDK enables functionalities such as managing affiliate links, handling in-app purchases (IAP), and utilising deep links. For more details and to access the Insert Affiliate dashboard, visit [app.insertaffiliate.com](https://app.insertaffiliate.com).
5
+ The **InsertAffiliateReactNative SDK** is designed for React Native applications, providing seamless integration with the [Insert Affiliate platform](https://insertaffiliate.com). For more details and to access the Insert Affiliate dashboard, visit [app.insertaffiliate.com](https://app.insertaffiliate.com).
6
6
 
7
7
  ## Features
8
8
 
9
9
  - **Unique Device Identification**: Generates and stores a short unique device ID to identify users effectively.
10
10
  - **Affiliate Identifier Management**: Set and retrieve the affiliate identifier based on user-specific links.
11
11
  - **In-App Purchase (IAP) Initialisation**: Easily reinitialise in-app purchases with validation options using the affiliate identifier.
12
- - **Offer Code Handling**: Fetch offer codes from the Insert Affiliate API and open redeem URLs directly in the App Store.
13
12
 
14
13
  ## Peer Dependencies
15
14
 
@@ -52,7 +51,7 @@ const App = () => {
52
51
  iapSkus={IAP_SKUS}
53
52
  iapticAppId="{{ your_iaptic_app_id }}"
54
53
  iapticAppName="{{ your_iaptic_app_name }}"
55
- iapticAppPublicKey="{{ your_iaptic_public_key }}">
54
+ iapticPublicKey="{{ your_iaptic_public_key }}">
56
55
  <Child />
57
56
  </DeepLinkIapProvider>
58
57
  );
@@ -114,7 +113,7 @@ const App = () => {
114
113
  iapSkus={IAP_SKUS}
115
114
  iapticAppId="your_iaptic_app_id"
116
115
  iapticAppName="your_iaptic_app_name"
117
- iapticAppPublicKey="your_iaptic_public_key">
116
+ iapticPublicKey="your_iaptic_public_key">
118
117
  <Child />
119
118
  </DeepLinkIapProvider>
120
119
  );
@@ -9,6 +9,7 @@ import {
9
9
  } from "react-native-iap";
10
10
  import { isPlay } from "react-native-iap/src/internal";
11
11
  import branch from "react-native-branch";
12
+ import { Platform } from "react-native";
12
13
  import axios from "axios";
13
14
  import AsyncStorage from "@react-native-async-storage/async-storage";
14
15
 
@@ -18,7 +19,7 @@ type T_DEEPLINK_IAP_PROVIDER = {
18
19
  iapSkus: string[];
19
20
  iapticAppId: string;
20
21
  iapticAppName: string;
21
- iapticAppPublicKey: string;
22
+ iapticPublicKey: string;
22
23
  };
23
24
 
24
25
  type T_DEEPLINK_IAP_CONTEXT = {
@@ -32,6 +33,22 @@ type T_DEEPLINK_IAP_CONTEXT = {
32
33
  handleBuySubscription: (productId: string, offerToken?: string) => void;
33
34
  };
34
35
 
36
+ type RequestBody = {
37
+ id: string;
38
+ type: string;
39
+ transaction?: {
40
+ id: string;
41
+ type: string;
42
+ appStoreReceipt?: string; // iOS-specific
43
+ purchaseToken?: string; // Android-specific
44
+ receipt?: string; // Android-specific
45
+ signature?: string; // Android-specific
46
+ };
47
+ additionalData?: {
48
+ applicationUsername: string;
49
+ };
50
+ };
51
+
35
52
  const ASYNC_KEYS = {
36
53
  REFERRER_LINK: "@app_referrer_link",
37
54
  USER_PURCHASE: "@app_user_purchase",
@@ -55,7 +72,7 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
55
72
  iapSkus,
56
73
  iapticAppId,
57
74
  iapticAppName,
58
- iapticAppPublicKey,
75
+ iapticPublicKey,
59
76
  }) => {
60
77
  // LOCAL STATES
61
78
  const [iapLoading, setIapLoading] = useState<boolean>(false);
@@ -221,55 +238,66 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
221
238
 
222
239
  const handlePurchaseValidation = async (jsonIapPurchase: Purchase) => {
223
240
  try {
224
- if (!userId || !referrerLink) {
225
- errorLog(
226
- `WANR ~ handlePurchaseValidation: No Referrer Link or User ID for validation`
227
- );
228
-
229
- await axios({
230
- url: `https://validator.iaptic.com/v1/validate`,
231
- method: "POST",
232
- headers: {
233
- Authorization: `Basic ${btoa(
234
- iapticAppName + ":" + iapticAppPublicKey
235
- )}`,
236
- },
237
- data: {
238
- id: iapticAppId,
239
- type: "application",
240
- transaction: {
241
- id: iapticAppId,
242
- type: "ios-appstore",
243
- appStoreReceipt: jsonIapPurchase.transactionReceipt,
244
- },
245
- },
246
- });
241
+ const baseRequestBody: RequestBody = {
242
+ id: iapticAppId,
243
+ type: "application",
244
+ };
245
+
246
+ let transaction;
247
+
248
+ if (Platform.OS === "ios") {
249
+ transaction = {
250
+ id: iapticAppId,
251
+ type: "ios-appstore",
252
+ appStoreReceipt: jsonIapPurchase.transactionReceipt,
253
+ };
254
+ } else {
255
+ const receiptJson = JSON.parse(atob(jsonIapPurchase.transactionReceipt || ""));
256
+ transaction = {
257
+ id: receiptJson.orderId, // Extracted orderId
258
+ type: "android-playstore",
259
+ purchaseToken: receiptJson.purchaseToken, // Extracted purchase token
260
+ receipt: jsonIapPurchase.transactionReceipt, // Full receipt (Base64)
261
+ signature: receiptJson.signature, // Receipt signature
262
+ };
263
+ }
264
+
265
+ const requestBody = {
266
+ ...baseRequestBody,
267
+ transaction,
268
+ };
269
+
270
+ if (userId && referrerLink) {
271
+ requestBody.additionalData = {
272
+ applicationUsername: `${referrerLink}/${userId}`,
273
+ };
274
+ }
275
+
276
+ // Send validation request to server
277
+ const response = await axios({
278
+ url: `https://validator.iaptic.com/v1/validate`,
279
+ method: "POST",
280
+ headers: {
281
+ Authorization: `Basic ${btoa(`${iapticAppName}:${iapticPublicKey}`)}`,
282
+ "Content-Type": "application/json",
283
+ },
284
+ data: requestBody,
285
+ });
286
+
287
+ if (response.status === 200) {
288
+ console.log("Validation successful:", response.data);
247
289
  setIapticValidated(true);
248
290
  } else {
249
- await axios({
250
- url: `https://validator.iaptic.com/v1/validate`,
251
- method: "POST",
252
- headers: {
253
- Authorization: `Basic ${btoa(
254
- iapticAppName + ":" + iapticAppPublicKey
255
- )}`,
256
- },
257
- data: {
258
- id: iapticAppId,
259
- type: "application",
260
- transaction: {
261
- id: iapticAppId,
262
- type: "ios-appstore",
263
- appStoreReceipt: jsonIapPurchase.transactionReceipt,
264
- },
265
- additionalData: {
266
- applicationUsername: `${referrerLink}/${userId}`,
267
- },
268
- },
269
- });
291
+ console.error("Validation failed:", response.data);
292
+ setIapticValidated(false);
270
293
  }
271
294
  } catch (error) {
272
- errorLog(`handlePurchaseValidation: ${error}`, "error");
295
+ if (error instanceof Error) {
296
+ console.error(`handlePurchaseValidation Error: ${error.message}`);
297
+ } else {
298
+ console.error(`handlePurchaseValidation Unknown Error: ${JSON.stringify(error)}`);
299
+ }
300
+
273
301
  setIapticValidated(false);
274
302
  }
275
303
  };
File without changes