insert-affiliate-react-native-sdk 1.6.0 → 1.6.2
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/dist/DeepLinkIapProvider.d.ts +1 -1
- package/dist/DeepLinkIapProvider.js +9 -9
- package/dist/useDeepLinkIapProvider.d.ts +1 -1
- package/dist/useDeepLinkIapProvider.js +2 -2
- package/package.json +1 -1
- package/readme.md +18 -18
- package/src/DeepLinkIapProvider.tsx +10 -10
- package/src/useDeepLinkIapProvider.tsx +2 -2
|
@@ -8,7 +8,7 @@ type CustomPurchase = {
|
|
|
8
8
|
type T_DEEPLINK_IAP_CONTEXT = {
|
|
9
9
|
referrerLink: string;
|
|
10
10
|
userId: string;
|
|
11
|
-
|
|
11
|
+
OfferCode: string | null;
|
|
12
12
|
returnInsertAffiliateIdentifier: () => Promise<string | null>;
|
|
13
13
|
validatePurchaseWithIapticAPI: (jsonIapPurchase: CustomPurchase, iapticAppId: string, iapticAppName: string, iapticPublicKey: string) => Promise<boolean>;
|
|
14
14
|
returnUserAccountTokenAndStoreExpectedTransaction: () => Promise<string | null>;
|
|
@@ -52,7 +52,7 @@ const ASYNC_KEYS = {
|
|
|
52
52
|
exports.DeepLinkIapContext = (0, react_1.createContext)({
|
|
53
53
|
referrerLink: '',
|
|
54
54
|
userId: '',
|
|
55
|
-
|
|
55
|
+
OfferCode: null,
|
|
56
56
|
returnInsertAffiliateIdentifier: () => __awaiter(void 0, void 0, void 0, function* () { return ''; }),
|
|
57
57
|
validatePurchaseWithIapticAPI: (jsonIapPurchase, iapticAppId, iapticAppName, iapticPublicKey) => __awaiter(void 0, void 0, void 0, function* () { return false; }),
|
|
58
58
|
returnUserAccountTokenAndStoreExpectedTransaction: () => __awaiter(void 0, void 0, void 0, function* () { return ''; }),
|
|
@@ -69,7 +69,7 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
69
69
|
const [companyCode, setCompanyCode] = (0, react_1.useState)(null);
|
|
70
70
|
const [isInitialized, setIsInitialized] = (0, react_1.useState)(false);
|
|
71
71
|
const [verboseLogging, setVerboseLogging] = (0, react_1.useState)(false);
|
|
72
|
-
const [
|
|
72
|
+
const [OfferCode, setOfferCode] = (0, react_1.useState)(null);
|
|
73
73
|
// MARK: Initialize the SDK
|
|
74
74
|
const initialize = (companyCode_1, ...args_1) => __awaiter(void 0, [companyCode_1, ...args_1], void 0, function* (companyCode, verboseLogging = false) {
|
|
75
75
|
setVerboseLogging(verboseLogging);
|
|
@@ -109,11 +109,11 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
109
109
|
const uId = yield getValueFromAsync(ASYNC_KEYS.USER_ID);
|
|
110
110
|
const refLink = yield getValueFromAsync(ASYNC_KEYS.REFERRER_LINK);
|
|
111
111
|
const companyCodeFromStorage = yield getValueFromAsync(ASYNC_KEYS.COMPANY_CODE);
|
|
112
|
-
const
|
|
112
|
+
const storedOfferCode = yield getValueFromAsync(ASYNC_KEYS.IOS_OFFER_CODE);
|
|
113
113
|
verboseLog(`User ID found: ${uId ? 'Yes' : 'No'}`);
|
|
114
114
|
verboseLog(`Referrer link found: ${refLink ? 'Yes' : 'No'}`);
|
|
115
115
|
verboseLog(`Company code found: ${companyCodeFromStorage ? 'Yes' : 'No'}`);
|
|
116
|
-
verboseLog(`iOS Offer Code found: ${
|
|
116
|
+
verboseLog(`iOS Offer Code found: ${storedOfferCode ? 'Yes' : 'No'}`);
|
|
117
117
|
if (uId && refLink) {
|
|
118
118
|
setUserId(uId);
|
|
119
119
|
setReferrerLink(refLink);
|
|
@@ -123,8 +123,8 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
123
123
|
setCompanyCode(companyCodeFromStorage);
|
|
124
124
|
verboseLog('Company code restored from storage');
|
|
125
125
|
}
|
|
126
|
-
if (
|
|
127
|
-
|
|
126
|
+
if (storedOfferCode) {
|
|
127
|
+
setOfferCode(storedOfferCode);
|
|
128
128
|
verboseLog('iOS Offer Code restored from storage');
|
|
129
129
|
}
|
|
130
130
|
}
|
|
@@ -586,7 +586,7 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
586
586
|
if (offerCode && offerCode.length > 0) {
|
|
587
587
|
// Store in both AsyncStorage and state
|
|
588
588
|
yield saveValueInAsync(ASYNC_KEYS.IOS_OFFER_CODE, offerCode);
|
|
589
|
-
|
|
589
|
+
setOfferCode(offerCode);
|
|
590
590
|
verboseLog(`Successfully stored offer code: ${offerCode}`);
|
|
591
591
|
console.log('[Insert Affiliate] Offer code retrieved and stored successfully');
|
|
592
592
|
}
|
|
@@ -594,7 +594,7 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
594
594
|
verboseLog('No valid offer code found to store');
|
|
595
595
|
// Clear stored offer code if none found
|
|
596
596
|
yield saveValueInAsync(ASYNC_KEYS.IOS_OFFER_CODE, '');
|
|
597
|
-
|
|
597
|
+
setOfferCode(null);
|
|
598
598
|
}
|
|
599
599
|
}
|
|
600
600
|
catch (error) {
|
|
@@ -613,7 +613,7 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
613
613
|
return (react_1.default.createElement(exports.DeepLinkIapContext.Provider, { value: {
|
|
614
614
|
referrerLink,
|
|
615
615
|
userId,
|
|
616
|
-
|
|
616
|
+
OfferCode,
|
|
617
617
|
setShortCode,
|
|
618
618
|
returnInsertAffiliateIdentifier,
|
|
619
619
|
storeExpectedStoreTransaction,
|
|
@@ -12,6 +12,6 @@ declare const useDeepLinkIapProvider: () => {
|
|
|
12
12
|
setInsertAffiliateIdentifier: (referringLink: string) => Promise<void | string>;
|
|
13
13
|
initialize: (code: string | null, verboseLogging?: boolean) => Promise<void>;
|
|
14
14
|
isInitialized: boolean;
|
|
15
|
-
|
|
15
|
+
OfferCode: string | null;
|
|
16
16
|
};
|
|
17
17
|
export default useDeepLinkIapProvider;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const react_1 = require("react");
|
|
4
4
|
const DeepLinkIapProvider_1 = require("./DeepLinkIapProvider");
|
|
5
5
|
const useDeepLinkIapProvider = () => {
|
|
6
|
-
const { referrerLink, userId, validatePurchaseWithIapticAPI, storeExpectedStoreTransaction, returnUserAccountTokenAndStoreExpectedTransaction, returnInsertAffiliateIdentifier, trackEvent, setShortCode, setInsertAffiliateIdentifier, initialize, isInitialized,
|
|
6
|
+
const { referrerLink, userId, validatePurchaseWithIapticAPI, storeExpectedStoreTransaction, returnUserAccountTokenAndStoreExpectedTransaction, returnInsertAffiliateIdentifier, trackEvent, setShortCode, setInsertAffiliateIdentifier, initialize, isInitialized, OfferCode, } = (0, react_1.useContext)(DeepLinkIapProvider_1.DeepLinkIapContext);
|
|
7
7
|
return {
|
|
8
8
|
referrerLink,
|
|
9
9
|
userId,
|
|
@@ -16,7 +16,7 @@ const useDeepLinkIapProvider = () => {
|
|
|
16
16
|
setInsertAffiliateIdentifier,
|
|
17
17
|
initialize,
|
|
18
18
|
isInitialized,
|
|
19
|
-
|
|
19
|
+
OfferCode,
|
|
20
20
|
};
|
|
21
21
|
};
|
|
22
22
|
exports.default = useDeepLinkIapProvider;
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -528,7 +528,7 @@ The SDK allows you to apply dynamic modifiers to in-app purchases based on wheth
|
|
|
528
528
|
|
|
529
529
|
#### How It Works
|
|
530
530
|
|
|
531
|
-
When a user clicks an affiliate link or enters a short code linked to an offer (set up in the **Insert Affiliate Dashboard**), the SDK auto-populates the `
|
|
531
|
+
When a user clicks an affiliate link or enters a short code linked to an offer (set up in the **Insert Affiliate Dashboard**), the SDK auto-populates the `OfferCode` field with a relevant modifier (e.g., `_oneWeekFree`). You can append this to your base product ID to dynamically display the correct subscription.
|
|
532
532
|
|
|
533
533
|
|
|
534
534
|
#### Basic Usage
|
|
@@ -540,7 +540,7 @@ If an affiliate short code is stored, the SDK automatically fetches and saves th
|
|
|
540
540
|
The offer code modifier is available through the context:
|
|
541
541
|
|
|
542
542
|
```javascript
|
|
543
|
-
const {
|
|
543
|
+
const { OfferCode } = useDeepLinkIapProvider();
|
|
544
544
|
```
|
|
545
545
|
|
|
546
546
|
##### Setup Requirements
|
|
@@ -553,7 +553,7 @@ const { iOSOfferCode } = useDeepLinkIapProvider();
|
|
|
553
553
|
|
|
554
554
|
|
|
555
555
|
**Product Naming Pattern:**
|
|
556
|
-
- Follow the pattern: `{baseProductId}{
|
|
556
|
+
- Follow the pattern: `{baseProductId}{OfferCode}`
|
|
557
557
|
- Example: `oneMonthSubscription` + `_oneWeekFree` = `oneMonthSubscription_oneWeekFree`
|
|
558
558
|
|
|
559
559
|
---
|
|
@@ -578,14 +578,14 @@ import { useDeepLinkIapProvider } from 'insert-affiliate-react-native-sdk';
|
|
|
578
578
|
import Purchases from 'react-native-purchases';
|
|
579
579
|
|
|
580
580
|
const PurchaseHandler = () => {
|
|
581
|
-
const {
|
|
581
|
+
const { OfferCode } = useDeepLinkIapProvider();
|
|
582
582
|
const [subscriptions, setSubscriptions] = useState([]);
|
|
583
583
|
|
|
584
584
|
const fetchSubscriptions = async () => {
|
|
585
585
|
const offerings = await Purchases.getOfferings();
|
|
586
586
|
let packagesToUse = [];
|
|
587
587
|
|
|
588
|
-
if (
|
|
588
|
+
if (OfferCode) {
|
|
589
589
|
|
|
590
590
|
|
|
591
591
|
// Construct modified product IDs from base products
|
|
@@ -593,7 +593,7 @@ const PurchaseHandler = () => {
|
|
|
593
593
|
|
|
594
594
|
for (const basePackage of baseProducts) {
|
|
595
595
|
const baseProductId = basePackage.product.identifier;
|
|
596
|
-
const modifiedProductId = `${baseProductId}_${
|
|
596
|
+
const modifiedProductId = `${baseProductId}_${OfferCode}`;
|
|
597
597
|
|
|
598
598
|
// Search all offerings for the modified product
|
|
599
599
|
const allOfferings = Object.values(offerings.all);
|
|
@@ -633,7 +633,7 @@ const PurchaseHandler = () => {
|
|
|
633
633
|
|
|
634
634
|
useEffect(() => {
|
|
635
635
|
fetchSubscriptions();
|
|
636
|
-
}, [
|
|
636
|
+
}, [OfferCode]);
|
|
637
637
|
|
|
638
638
|
return (
|
|
639
639
|
<View>
|
|
@@ -644,8 +644,8 @@ const PurchaseHandler = () => {
|
|
|
644
644
|
onPress={() => handlePurchase(pkg)}
|
|
645
645
|
/>
|
|
646
646
|
))}
|
|
647
|
-
{
|
|
648
|
-
<Text>Special offer applied: {
|
|
647
|
+
{OfferCode && (
|
|
648
|
+
<Text>Special offer applied: {OfferCode}</Text>
|
|
649
649
|
)}
|
|
650
650
|
</View>
|
|
651
651
|
);
|
|
@@ -669,7 +669,7 @@ import {
|
|
|
669
669
|
} from 'react-native-iap';
|
|
670
670
|
|
|
671
671
|
const NativeIAPPurchaseView = () => {
|
|
672
|
-
const {
|
|
672
|
+
const { OfferCode, returnUserAccountTokenAndStoreExpectedTransaction } = useDeepLinkIapProvider();
|
|
673
673
|
const [availableProducts, setAvailableProducts] = useState([]);
|
|
674
674
|
const [loading, setLoading] = useState(false);
|
|
675
675
|
const { currentPurchase, connected } = useIAP();
|
|
@@ -677,8 +677,8 @@ const NativeIAPPurchaseView = () => {
|
|
|
677
677
|
const baseProductIdentifier = "oneMonthSubscription";
|
|
678
678
|
|
|
679
679
|
// Dynamic product identifier that includes offer code
|
|
680
|
-
const dynamicProductIdentifier =
|
|
681
|
-
? `${baseProductIdentifier}${
|
|
680
|
+
const dynamicProductIdentifier = OfferCode
|
|
681
|
+
? `${baseProductIdentifier}${OfferCode}` // e.g., "oneMonthSubscription_oneWeekFree"
|
|
682
682
|
: baseProductIdentifier;
|
|
683
683
|
|
|
684
684
|
const fetchProducts = async () => {
|
|
@@ -689,7 +689,7 @@ const NativeIAPPurchaseView = () => {
|
|
|
689
689
|
let productIds = [dynamicProductIdentifier];
|
|
690
690
|
|
|
691
691
|
// Also include base product as fallback
|
|
692
|
-
if (
|
|
692
|
+
if (OfferCode) {
|
|
693
693
|
productIds.push(baseProductIdentifier);
|
|
694
694
|
}
|
|
695
695
|
|
|
@@ -697,7 +697,7 @@ const NativeIAPPurchaseView = () => {
|
|
|
697
697
|
|
|
698
698
|
// Prioritize the dynamic product if it exists
|
|
699
699
|
let sortedProducts = products;
|
|
700
|
-
if (
|
|
700
|
+
if (OfferCode && products.length > 1) {
|
|
701
701
|
sortedProducts = products.sort((a, b) =>
|
|
702
702
|
a.productId === dynamicProductIdentifier ? -1 : 1
|
|
703
703
|
);
|
|
@@ -727,7 +727,7 @@ const NativeIAPPurchaseView = () => {
|
|
|
727
727
|
if (connected) {
|
|
728
728
|
fetchProducts();
|
|
729
729
|
}
|
|
730
|
-
}, [connected,
|
|
730
|
+
}, [connected, OfferCode]);;
|
|
731
731
|
|
|
732
732
|
const primaryProduct = availableProducts[0];
|
|
733
733
|
|
|
@@ -737,10 +737,10 @@ const NativeIAPPurchaseView = () => {
|
|
|
737
737
|
Premium Subscription
|
|
738
738
|
</Text>
|
|
739
739
|
|
|
740
|
-
{
|
|
740
|
+
{OfferCode && (
|
|
741
741
|
<View style={{ backgroundColor: '#e3f2fd', padding: 10, marginBottom: 15, borderRadius: 8 }}>
|
|
742
742
|
<Text style={{ color: '#1976d2', fontWeight: 'bold' }}>
|
|
743
|
-
🎉 Special Offer Applied: {
|
|
743
|
+
🎉 Special Offer Applied: {OfferCode}
|
|
744
744
|
</Text>
|
|
745
745
|
</View>
|
|
746
746
|
)}
|
|
@@ -765,7 +765,7 @@ const NativeIAPPurchaseView = () => {
|
|
|
765
765
|
disabled={loading}
|
|
766
766
|
/>
|
|
767
767
|
|
|
768
|
-
{primaryProduct.productId === dynamicProductIdentifier &&
|
|
768
|
+
{primaryProduct.productId === dynamicProductIdentifier && OfferCode && (
|
|
769
769
|
<Text style={{ fontSize: 12, color: '#4caf50', marginTop: 10 }}>
|
|
770
770
|
✓ Promotional pricing applied
|
|
771
771
|
</Text>
|
|
@@ -15,7 +15,7 @@ type CustomPurchase = {
|
|
|
15
15
|
type T_DEEPLINK_IAP_CONTEXT = {
|
|
16
16
|
referrerLink: string;
|
|
17
17
|
userId: string;
|
|
18
|
-
|
|
18
|
+
OfferCode: string | null;
|
|
19
19
|
returnInsertAffiliateIdentifier: () => Promise<string | null>;
|
|
20
20
|
validatePurchaseWithIapticAPI: (
|
|
21
21
|
jsonIapPurchase: CustomPurchase,
|
|
@@ -65,7 +65,7 @@ const ASYNC_KEYS = {
|
|
|
65
65
|
export const DeepLinkIapContext = createContext<T_DEEPLINK_IAP_CONTEXT>({
|
|
66
66
|
referrerLink: '',
|
|
67
67
|
userId: '',
|
|
68
|
-
|
|
68
|
+
OfferCode: null,
|
|
69
69
|
returnInsertAffiliateIdentifier: async () => '',
|
|
70
70
|
validatePurchaseWithIapticAPI: async (
|
|
71
71
|
jsonIapPurchase: CustomPurchase,
|
|
@@ -90,7 +90,7 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
|
|
|
90
90
|
const [companyCode, setCompanyCode] = useState<string | null>(null);
|
|
91
91
|
const [isInitialized, setIsInitialized] = useState<boolean>(false);
|
|
92
92
|
const [verboseLogging, setVerboseLogging] = useState<boolean>(false);
|
|
93
|
-
const [
|
|
93
|
+
const [OfferCode, setOfferCode] = useState<string | null>(null);
|
|
94
94
|
|
|
95
95
|
// MARK: Initialize the SDK
|
|
96
96
|
const initialize = async (companyCode: string | null, verboseLogging: boolean = false): Promise<void> => {
|
|
@@ -138,12 +138,12 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
|
|
|
138
138
|
const uId = await getValueFromAsync(ASYNC_KEYS.USER_ID);
|
|
139
139
|
const refLink = await getValueFromAsync(ASYNC_KEYS.REFERRER_LINK);
|
|
140
140
|
const companyCodeFromStorage = await getValueFromAsync(ASYNC_KEYS.COMPANY_CODE);
|
|
141
|
-
const
|
|
141
|
+
const storedOfferCode = await getValueFromAsync(ASYNC_KEYS.IOS_OFFER_CODE);
|
|
142
142
|
|
|
143
143
|
verboseLog(`User ID found: ${uId ? 'Yes' : 'No'}`);
|
|
144
144
|
verboseLog(`Referrer link found: ${refLink ? 'Yes' : 'No'}`);
|
|
145
145
|
verboseLog(`Company code found: ${companyCodeFromStorage ? 'Yes' : 'No'}`);
|
|
146
|
-
verboseLog(`iOS Offer Code found: ${
|
|
146
|
+
verboseLog(`iOS Offer Code found: ${storedOfferCode ? 'Yes' : 'No'}`);
|
|
147
147
|
|
|
148
148
|
if (uId && refLink) {
|
|
149
149
|
setUserId(uId);
|
|
@@ -156,8 +156,8 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
|
|
|
156
156
|
verboseLog('Company code restored from storage');
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
if (
|
|
160
|
-
|
|
159
|
+
if (storedOfferCode) {
|
|
160
|
+
setOfferCode(storedOfferCode);
|
|
161
161
|
verboseLog('iOS Offer Code restored from storage');
|
|
162
162
|
}
|
|
163
163
|
} catch (error) {
|
|
@@ -707,14 +707,14 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
|
|
|
707
707
|
if (offerCode && offerCode.length > 0) {
|
|
708
708
|
// Store in both AsyncStorage and state
|
|
709
709
|
await saveValueInAsync(ASYNC_KEYS.IOS_OFFER_CODE, offerCode);
|
|
710
|
-
|
|
710
|
+
setOfferCode(offerCode);
|
|
711
711
|
verboseLog(`Successfully stored offer code: ${offerCode}`);
|
|
712
712
|
console.log('[Insert Affiliate] Offer code retrieved and stored successfully');
|
|
713
713
|
} else {
|
|
714
714
|
verboseLog('No valid offer code found to store');
|
|
715
715
|
// Clear stored offer code if none found
|
|
716
716
|
await saveValueInAsync(ASYNC_KEYS.IOS_OFFER_CODE, '');
|
|
717
|
-
|
|
717
|
+
setOfferCode(null);
|
|
718
718
|
}
|
|
719
719
|
} catch (error) {
|
|
720
720
|
console.error('[Insert Affiliate] Error retrieving and storing offer code:', error);
|
|
@@ -737,7 +737,7 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
|
|
|
737
737
|
value={{
|
|
738
738
|
referrerLink,
|
|
739
739
|
userId,
|
|
740
|
-
|
|
740
|
+
OfferCode,
|
|
741
741
|
setShortCode,
|
|
742
742
|
returnInsertAffiliateIdentifier,
|
|
743
743
|
storeExpectedStoreTransaction,
|
|
@@ -14,7 +14,7 @@ const useDeepLinkIapProvider = () => {
|
|
|
14
14
|
setInsertAffiliateIdentifier,
|
|
15
15
|
initialize,
|
|
16
16
|
isInitialized,
|
|
17
|
-
|
|
17
|
+
OfferCode,
|
|
18
18
|
} = useContext(DeepLinkIapContext);
|
|
19
19
|
|
|
20
20
|
return {
|
|
@@ -29,7 +29,7 @@ const useDeepLinkIapProvider = () => {
|
|
|
29
29
|
setInsertAffiliateIdentifier,
|
|
30
30
|
initialize,
|
|
31
31
|
isInitialized,
|
|
32
|
-
|
|
32
|
+
OfferCode,
|
|
33
33
|
};
|
|
34
34
|
};
|
|
35
35
|
|