react-native-iap 8.5.3 → 8.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/README.md +4 -20
- package/RNIap.podspec +33 -18
- package/android/build.gradle +137 -38
- package/android/gradle.properties +8 -0
- package/ios/RNIapIos-Bridging-Header.h +2 -0
- package/ios/RNIapIos.m +13 -0
- package/ios/RNIapIos.swift +84 -36
- package/ios/{RNIap.xcodeproj → RNIapIos.xcodeproj}/project.pbxproj +29 -116
- package/lib/commonjs/__test__/iap.test.js +21 -0
- package/lib/commonjs/__test__/iap.test.js.map +1 -0
- package/lib/commonjs/hooks/useIAP.js +78 -0
- package/lib/commonjs/hooks/useIAP.js.map +1 -0
- package/lib/commonjs/hooks/withIAPContext.js +92 -0
- package/lib/commonjs/hooks/withIAPContext.js.map +1 -0
- package/lib/commonjs/iap.js +577 -0
- package/lib/commonjs/iap.js.map +1 -0
- package/lib/commonjs/index.js +59 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/types/amazon.js +2 -0
- package/lib/commonjs/types/amazon.js.map +1 -0
- package/lib/commonjs/types/android.js +55 -0
- package/lib/commonjs/types/android.js.map +1 -0
- package/lib/commonjs/types/apple.js +165 -0
- package/lib/commonjs/types/apple.js.map +1 -0
- package/lib/commonjs/types/index.js +59 -0
- package/lib/commonjs/types/index.js.map +1 -0
- package/lib/module/__test__/iap.test.js +17 -0
- package/lib/module/__test__/iap.test.js.map +1 -0
- package/lib/module/hooks/useIAP.js +68 -0
- package/lib/module/hooks/useIAP.js.map +1 -0
- package/lib/module/hooks/withIAPContext.js +76 -0
- package/lib/module/hooks/withIAPContext.js.map +1 -0
- package/lib/module/iap.js +488 -0
- package/lib/module/iap.js.map +1 -0
- package/lib/module/index.js +6 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/types/amazon.js +2 -0
- package/lib/module/types/amazon.js.map +1 -0
- package/lib/module/types/android.js +44 -0
- package/lib/module/types/android.js.map +1 -0
- package/lib/module/types/apple.js +153 -0
- package/lib/module/types/apple.js.map +1 -0
- package/lib/module/types/index.js +48 -0
- package/lib/module/types/index.js.map +1 -0
- package/lib/typescript/__test__/iap.test.d.ts +1 -0
- package/lib/typescript/hooks/useIAP.d.ts +22 -0
- package/lib/typescript/hooks/withIAPContext.d.ts +22 -0
- package/lib/typescript/iap.d.ts +195 -0
- package/lib/typescript/index.d.ts +5 -0
- package/lib/typescript/types/amazon.d.ts +23 -0
- package/lib/typescript/types/android.d.ts +47 -0
- package/lib/typescript/types/apple.d.ts +424 -0
- package/lib/typescript/types/index.d.ts +146 -0
- package/package.json +80 -47
- package/src/__test__/iap.test.ts +20 -0
- package/src/hooks/useIAP.ts +130 -0
- package/src/hooks/withIAPContext.tsx +160 -0
- package/src/iap.ts +686 -0
- package/src/index.ts +7 -0
- package/src/types/amazon.ts +23 -0
- package/src/types/android.ts +51 -0
- package/src/types/apple.ts +467 -0
- package/src/types/index.ts +185 -0
- package/.editorconfig +0 -10
- package/.flowconfig +0 -11
- package/.monolinterrc +0 -3
- package/.prettierignore +0 -6
- package/.swiftlint.yml +0 -11
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +0 -6
- package/android/gradlew +0 -160
- package/android/gradlew.bat +0 -90
- package/babel.config.js +0 -12
- package/index.ts +0 -5
- package/ios/RNIap.xcodeproj/xcshareddata/xcschemes/RNIap.xcscheme +0 -80
- package/jest.config.js +0 -190
- package/test/mocks/react-native-modules.js +0 -14
|
@@ -7,20 +7,11 @@
|
|
|
7
7
|
objects = {
|
|
8
8
|
|
|
9
9
|
/* Begin PBXBuildFile section */
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
5E555C0D2413F4C50049A1A2 /* RNIapIos.m in Sources */ = {isa = PBXBuildFile; fileRef = B3E7B5891CC2AC0600A0062D /* RNIapIos.m */; };
|
|
11
|
+
F4FF95D7245B92E800C19C63 /* RNIapIos.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FF95D6245B92E800C19C63 /* RNIapIos.swift */; };
|
|
12
12
|
/* End PBXBuildFile section */
|
|
13
13
|
|
|
14
14
|
/* Begin PBXCopyFilesBuildPhase section */
|
|
15
|
-
0707446C2296C0EF00B1DC9D /* CopyFiles */ = {
|
|
16
|
-
isa = PBXCopyFilesBuildPhase;
|
|
17
|
-
buildActionMask = 2147483647;
|
|
18
|
-
dstPath = "include/$(PRODUCT_NAME)";
|
|
19
|
-
dstSubfolderSpec = 16;
|
|
20
|
-
files = (
|
|
21
|
-
);
|
|
22
|
-
runOnlyForDeploymentPostprocessing = 0;
|
|
23
|
-
};
|
|
24
15
|
58B511D91A9E6C8500147676 /* CopyFiles */ = {
|
|
25
16
|
isa = PBXCopyFilesBuildPhase;
|
|
26
17
|
buildActionMask = 2147483647;
|
|
@@ -33,20 +24,13 @@
|
|
|
33
24
|
/* End PBXCopyFilesBuildPhase section */
|
|
34
25
|
|
|
35
26
|
/* Begin PBXFileReference section */
|
|
36
|
-
|
|
37
|
-
134814201AA4EA6300B7C361 /* libRNIap.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNIap.a; sourceTree = BUILT_PRODUCTS_DIR; };
|
|
38
|
-
B3E7B5881CC2AC0600A0062D /* RNIapIos.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNIapIos.h; sourceTree = "<group>"; };
|
|
27
|
+
134814201AA4EA6300B7C361 /* libRNIapIos.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNIapIos.a; sourceTree = BUILT_PRODUCTS_DIR; };
|
|
39
28
|
B3E7B5891CC2AC0600A0062D /* RNIapIos.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNIapIos.m; sourceTree = "<group>"; };
|
|
29
|
+
F4FF95D5245B92E700C19C63 /* RNIapIosIap-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RNIapIosIap-Bridging-Header.h"; sourceTree = "<group>"; };
|
|
30
|
+
F4FF95D6245B92E800C19C63 /* RNIapIos.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RNIapIos.swift; sourceTree = "<group>"; };
|
|
40
31
|
/* End PBXFileReference section */
|
|
41
32
|
|
|
42
33
|
/* Begin PBXFrameworksBuildPhase section */
|
|
43
|
-
0707446B2296C0EF00B1DC9D /* Frameworks */ = {
|
|
44
|
-
isa = PBXFrameworksBuildPhase;
|
|
45
|
-
buildActionMask = 2147483647;
|
|
46
|
-
files = (
|
|
47
|
-
);
|
|
48
|
-
runOnlyForDeploymentPostprocessing = 0;
|
|
49
|
-
};
|
|
50
34
|
58B511D81A9E6C8500147676 /* Frameworks */ = {
|
|
51
35
|
isa = PBXFrameworksBuildPhase;
|
|
52
36
|
buildActionMask = 2147483647;
|
|
@@ -60,7 +44,7 @@
|
|
|
60
44
|
134814211AA4EA7D00B7C361 /* Products */ = {
|
|
61
45
|
isa = PBXGroup;
|
|
62
46
|
children = (
|
|
63
|
-
134814201AA4EA6300B7C361 /*
|
|
47
|
+
134814201AA4EA6300B7C361 /* libRNIapIos.a */,
|
|
64
48
|
);
|
|
65
49
|
name = Products;
|
|
66
50
|
sourceTree = "<group>";
|
|
@@ -68,36 +52,19 @@
|
|
|
68
52
|
58B511D21A9E6C8500147676 = {
|
|
69
53
|
isa = PBXGroup;
|
|
70
54
|
children = (
|
|
71
|
-
|
|
55
|
+
F4FF95D6245B92E800C19C63 /* RNIapIos.swift */,
|
|
72
56
|
B3E7B5891CC2AC0600A0062D /* RNIapIos.m */,
|
|
57
|
+
F4FF95D5245B92E700C19C63 /* RNIapIosIap-Bridging-Header.h */,
|
|
73
58
|
134814211AA4EA7D00B7C361 /* Products */,
|
|
74
|
-
070744702296C0EF00B1DC9D /* libRNIap.a */,
|
|
75
59
|
);
|
|
76
60
|
sourceTree = "<group>";
|
|
77
61
|
};
|
|
78
62
|
/* End PBXGroup section */
|
|
79
63
|
|
|
80
64
|
/* Begin PBXNativeTarget section */
|
|
81
|
-
|
|
82
|
-
isa = PBXNativeTarget;
|
|
83
|
-
buildConfigurationList = 0707446D2296C0EF00B1DC9D /* Build configuration list for PBXNativeTarget "RNIap-tvOS" */;
|
|
84
|
-
buildPhases = (
|
|
85
|
-
070744682296C0EF00B1DC9D /* Sources */,
|
|
86
|
-
0707446B2296C0EF00B1DC9D /* Frameworks */,
|
|
87
|
-
0707446C2296C0EF00B1DC9D /* CopyFiles */,
|
|
88
|
-
);
|
|
89
|
-
buildRules = (
|
|
90
|
-
);
|
|
91
|
-
dependencies = (
|
|
92
|
-
);
|
|
93
|
-
name = "RNIap-tvOS";
|
|
94
|
-
productName = RCTDataManager;
|
|
95
|
-
productReference = 070744702296C0EF00B1DC9D /* libRNIap.a */;
|
|
96
|
-
productType = "com.apple.product-type.library.static";
|
|
97
|
-
};
|
|
98
|
-
58B511DA1A9E6C8500147676 /* RNIap */ = {
|
|
65
|
+
58B511DA1A9E6C8500147676 /* RNIapIos */ = {
|
|
99
66
|
isa = PBXNativeTarget;
|
|
100
|
-
buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "
|
|
67
|
+
buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "RNIapIos" */;
|
|
101
68
|
buildPhases = (
|
|
102
69
|
58B511D71A9E6C8500147676 /* Sources */,
|
|
103
70
|
58B511D81A9E6C8500147676 /* Frameworks */,
|
|
@@ -107,9 +74,9 @@
|
|
|
107
74
|
);
|
|
108
75
|
dependencies = (
|
|
109
76
|
);
|
|
110
|
-
name =
|
|
77
|
+
name = RNIapIos;
|
|
111
78
|
productName = RCTDataManager;
|
|
112
|
-
productReference = 134814201AA4EA6300B7C361 /*
|
|
79
|
+
productReference = 134814201AA4EA6300B7C361 /* libRNIapIos.a */;
|
|
113
80
|
productType = "com.apple.product-type.library.static";
|
|
114
81
|
};
|
|
115
82
|
/* End PBXNativeTarget section */
|
|
@@ -118,7 +85,7 @@
|
|
|
118
85
|
58B511D31A9E6C8500147676 /* Project object */ = {
|
|
119
86
|
isa = PBXProject;
|
|
120
87
|
attributes = {
|
|
121
|
-
LastUpgradeCheck =
|
|
88
|
+
LastUpgradeCheck = 0920;
|
|
122
89
|
ORGANIZATIONNAME = Facebook;
|
|
123
90
|
TargetAttributes = {
|
|
124
91
|
58B511DA1A9E6C8500147676 = {
|
|
@@ -126,7 +93,7 @@
|
|
|
126
93
|
};
|
|
127
94
|
};
|
|
128
95
|
};
|
|
129
|
-
buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "
|
|
96
|
+
buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "RNIapIos" */;
|
|
130
97
|
compatibilityVersion = "Xcode 3.2";
|
|
131
98
|
developmentRegion = English;
|
|
132
99
|
hasScannedForEncodings = 0;
|
|
@@ -139,25 +106,17 @@
|
|
|
139
106
|
projectDirPath = "";
|
|
140
107
|
projectRoot = "";
|
|
141
108
|
targets = (
|
|
142
|
-
58B511DA1A9E6C8500147676 /*
|
|
143
|
-
070744672296C0EF00B1DC9D /* RNIap-tvOS */,
|
|
109
|
+
58B511DA1A9E6C8500147676 /* RNIapIos */,
|
|
144
110
|
);
|
|
145
111
|
};
|
|
146
112
|
/* End PBXProject section */
|
|
147
113
|
|
|
148
114
|
/* Begin PBXSourcesBuildPhase section */
|
|
149
|
-
070744682296C0EF00B1DC9D /* Sources */ = {
|
|
150
|
-
isa = PBXSourcesBuildPhase;
|
|
151
|
-
buildActionMask = 2147483647;
|
|
152
|
-
files = (
|
|
153
|
-
0707446A2296C0EF00B1DC9D /* RNIapIos.m in Sources */,
|
|
154
|
-
);
|
|
155
|
-
runOnlyForDeploymentPostprocessing = 0;
|
|
156
|
-
};
|
|
157
115
|
58B511D71A9E6C8500147676 /* Sources */ = {
|
|
158
116
|
isa = PBXSourcesBuildPhase;
|
|
159
117
|
buildActionMask = 2147483647;
|
|
160
118
|
files = (
|
|
119
|
+
F4FF95D7245B92E800C19C63 /* RNIapIos.swift in Sources */,
|
|
161
120
|
B3E7B58A1CC2AC0600A0062D /* RNIapIos.m in Sources */,
|
|
162
121
|
);
|
|
163
122
|
runOnlyForDeploymentPostprocessing = 0;
|
|
@@ -165,47 +124,10 @@
|
|
|
165
124
|
/* End PBXSourcesBuildPhase section */
|
|
166
125
|
|
|
167
126
|
/* Begin XCBuildConfiguration section */
|
|
168
|
-
0707446E2296C0EF00B1DC9D /* Debug */ = {
|
|
169
|
-
isa = XCBuildConfiguration;
|
|
170
|
-
buildSettings = {
|
|
171
|
-
HEADER_SEARCH_PATHS = (
|
|
172
|
-
"$(inherited)",
|
|
173
|
-
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
|
|
174
|
-
"$(SRCROOT)/../../../React/**",
|
|
175
|
-
"$(SRCROOT)/../../react-native/React/**",
|
|
176
|
-
"${SRCROOT}/../../../ios/Pods/Headers/Public/**",
|
|
177
|
-
);
|
|
178
|
-
LIBRARY_SEARCH_PATHS = "$(inherited)";
|
|
179
|
-
OTHER_LDFLAGS = "-ObjC";
|
|
180
|
-
PRODUCT_NAME = RNIap;
|
|
181
|
-
SDKROOT = appletvos;
|
|
182
|
-
SKIP_INSTALL = YES;
|
|
183
|
-
};
|
|
184
|
-
name = Debug;
|
|
185
|
-
};
|
|
186
|
-
0707446F2296C0EF00B1DC9D /* Release */ = {
|
|
187
|
-
isa = XCBuildConfiguration;
|
|
188
|
-
buildSettings = {
|
|
189
|
-
HEADER_SEARCH_PATHS = (
|
|
190
|
-
"$(inherited)",
|
|
191
|
-
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
|
|
192
|
-
"$(SRCROOT)/../../../React/**",
|
|
193
|
-
"$(SRCROOT)/../../react-native/React/**",
|
|
194
|
-
"${SRCROOT}/../../../ios/Pods/Headers/Public/**",
|
|
195
|
-
);
|
|
196
|
-
LIBRARY_SEARCH_PATHS = "$(inherited)";
|
|
197
|
-
OTHER_LDFLAGS = "-ObjC";
|
|
198
|
-
PRODUCT_NAME = RNIap;
|
|
199
|
-
SDKROOT = appletvos;
|
|
200
|
-
SKIP_INSTALL = YES;
|
|
201
|
-
};
|
|
202
|
-
name = Release;
|
|
203
|
-
};
|
|
204
127
|
58B511ED1A9E6C8500147676 /* Debug */ = {
|
|
205
128
|
isa = XCBuildConfiguration;
|
|
206
129
|
buildSettings = {
|
|
207
130
|
ALWAYS_SEARCH_USER_PATHS = NO;
|
|
208
|
-
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
|
|
209
131
|
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
|
210
132
|
CLANG_CXX_LIBRARY = "libc++";
|
|
211
133
|
CLANG_ENABLE_MODULES = YES;
|
|
@@ -214,14 +136,12 @@
|
|
|
214
136
|
CLANG_WARN_BOOL_CONVERSION = YES;
|
|
215
137
|
CLANG_WARN_COMMA = YES;
|
|
216
138
|
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
|
217
|
-
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
|
|
218
139
|
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
|
219
140
|
CLANG_WARN_EMPTY_BODY = YES;
|
|
220
141
|
CLANG_WARN_ENUM_CONVERSION = YES;
|
|
221
142
|
CLANG_WARN_INFINITE_RECURSION = YES;
|
|
222
143
|
CLANG_WARN_INT_CONVERSION = YES;
|
|
223
144
|
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
|
224
|
-
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
|
|
225
145
|
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
|
226
146
|
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
|
227
147
|
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
|
@@ -232,6 +152,7 @@
|
|
|
232
152
|
COPY_PHASE_STRIP = NO;
|
|
233
153
|
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
|
234
154
|
ENABLE_TESTABILITY = YES;
|
|
155
|
+
"EXCLUDED_ARCHS[sdk=*]" = arm64;
|
|
235
156
|
GCC_C_LANGUAGE_STANDARD = gnu99;
|
|
236
157
|
GCC_DYNAMIC_NO_PIC = NO;
|
|
237
158
|
GCC_NO_COMMON_BLOCKS = YES;
|
|
@@ -247,7 +168,7 @@
|
|
|
247
168
|
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
|
248
169
|
GCC_WARN_UNUSED_FUNCTION = YES;
|
|
249
170
|
GCC_WARN_UNUSED_VARIABLE = YES;
|
|
250
|
-
IPHONEOS_DEPLOYMENT_TARGET =
|
|
171
|
+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
|
251
172
|
MTL_ENABLE_DEBUG_INFO = YES;
|
|
252
173
|
ONLY_ACTIVE_ARCH = YES;
|
|
253
174
|
SDKROOT = iphoneos;
|
|
@@ -258,7 +179,6 @@
|
|
|
258
179
|
isa = XCBuildConfiguration;
|
|
259
180
|
buildSettings = {
|
|
260
181
|
ALWAYS_SEARCH_USER_PATHS = NO;
|
|
261
|
-
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
|
|
262
182
|
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
|
263
183
|
CLANG_CXX_LIBRARY = "libc++";
|
|
264
184
|
CLANG_ENABLE_MODULES = YES;
|
|
@@ -267,14 +187,12 @@
|
|
|
267
187
|
CLANG_WARN_BOOL_CONVERSION = YES;
|
|
268
188
|
CLANG_WARN_COMMA = YES;
|
|
269
189
|
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
|
270
|
-
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
|
|
271
190
|
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
|
272
191
|
CLANG_WARN_EMPTY_BODY = YES;
|
|
273
192
|
CLANG_WARN_ENUM_CONVERSION = YES;
|
|
274
193
|
CLANG_WARN_INFINITE_RECURSION = YES;
|
|
275
194
|
CLANG_WARN_INT_CONVERSION = YES;
|
|
276
195
|
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
|
277
|
-
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
|
|
278
196
|
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
|
279
197
|
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
|
280
198
|
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
|
@@ -285,6 +203,7 @@
|
|
|
285
203
|
COPY_PHASE_STRIP = YES;
|
|
286
204
|
ENABLE_NS_ASSERTIONS = NO;
|
|
287
205
|
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
|
206
|
+
"EXCLUDED_ARCHS[sdk=*]" = arm64;
|
|
288
207
|
GCC_C_LANGUAGE_STANDARD = gnu99;
|
|
289
208
|
GCC_NO_COMMON_BLOCKS = YES;
|
|
290
209
|
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
|
@@ -293,7 +212,7 @@
|
|
|
293
212
|
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
|
294
213
|
GCC_WARN_UNUSED_FUNCTION = YES;
|
|
295
214
|
GCC_WARN_UNUSED_VARIABLE = YES;
|
|
296
|
-
IPHONEOS_DEPLOYMENT_TARGET =
|
|
215
|
+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
|
297
216
|
MTL_ENABLE_DEBUG_INFO = NO;
|
|
298
217
|
SDKROOT = iphoneos;
|
|
299
218
|
VALIDATE_PRODUCT = YES;
|
|
@@ -308,12 +227,14 @@
|
|
|
308
227
|
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
|
|
309
228
|
"$(SRCROOT)/../../../React/**",
|
|
310
229
|
"$(SRCROOT)/../../react-native/React/**",
|
|
311
|
-
"${SRCROOT}/../../../ios/Pods/Headers/Public/**",
|
|
312
230
|
);
|
|
313
231
|
LIBRARY_SEARCH_PATHS = "$(inherited)";
|
|
314
232
|
OTHER_LDFLAGS = "-ObjC";
|
|
315
|
-
PRODUCT_NAME =
|
|
233
|
+
PRODUCT_NAME = RNIapIos;
|
|
316
234
|
SKIP_INSTALL = YES;
|
|
235
|
+
SWIFT_OBJC_BRIDGING_HEADER = "RNIapIosIap-Bridging-Header.h";
|
|
236
|
+
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
|
237
|
+
SWIFT_VERSION = 5.0;
|
|
317
238
|
};
|
|
318
239
|
name = Debug;
|
|
319
240
|
};
|
|
@@ -325,28 +246,20 @@
|
|
|
325
246
|
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
|
|
326
247
|
"$(SRCROOT)/../../../React/**",
|
|
327
248
|
"$(SRCROOT)/../../react-native/React/**",
|
|
328
|
-
"${SRCROOT}/../../../ios/Pods/Headers/Public/**",
|
|
329
249
|
);
|
|
330
250
|
LIBRARY_SEARCH_PATHS = "$(inherited)";
|
|
331
251
|
OTHER_LDFLAGS = "-ObjC";
|
|
332
|
-
PRODUCT_NAME =
|
|
252
|
+
PRODUCT_NAME = RNIapIos;
|
|
333
253
|
SKIP_INSTALL = YES;
|
|
254
|
+
SWIFT_OBJC_BRIDGING_HEADER = "RNIapIosIap-Bridging-Header.h";
|
|
255
|
+
SWIFT_VERSION = 5.0;
|
|
334
256
|
};
|
|
335
257
|
name = Release;
|
|
336
258
|
};
|
|
337
259
|
/* End XCBuildConfiguration section */
|
|
338
260
|
|
|
339
261
|
/* Begin XCConfigurationList section */
|
|
340
|
-
|
|
341
|
-
isa = XCConfigurationList;
|
|
342
|
-
buildConfigurations = (
|
|
343
|
-
0707446E2296C0EF00B1DC9D /* Debug */,
|
|
344
|
-
0707446F2296C0EF00B1DC9D /* Release */,
|
|
345
|
-
);
|
|
346
|
-
defaultConfigurationIsVisible = 0;
|
|
347
|
-
defaultConfigurationName = Release;
|
|
348
|
-
};
|
|
349
|
-
58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "RNIap" */ = {
|
|
262
|
+
58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "RNIapIos" */ = {
|
|
350
263
|
isa = XCConfigurationList;
|
|
351
264
|
buildConfigurations = (
|
|
352
265
|
58B511ED1A9E6C8500147676 /* Debug */,
|
|
@@ -355,7 +268,7 @@
|
|
|
355
268
|
defaultConfigurationIsVisible = 0;
|
|
356
269
|
defaultConfigurationName = Release;
|
|
357
270
|
};
|
|
358
|
-
58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "
|
|
271
|
+
58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "RNIapIos" */ = {
|
|
359
272
|
isa = XCConfigurationList;
|
|
360
273
|
buildConfigurations = (
|
|
361
274
|
58B511F01A9E6C8500147676 /* Debug */,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _reactNative = require("react-native");
|
|
4
|
+
|
|
5
|
+
var _iap = require("../iap");
|
|
6
|
+
|
|
7
|
+
const rnLib = '../../node_modules/react-native/Libraries';
|
|
8
|
+
describe('Google Play IAP', () => {
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
jest.mock(rnLib + '/Utilities/Platform', () => ({
|
|
11
|
+
OS: 'android',
|
|
12
|
+
select: dict => dict.android
|
|
13
|
+
}));
|
|
14
|
+
});
|
|
15
|
+
it("should call init on Google Play's native module but not on Amazon's", async () => {
|
|
16
|
+
await (0, _iap.initConnection)();
|
|
17
|
+
expect(_reactNative.NativeModules.RNIapModule.initConnection).toBeCalled();
|
|
18
|
+
expect(_reactNative.NativeModules.RNIapAmazonModule.initConnection).not.toBeCalled();
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
//# sourceMappingURL=iap.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["rnLib","describe","beforeEach","jest","mock","OS","select","dict","android","it","initConnection","expect","NativeModules","RNIapModule","toBeCalled","RNIapAmazonModule","not"],"sources":["iap.test.ts"],"sourcesContent":["import {NativeModules} from 'react-native';\n\nimport {initConnection} from '../iap';\n\nconst rnLib = '../../node_modules/react-native/Libraries';\n\ndescribe('Google Play IAP', () => {\n beforeEach(() => {\n jest.mock(rnLib + '/Utilities/Platform', () => ({\n OS: 'android',\n select: (dict: {[x: string]: any}) => dict.android,\n }));\n });\n\n it(\"should call init on Google Play's native module but not on Amazon's\", async () => {\n await initConnection();\n expect(NativeModules.RNIapModule.initConnection).toBeCalled();\n expect(NativeModules.RNIapAmazonModule.initConnection).not.toBeCalled();\n });\n});\n"],"mappings":";;AAAA;;AAEA;;AAEA,MAAMA,KAAK,GAAG,2CAAd;AAEAC,QAAQ,CAAC,iBAAD,EAAoB,MAAM;EAChCC,UAAU,CAAC,MAAM;IACfC,IAAI,CAACC,IAAL,CAAUJ,KAAK,GAAG,qBAAlB,EAAyC,OAAO;MAC9CK,EAAE,EAAE,SAD0C;MAE9CC,MAAM,EAAGC,IAAD,IAA8BA,IAAI,CAACC;IAFG,CAAP,CAAzC;EAID,CALS,CAAV;EAOAC,EAAE,CAAC,qEAAD,EAAwE,YAAY;IACpF,MAAM,IAAAC,mBAAA,GAAN;IACAC,MAAM,CAACC,0BAAA,CAAcC,WAAd,CAA0BH,cAA3B,CAAN,CAAiDI,UAAjD;IACAH,MAAM,CAACC,0BAAA,CAAcG,iBAAd,CAAgCL,cAAjC,CAAN,CAAuDM,GAAvD,CAA2DF,UAA3D;EACD,CAJC,CAAF;AAKD,CAbO,CAAR"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useIAP = useIAP;
|
|
7
|
+
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
|
|
10
|
+
var _iap = require("../iap");
|
|
11
|
+
|
|
12
|
+
var _withIAPContext = require("./withIAPContext");
|
|
13
|
+
|
|
14
|
+
function useIAP() {
|
|
15
|
+
const {
|
|
16
|
+
connected,
|
|
17
|
+
products,
|
|
18
|
+
promotedProductsIOS,
|
|
19
|
+
subscriptions,
|
|
20
|
+
purchaseHistories,
|
|
21
|
+
availablePurchases,
|
|
22
|
+
currentPurchase,
|
|
23
|
+
currentPurchaseError,
|
|
24
|
+
initConnectionError,
|
|
25
|
+
setProducts,
|
|
26
|
+
setSubscriptions,
|
|
27
|
+
setAvailablePurchases,
|
|
28
|
+
setPurchaseHistories,
|
|
29
|
+
setCurrentPurchase,
|
|
30
|
+
setCurrentPurchaseError
|
|
31
|
+
} = (0, _withIAPContext.useIAPContext)();
|
|
32
|
+
const getProducts = (0, _react.useCallback)(async skus => {
|
|
33
|
+
setProducts(await (0, _iap.getProducts)(skus));
|
|
34
|
+
}, [setProducts]);
|
|
35
|
+
const getSubscriptions = (0, _react.useCallback)(async skus => {
|
|
36
|
+
setSubscriptions(await (0, _iap.getSubscriptions)(skus));
|
|
37
|
+
}, [setSubscriptions]);
|
|
38
|
+
const getAvailablePurchases = (0, _react.useCallback)(async () => {
|
|
39
|
+
setAvailablePurchases(await (0, _iap.getAvailablePurchases)());
|
|
40
|
+
}, [setAvailablePurchases]);
|
|
41
|
+
const getPurchaseHistories = (0, _react.useCallback)(async () => {
|
|
42
|
+
setPurchaseHistories(await (0, _iap.getPurchaseHistory)());
|
|
43
|
+
}, [setPurchaseHistories]);
|
|
44
|
+
const finishTransaction = (0, _react.useCallback)(async (purchase, isConsumable, developerPayloadAndroid) => {
|
|
45
|
+
try {
|
|
46
|
+
return await (0, _iap.finishTransaction)(purchase, isConsumable, developerPayloadAndroid);
|
|
47
|
+
} catch (err) {
|
|
48
|
+
throw err;
|
|
49
|
+
} finally {
|
|
50
|
+
if (purchase.productId === (currentPurchase === null || currentPurchase === void 0 ? void 0 : currentPurchase.productId)) {
|
|
51
|
+
setCurrentPurchase(undefined);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (purchase.productId === (currentPurchaseError === null || currentPurchaseError === void 0 ? void 0 : currentPurchaseError.productId)) {
|
|
55
|
+
setCurrentPurchaseError(undefined);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}, [currentPurchase === null || currentPurchase === void 0 ? void 0 : currentPurchase.productId, currentPurchaseError === null || currentPurchaseError === void 0 ? void 0 : currentPurchaseError.productId, setCurrentPurchase, setCurrentPurchaseError]);
|
|
59
|
+
return {
|
|
60
|
+
connected,
|
|
61
|
+
products,
|
|
62
|
+
promotedProductsIOS,
|
|
63
|
+
subscriptions,
|
|
64
|
+
purchaseHistories,
|
|
65
|
+
availablePurchases,
|
|
66
|
+
currentPurchase,
|
|
67
|
+
currentPurchaseError,
|
|
68
|
+
initConnectionError,
|
|
69
|
+
finishTransaction,
|
|
70
|
+
getProducts,
|
|
71
|
+
getSubscriptions,
|
|
72
|
+
getAvailablePurchases,
|
|
73
|
+
getPurchaseHistories,
|
|
74
|
+
requestPurchase: _iap.requestPurchase,
|
|
75
|
+
requestSubscription: _iap.requestSubscription
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=useIAP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useIAP","connected","products","promotedProductsIOS","subscriptions","purchaseHistories","availablePurchases","currentPurchase","currentPurchaseError","initConnectionError","setProducts","setSubscriptions","setAvailablePurchases","setPurchaseHistories","setCurrentPurchase","setCurrentPurchaseError","useIAPContext","getProducts","useCallback","skus","iapGetProducts","getSubscriptions","iapGetSubscriptions","getAvailablePurchases","iapGetAvailablePurchases","getPurchaseHistories","getPurchaseHistory","finishTransaction","purchase","isConsumable","developerPayloadAndroid","iapFinishTransaction","err","productId","undefined","requestPurchase","iapRequestPurchase","requestSubscription","iapRequestSubscription"],"sources":["useIAP.ts"],"sourcesContent":["import {useCallback} from 'react';\n\nimport {\n finishTransaction as iapFinishTransaction,\n getAvailablePurchases as iapGetAvailablePurchases,\n getProducts as iapGetProducts,\n getPurchaseHistory,\n getSubscriptions as iapGetSubscriptions,\n requestPurchase as iapRequestPurchase,\n requestSubscription as iapRequestSubscription,\n} from '../iap';\nimport type {Product, Purchase, PurchaseError, Subscription} from '../types';\n\nimport {useIAPContext} from './withIAPContext';\n\ntype IAP_STATUS = {\n connected: boolean;\n products: Product[];\n promotedProductsIOS: Product[];\n subscriptions: Subscription[];\n purchaseHistories: Purchase[];\n availablePurchases: Purchase[];\n currentPurchase?: Purchase;\n currentPurchaseError?: PurchaseError;\n initConnectionError?: Error;\n finishTransaction: (\n purchase: Purchase,\n isConsumable?: boolean,\n developerPayloadAndroid?: string,\n ) => Promise<string | void>;\n getAvailablePurchases: () => Promise<void>;\n getPurchaseHistories: () => Promise<void>;\n getProducts: (skus: string[]) => Promise<void>;\n getSubscriptions: (skus: string[]) => Promise<void>;\n requestPurchase: typeof iapRequestPurchase;\n requestSubscription: typeof iapRequestSubscription;\n};\n\nexport function useIAP(): IAP_STATUS {\n const {\n connected,\n products,\n promotedProductsIOS,\n subscriptions,\n purchaseHistories,\n availablePurchases,\n currentPurchase,\n currentPurchaseError,\n initConnectionError,\n setProducts,\n setSubscriptions,\n setAvailablePurchases,\n setPurchaseHistories,\n setCurrentPurchase,\n setCurrentPurchaseError,\n } = useIAPContext();\n\n const getProducts = useCallback(\n async (skus: string[]): Promise<void> => {\n setProducts(await iapGetProducts(skus));\n },\n [setProducts],\n );\n\n const getSubscriptions = useCallback(\n async (skus: string[]): Promise<void> => {\n setSubscriptions(await iapGetSubscriptions(skus));\n },\n [setSubscriptions],\n );\n\n const getAvailablePurchases = useCallback(async (): Promise<void> => {\n setAvailablePurchases(await iapGetAvailablePurchases());\n }, [setAvailablePurchases]);\n\n const getPurchaseHistories = useCallback(async (): Promise<void> => {\n setPurchaseHistories(await getPurchaseHistory());\n }, [setPurchaseHistories]);\n\n const finishTransaction = useCallback(\n async (\n purchase: Purchase,\n isConsumable?: boolean,\n developerPayloadAndroid?: string,\n ): Promise<string | void> => {\n try {\n return await iapFinishTransaction(\n purchase,\n isConsumable,\n developerPayloadAndroid,\n );\n } catch (err) {\n throw err;\n } finally {\n if (purchase.productId === currentPurchase?.productId) {\n setCurrentPurchase(undefined);\n }\n\n if (purchase.productId === currentPurchaseError?.productId) {\n setCurrentPurchaseError(undefined);\n }\n }\n },\n [\n currentPurchase?.productId,\n currentPurchaseError?.productId,\n setCurrentPurchase,\n setCurrentPurchaseError,\n ],\n );\n\n return {\n connected,\n products,\n promotedProductsIOS,\n subscriptions,\n purchaseHistories,\n availablePurchases,\n currentPurchase,\n currentPurchaseError,\n initConnectionError,\n finishTransaction,\n getProducts,\n getSubscriptions,\n getAvailablePurchases,\n getPurchaseHistories,\n requestPurchase: iapRequestPurchase,\n requestSubscription: iapRequestSubscription,\n };\n}\n"],"mappings":";;;;;;;AAAA;;AAEA;;AAWA;;AAyBO,SAASA,MAAT,GAA8B;EACnC,MAAM;IACJC,SADI;IAEJC,QAFI;IAGJC,mBAHI;IAIJC,aAJI;IAKJC,iBALI;IAMJC,kBANI;IAOJC,eAPI;IAQJC,oBARI;IASJC,mBATI;IAUJC,WAVI;IAWJC,gBAXI;IAYJC,qBAZI;IAaJC,oBAbI;IAcJC,kBAdI;IAeJC;EAfI,IAgBF,IAAAC,6BAAA,GAhBJ;EAkBA,MAAMC,WAAW,GAAG,IAAAC,kBAAA,EAClB,MAAOC,IAAP,IAAyC;IACvCT,WAAW,CAAC,MAAM,IAAAU,gBAAA,EAAeD,IAAf,CAAP,CAAX;EACD,CAHiB,EAIlB,CAACT,WAAD,CAJkB,CAApB;EAOA,MAAMW,gBAAgB,GAAG,IAAAH,kBAAA,EACvB,MAAOC,IAAP,IAAyC;IACvCR,gBAAgB,CAAC,MAAM,IAAAW,qBAAA,EAAo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PK;IAQLC,oBARK;IASLC,mBATK;IAULkB,iBAVK;IAWLV,WAXK;IAYLI,gBAZK;IAaLE,qBAbK;IAcLE,oBAdK;IAeLU,eAAe,EAAEC,oBAfZ;IAgBLC,mBAAmB,EAAEC;EAhBhB,CAAP;AAkBD"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useIAPContext = useIAPContext;
|
|
7
|
+
exports.withIAPContext = withIAPContext;
|
|
8
|
+
|
|
9
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
+
|
|
11
|
+
var _iap = require("../iap");
|
|
12
|
+
|
|
13
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
14
|
+
|
|
15
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
16
|
+
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
const IAPContext = /*#__PURE__*/_react.default.createContext(null);
|
|
19
|
+
|
|
20
|
+
function useIAPContext() {
|
|
21
|
+
const ctx = (0, _react.useContext)(IAPContext);
|
|
22
|
+
|
|
23
|
+
if (!ctx) {
|
|
24
|
+
throw new Error('You need wrap your app with withIAPContext HOC');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return ctx;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function withIAPContext(Component) {
|
|
31
|
+
return function WrapperComponent(props) {
|
|
32
|
+
const [connected, setConnected] = (0, _react.useState)(false);
|
|
33
|
+
const [products, setProducts] = (0, _react.useState)([]);
|
|
34
|
+
const [promotedProductsIOS, setPromotedProductsIOS] = (0, _react.useState)([]);
|
|
35
|
+
const [subscriptions, setSubscriptions] = (0, _react.useState)([]);
|
|
36
|
+
const [purchaseHistories, setPurchaseHistories] = (0, _react.useState)([]);
|
|
37
|
+
const [availablePurchases, setAvailablePurchases] = (0, _react.useState)([]);
|
|
38
|
+
const [currentPurchase, setCurrentPurchase] = (0, _react.useState)();
|
|
39
|
+
const [currentPurchaseError, setCurrentPurchaseError] = (0, _react.useState)();
|
|
40
|
+
const [initConnectionError, setInitConnectionError] = (0, _react.useState)();
|
|
41
|
+
const context = (0, _react.useMemo)(() => ({
|
|
42
|
+
connected,
|
|
43
|
+
products,
|
|
44
|
+
subscriptions,
|
|
45
|
+
promotedProductsIOS,
|
|
46
|
+
purchaseHistories,
|
|
47
|
+
availablePurchases,
|
|
48
|
+
currentPurchase,
|
|
49
|
+
currentPurchaseError,
|
|
50
|
+
initConnectionError,
|
|
51
|
+
setProducts,
|
|
52
|
+
setSubscriptions,
|
|
53
|
+
setPurchaseHistories,
|
|
54
|
+
setAvailablePurchases,
|
|
55
|
+
setCurrentPurchase,
|
|
56
|
+
setCurrentPurchaseError
|
|
57
|
+
}), [connected, products, subscriptions, promotedProductsIOS, purchaseHistories, availablePurchases, currentPurchase, currentPurchaseError, initConnectionError, setProducts, setSubscriptions, setPurchaseHistories, setAvailablePurchases, setCurrentPurchase, setCurrentPurchaseError]);
|
|
58
|
+
(0, _react.useEffect)(() => {
|
|
59
|
+
(0, _iap.initConnection)().then(value => {
|
|
60
|
+
setInitConnectionError(undefined);
|
|
61
|
+
setConnected(value);
|
|
62
|
+
}).catch(setInitConnectionError);
|
|
63
|
+
}, []);
|
|
64
|
+
(0, _react.useEffect)(() => {
|
|
65
|
+
if (!connected) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const purchaseUpdateSubscription = (0, _iap.purchaseUpdatedListener)(async purchase => {
|
|
70
|
+
setCurrentPurchaseError(undefined);
|
|
71
|
+
setCurrentPurchase(purchase);
|
|
72
|
+
});
|
|
73
|
+
const purchaseErrorSubscription = (0, _iap.purchaseErrorListener)(error => {
|
|
74
|
+
setCurrentPurchase(undefined);
|
|
75
|
+
setCurrentPurchaseError(error);
|
|
76
|
+
});
|
|
77
|
+
const promotedProductSubscription = (0, _iap.promotedProductListener)(async () => {
|
|
78
|
+
const product = await (0, _iap.getPromotedProductIOS)();
|
|
79
|
+
setPromotedProductsIOS(prevProducts => [...prevProducts, ...(product ? [product] : [])]);
|
|
80
|
+
});
|
|
81
|
+
return () => {
|
|
82
|
+
purchaseUpdateSubscription.remove();
|
|
83
|
+
purchaseErrorSubscription.remove();
|
|
84
|
+
promotedProductSubscription.remove();
|
|
85
|
+
};
|
|
86
|
+
}, [connected]);
|
|
87
|
+
return /*#__PURE__*/_react.default.createElement(IAPContext.Provider, {
|
|
88
|
+
value: context
|
|
89
|
+
}, /*#__PURE__*/_react.default.createElement(Component, props));
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=withIAPContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["IAPContext","React","createContext","useIAPContext","ctx","useContext","Error","withIAPContext","Component","WrapperComponent","props","connected","setConnected","useState","products","setProducts","promotedProductsIOS","setPromotedProductsIOS","subscriptions","setSubscriptions","purchaseHistories","setPurchaseHistories","availablePurchases","setAvailablePurchases","currentPurchase","setCurrentPurchase","currentPurchaseError","setCurrentPurchaseError","initConnectionError","setInitConnectionError","context","useMemo","useEffect","initConnection","then","value","undefined","catch","purchaseUpdateSubscription","purchaseUpdatedListener","purchase","purchaseErrorSubscription","purchaseErrorListener","error","promotedProductSubscription","promotedProductListener","product","getPromotedProductIOS","prevProducts","remove"],"sources":["withIAPContext.tsx"],"sourcesContent":["import React, {useContext, useEffect, useMemo, useState} from 'react';\n\nimport {\n getPromotedProductIOS,\n initConnection,\n promotedProductListener,\n purchaseErrorListener,\n purchaseUpdatedListener,\n} from '../iap';\nimport type {\n InAppPurchase,\n Product,\n Purchase,\n PurchaseError,\n Subscription,\n SubscriptionPurchase,\n} from '../types';\n\ntype IAPContextType = {\n connected: boolean;\n products: Product[];\n promotedProductsIOS: Product[];\n subscriptions: Subscription[];\n purchaseHistories: Purchase[];\n availablePurchases: Purchase[];\n currentPurchase?: Purchase;\n currentPurchaseError?: PurchaseError;\n initConnectionError?: Error;\n setProducts: (products: Product[]) => void;\n setSubscriptions: (subscriptions: Subscription[]) => void;\n setPurchaseHistories: (purchaseHistories: Purchase[]) => void;\n setAvailablePurchases: (availablePurchases: Purchase[]) => void;\n setCurrentPurchase: (currentPurchase: Purchase | undefined) => void;\n setCurrentPurchaseError: (\n currentPurchaseError: PurchaseError | undefined,\n ) => void;\n};\n\n// @ts-ignore\nconst IAPContext = React.createContext<IAPContextType>(null);\n\nexport function useIAPContext(): IAPContextType {\n const ctx = useContext(IAPContext);\n\n if (!ctx) {\n throw new Error('You need wrap your app with withIAPContext HOC');\n }\n\n return ctx;\n}\n\nexport function withIAPContext<T>(Component: React.ComponentType<T>) {\n return function WrapperComponent(props: T) {\n const [connected, setConnected] = useState(false);\n const [products, setProducts] = useState<Product[]>([]);\n\n const [promotedProductsIOS, setPromotedProductsIOS] = useState<Product[]>(\n [],\n );\n const [subscriptions, setSubscriptions] = useState<Subscription[]>([]);\n const [purchaseHistories, setPurchaseHistories] = useState<Purchase[]>([]);\n\n const [availablePurchases, setAvailablePurchases] = useState<Purchase[]>(\n [],\n );\n const [currentPurchase, setCurrentPurchase] = useState<Purchase>();\n\n const [currentPurchaseError, setCurrentPurchaseError] =\n useState<PurchaseError>();\n\n const [initConnectionError, setInitConnectionError] = useState<Error>();\n\n const context = useMemo(\n () => ({\n connected,\n products,\n subscriptions,\n promotedProductsIOS,\n purchaseHistories,\n availablePurchases,\n currentPurchase,\n currentPurchaseError,\n initConnectionError,\n setProducts,\n setSubscriptions,\n setPurchaseHistories,\n setAvailablePurchases,\n setCurrentPurchase,\n setCurrentPurchaseError,\n }),\n [\n connected,\n products,\n subscriptions,\n promotedProductsIOS,\n purchaseHistories,\n availablePurchases,\n currentPurchase,\n currentPurchaseError,\n initConnectionError,\n setProducts,\n setSubscriptions,\n setPurchaseHistories,\n setAvailablePurchases,\n setCurrentPurchase,\n setCurrentPurchaseError,\n ],\n );\n\n useEffect(() => {\n initConnection()\n .then((value) => {\n setInitConnectionError(undefined);\n setConnected(value);\n })\n .catch(setInitConnectionError);\n }, []);\n\n useEffect(() => {\n if (!connected) {\n return;\n }\n\n const purchaseUpdateSubscription = purchaseUpdatedListener(\n async (purchase: InAppPurchase | SubscriptionPurchase) => {\n setCurrentPurchaseError(undefined);\n setCurrentPurchase(purchase);\n },\n );\n\n const purchaseErrorSubscription = purchaseErrorListener(\n (error: PurchaseError) => {\n setCurrentPurchase(undefined);\n setCurrentPurchaseError(error);\n },\n );\n\n const promotedProductSubscription = promotedProductListener(async () => {\n const product = await getPromotedProductIOS();\n\n setPromotedProductsIOS((prevProducts) => [\n ...prevProducts,\n ...(product ? [product] : []),\n ]);\n });\n\n return () => {\n purchaseUpdateSubscription.remove();\n purchaseErrorSubscription.remove();\n promotedProductSubscription.remove();\n };\n }, [connected]);\n\n return (\n <IAPContext.Provider value={context}>\n <Component {...props} />\n </IAPContext.Provider>\n );\n };\n}\n"],"mappings":";;;;;;;;AAAA;;AAEA;;;;;;AAoCA;AACA,MAAMA,UAAU,gBAAGC,cAAA,CAAMC,aA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