expo-iap 1.0.3 → 2.0.0-rc.1
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/.eslintrc.js +9 -0
- package/.prettierrc.js +9 -0
- package/.swiftlint.yml +10 -0
- package/README.md +28 -21
- package/android/build.gradle +34 -72
- package/android/src/main/AndroidManifest.xml +1 -4
- package/android/src/main/java/expo/modules/iap/ExpoIapModule.kt +535 -0
- package/android/src/main/java/expo/modules/iap/MissingCurrentActivityException.kt +6 -0
- package/android/src/main/java/expo/modules/iap/PlayUtils.kt +124 -0
- package/build/ExpoIap.types.d.ts +89 -0
- package/build/ExpoIap.types.d.ts.map +1 -0
- package/build/ExpoIap.types.js +59 -0
- package/build/ExpoIap.types.js.map +1 -0
- package/build/ExpoIapModule.d.ts +3 -0
- package/build/ExpoIapModule.d.ts.map +1 -0
- package/build/ExpoIapModule.js +5 -0
- package/build/ExpoIapModule.js.map +1 -0
- package/build/index.d.ts +38 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +202 -0
- package/build/index.js.map +1 -0
- package/build/modules/android.d.ts +40 -0
- package/build/modules/android.d.ts.map +1 -0
- package/build/modules/android.js +54 -0
- package/build/modules/android.js.map +1 -0
- package/build/modules/ios.d.ts +41 -0
- package/build/modules/ios.d.ts.map +1 -0
- package/build/modules/ios.js +44 -0
- package/build/modules/ios.js.map +1 -0
- package/build/types/ExpoIapAndroid.types.d.ts +113 -0
- package/build/types/ExpoIapAndroid.types.d.ts.map +1 -0
- package/build/types/ExpoIapAndroid.types.js +23 -0
- package/build/types/ExpoIapAndroid.types.js.map +1 -0
- package/build/types/ExpoIapIos.types.d.ts +122 -0
- package/build/types/ExpoIapIos.types.d.ts.map +1 -0
- package/build/types/ExpoIapIos.types.js +2 -0
- package/build/types/ExpoIapIos.types.js.map +1 -0
- package/bun.lockb +0 -0
- package/expo-module.config.json +4 -8
- package/ios/ExpoIap.podspec +27 -0
- package/ios/ExpoIapModule.swift +498 -0
- package/ios/ProductStore.swift +27 -0
- package/ios/Types.swift +54 -0
- package/package.json +33 -62
- package/src/ExpoIap.types.ts +125 -0
- package/src/ExpoIapModule.ts +5 -0
- package/src/index.ts +397 -0
- package/src/modules/android.ts +89 -0
- package/src/modules/ios.ts +81 -0
- package/src/types/ExpoIapAndroid.types.ts +123 -0
- package/src/types/ExpoIapIos.types.ts +141 -0
- package/tsconfig.json +9 -0
- package/.editorconfig +0 -10
- package/.flowconfig +0 -11
- package/.monolinterrc +0 -3
- package/.yarn/install-state.gz +0 -0
- package/.yarn/releases/yarn-3.1.1.cjs +0 -768
- package/.yarnrc.yml +0 -3
- package/LICENSE +0 -21
- package/RNIap.podspec +0 -18
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +0 -6
- package/android/gradle.properties +0 -2
- package/android/gradlew +0 -160
- package/android/gradlew.bat +0 -90
- package/android/libs/in-app-purchasing-2.0.76.jar +0 -0
- package/android/src/amazon/AndroidManifest.xml +0 -12
- package/android/src/amazon/java/com/dooboolab/RNIap/RNIapAmazonListener.kt +0 -356
- package/android/src/amazon/java/com/dooboolab/RNIap/RNIapAmazonModule.kt +0 -128
- package/android/src/amazon/java/com/dooboolab/RNIap/RNIapPackage.kt +0 -20
- package/android/src/main/java/com/dooboolab/RNIap/DoobooUtils.kt +0 -180
- package/android/src/play/java/com/dooboolab/RNIap/PlayUtils.kt +0 -77
- package/android/src/play/java/com/dooboolab/RNIap/RNIapModule.kt +0 -698
- package/android/src/play/java/com/dooboolab/RNIap/RNIapPackage.kt +0 -20
- package/babel.config.js +0 -10
- package/index.d.ts +0 -3
- package/index.js +0 -3
- package/index.js.flow +0 -9
- package/ios/RNIap.xcodeproj/project.pbxproj +0 -370
- package/ios/RNIap.xcodeproj/xcshareddata/xcschemes/RNIap.xcscheme +0 -80
- package/ios/RNIapIos.m +0 -60
- package/ios/RNIapIos.swift +0 -932
- package/ios/RNIapQueue.swift +0 -35
- package/jest.config.js +0 -194
- package/src/__test__/iap.test.d.ts +0 -1
- package/src/__test__/iap.test.js +0 -59
- package/src/hooks/useIAP.d.ts +0 -21
- package/src/hooks/useIAP.js +0 -140
- package/src/hooks/withIAPContext.d.ts +0 -21
- package/src/hooks/withIAPContext.js +0 -142
- package/src/iap.d.ts +0 -197
- package/src/iap.js +0 -625
- package/src/index.d.ts +0 -4
- package/src/index.js +0 -4
- package/src/types/amazon.d.ts +0 -23
- package/src/types/amazon.js +0 -1
- package/src/types/android.d.ts +0 -47
- package/src/types/android.js +0 -22
- package/src/types/apple.d.ts +0 -424
- package/src/types/apple.js +0 -165
- package/src/types/index.d.ts +0 -117
- package/src/types/index.js +0 -40
- package/test/mocks/react-native-modules.js +0 -14
package/ios/RNIapQueue.swift
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// RNIapQueue.swift
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// Created by Andres Aguilar on 9/8/21.
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
import Foundation
|
|
9
|
-
import StoreKit
|
|
10
|
-
|
|
11
|
-
// Temporarily stores payment information since it is sent by the OS before RN instantiates the RNModule
|
|
12
|
-
@objc(RNIapQueue)
|
|
13
|
-
class RNIapQueue: NSObject, SKPaymentTransactionObserver {
|
|
14
|
-
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
|
|
15
|
-
//No-op
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
static let shared = RNIapQueue()
|
|
19
|
-
|
|
20
|
-
var queue: SKPaymentQueue? = nil;
|
|
21
|
-
var payment: SKPayment? = nil;
|
|
22
|
-
var product: SKProduct? = nil;
|
|
23
|
-
|
|
24
|
-
private override init(){}
|
|
25
|
-
|
|
26
|
-
// Sent when a user initiates an IAP buy from the App Store
|
|
27
|
-
@available(iOS 11.0, *)
|
|
28
|
-
func paymentQueue(_ queue: SKPaymentQueue, shouldAddStorePayment payment: SKPayment, for product: SKProduct) -> Bool{
|
|
29
|
-
RNIapQueue.shared.queue = queue
|
|
30
|
-
RNIapQueue.shared.payment = payment
|
|
31
|
-
RNIapQueue.shared.product = product
|
|
32
|
-
return false
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
}
|
package/jest.config.js
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
// For a detailed explanation regarding each configuration property, visit:
|
|
2
|
-
// https://jestjs.io/docs/en/configuration.html
|
|
3
|
-
|
|
4
|
-
module.exports = {
|
|
5
|
-
// All imported modules in your tests should be mocked automatically
|
|
6
|
-
// automock: false,
|
|
7
|
-
|
|
8
|
-
// Stop running tests after `n` failures
|
|
9
|
-
// bail: 0,
|
|
10
|
-
|
|
11
|
-
// The directory where Jest should store its cached dependency information
|
|
12
|
-
// cacheDirectory: "/private/var/folders/7j/chyhjjfx5vv8r5g_7nk_hrtm0000gp/T/jest_dy",
|
|
13
|
-
|
|
14
|
-
// Automatically clear mock calls and instances between every test
|
|
15
|
-
clearMocks: true,
|
|
16
|
-
|
|
17
|
-
// Indicates whether the coverage information should be collected while executing the test
|
|
18
|
-
// collectCoverage: false,
|
|
19
|
-
|
|
20
|
-
// An array of glob patterns indicating a set of files for which coverage information should be collected
|
|
21
|
-
// collectCoverageFrom: undefined,
|
|
22
|
-
|
|
23
|
-
// The directory where Jest should output its coverage files
|
|
24
|
-
coverageDirectory: "coverage",
|
|
25
|
-
|
|
26
|
-
// An array of regexp pattern strings used to skip coverage collection
|
|
27
|
-
// coveragePathIgnorePatterns: [
|
|
28
|
-
// "/node_modules/"
|
|
29
|
-
// ],
|
|
30
|
-
|
|
31
|
-
// Indicates which provider should be used to instrument code for coverage
|
|
32
|
-
// coverageProvider: "babel",
|
|
33
|
-
|
|
34
|
-
// A list of reporter names that Jest uses when writing coverage reports
|
|
35
|
-
// coverageReporters: [
|
|
36
|
-
// "json",
|
|
37
|
-
// "text",
|
|
38
|
-
// "lcov",
|
|
39
|
-
// "clover"
|
|
40
|
-
// ],
|
|
41
|
-
|
|
42
|
-
// An object that configures minimum threshold enforcement for coverage results
|
|
43
|
-
// coverageThreshold: undefined,
|
|
44
|
-
|
|
45
|
-
// A path to a custom dependency extractor
|
|
46
|
-
// dependencyExtractor: undefined,
|
|
47
|
-
|
|
48
|
-
// Make calling deprecated APIs throw helpful error messages
|
|
49
|
-
// errorOnDeprecated: false,
|
|
50
|
-
|
|
51
|
-
// Force coverage collection from ignored files using an array of glob patterns
|
|
52
|
-
// forceCoverageMatch: [],
|
|
53
|
-
|
|
54
|
-
// A path to a module which exports an async function that is triggered once before all test suites
|
|
55
|
-
// globalSetup: undefined,
|
|
56
|
-
|
|
57
|
-
// A path to a module which exports an async function that is triggered once after all test suites
|
|
58
|
-
// globalTeardown: undefined,
|
|
59
|
-
|
|
60
|
-
// A set of global variables that need to be available in all test environments
|
|
61
|
-
// globals: {},
|
|
62
|
-
|
|
63
|
-
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
|
|
64
|
-
// maxWorkers: "50%",
|
|
65
|
-
|
|
66
|
-
// An array of directory names to be searched recursively up from the requiring module's location
|
|
67
|
-
moduleDirectories: [
|
|
68
|
-
"node_modules","src"
|
|
69
|
-
],
|
|
70
|
-
|
|
71
|
-
// An array of file extensions your modules use
|
|
72
|
-
// moduleFileExtensions: [
|
|
73
|
-
// "js",
|
|
74
|
-
// "json",
|
|
75
|
-
// "jsx",
|
|
76
|
-
// "ts",
|
|
77
|
-
// "tsx",
|
|
78
|
-
// "node"
|
|
79
|
-
// ],
|
|
80
|
-
|
|
81
|
-
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
|
|
82
|
-
// moduleNameMapper: {},
|
|
83
|
-
|
|
84
|
-
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
|
|
85
|
-
modulePathIgnorePatterns: ["IapExample"],
|
|
86
|
-
|
|
87
|
-
// Activates notifications for test results
|
|
88
|
-
// notify: false,
|
|
89
|
-
|
|
90
|
-
// An enum that specifies notification mode. Requires { notify: true }
|
|
91
|
-
// notifyMode: "failure-change",
|
|
92
|
-
|
|
93
|
-
// A preset that is used as a base for Jest's configuration
|
|
94
|
-
preset: 'react-native',
|
|
95
|
-
|
|
96
|
-
// Run tests from one or more projects
|
|
97
|
-
// projects: undefined,
|
|
98
|
-
|
|
99
|
-
// Use this configuration option to add custom reporters to Jest
|
|
100
|
-
// reporters: undefined,
|
|
101
|
-
|
|
102
|
-
// Automatically reset mock state between every test
|
|
103
|
-
// resetMocks: false,
|
|
104
|
-
|
|
105
|
-
// Reset the module registry before running each individual test
|
|
106
|
-
// resetModules: false,
|
|
107
|
-
|
|
108
|
-
// A path to a custom resolver
|
|
109
|
-
// resolver: undefined,
|
|
110
|
-
|
|
111
|
-
// Automatically restore mock state between every test
|
|
112
|
-
// restoreMocks: false,
|
|
113
|
-
|
|
114
|
-
// The root directory that Jest should scan for tests and modules within
|
|
115
|
-
// rootDir: undefined,
|
|
116
|
-
|
|
117
|
-
// A list of paths to directories that Jest should use to search for files in
|
|
118
|
-
// roots: [
|
|
119
|
-
// "<rootDir>"
|
|
120
|
-
// ],
|
|
121
|
-
|
|
122
|
-
// Allows you to use a custom runner instead of Jest's default test runner
|
|
123
|
-
// runner: "jest-runner",
|
|
124
|
-
|
|
125
|
-
// The paths to modules that run some code to configure or set up the testing environment before each test
|
|
126
|
-
setupFiles: ["<rootDir>/test/mocks/react-native-modules.js",],
|
|
127
|
-
|
|
128
|
-
// A list of paths to modules that run some code to configure or set up the testing framework before each test
|
|
129
|
-
setupFilesAfterEnv: ['@testing-library/jest-native/extend-expect'],
|
|
130
|
-
|
|
131
|
-
// The number of seconds after which a test is considered as slow and reported as such in the results.
|
|
132
|
-
// slowTestThreshold: 5,
|
|
133
|
-
|
|
134
|
-
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
|
|
135
|
-
// snapshotSerializers: [],
|
|
136
|
-
|
|
137
|
-
// The test environment that will be used for testing
|
|
138
|
-
// testEnvironment: "node",
|
|
139
|
-
|
|
140
|
-
// Options that will be passed to the testEnvironment
|
|
141
|
-
// testEnvironmentOptions: {},
|
|
142
|
-
|
|
143
|
-
// Adds a location field to test results
|
|
144
|
-
// testLocationInResults: false,
|
|
145
|
-
|
|
146
|
-
// The glob patterns Jest uses to detect test files
|
|
147
|
-
// testMatch: [
|
|
148
|
-
// "**/__tests__/**/*.[jt]s?(x)",
|
|
149
|
-
// "**/?(*.)+(spec|test).[tj]s?(x)"
|
|
150
|
-
// ],
|
|
151
|
-
|
|
152
|
-
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
|
|
153
|
-
// testPathIgnorePatterns: [
|
|
154
|
-
// "/node_modules/"
|
|
155
|
-
// ],
|
|
156
|
-
|
|
157
|
-
// The regexp pattern or array of patterns that Jest uses to detect test files
|
|
158
|
-
// testRegex: [],
|
|
159
|
-
|
|
160
|
-
// This option allows the use of a custom results processor
|
|
161
|
-
// testResultsProcessor: undefined,
|
|
162
|
-
|
|
163
|
-
// This option allows use of a custom test runner
|
|
164
|
-
// testRunner: "jasmine2",
|
|
165
|
-
|
|
166
|
-
// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
|
|
167
|
-
// testURL: "http://localhost",
|
|
168
|
-
|
|
169
|
-
// Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
|
|
170
|
-
// timers: "real",
|
|
171
|
-
|
|
172
|
-
// A map from regular expressions to paths to transformers
|
|
173
|
-
transform: {
|
|
174
|
-
"^.+\\.(js|jsx|ts|tsx)$": "babel-jest",
|
|
175
|
-
"\\.(ts|tsx)$": "ts-jest"
|
|
176
|
-
},
|
|
177
|
-
|
|
178
|
-
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
|
|
179
|
-
transformIgnorePatterns: [
|
|
180
|
-
'node_modules/(?!@react-native|react-native)'
|
|
181
|
-
],
|
|
182
|
-
|
|
183
|
-
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
|
|
184
|
-
// unmockedModulePathPatterns: undefined,
|
|
185
|
-
|
|
186
|
-
// Indicates whether each individual test should be reported during the run
|
|
187
|
-
// verbose: undefined,
|
|
188
|
-
|
|
189
|
-
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
|
|
190
|
-
// watchPathIgnorePatterns: [],
|
|
191
|
-
|
|
192
|
-
// Whether to use watchman for file crawling
|
|
193
|
-
// watchman: true,
|
|
194
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/src/__test__/iap.test.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
-
function step(op) {
|
|
15
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
-
while (_) try {
|
|
17
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
-
switch (op[0]) {
|
|
20
|
-
case 0: case 1: t = op; break;
|
|
21
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
-
default:
|
|
25
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
-
if (t[2]) _.ops.pop();
|
|
30
|
-
_.trys.pop(); continue;
|
|
31
|
-
}
|
|
32
|
-
op = body.call(thisArg, _);
|
|
33
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
import { NativeModules } from 'react-native';
|
|
38
|
-
import { initConnection } from '../iap';
|
|
39
|
-
var rnLib = '../../node_modules/react-native/Libraries';
|
|
40
|
-
describe('Google Play IAP', function () {
|
|
41
|
-
beforeEach(function () {
|
|
42
|
-
jest.mock(rnLib + '/Utilities/Platform', function () { return ({
|
|
43
|
-
OS: 'android',
|
|
44
|
-
select: function (dict) { return dict.android; },
|
|
45
|
-
}); });
|
|
46
|
-
});
|
|
47
|
-
it("should call init on Google Play's native module but not on Amazon's", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
48
|
-
return __generator(this, function (_a) {
|
|
49
|
-
switch (_a.label) {
|
|
50
|
-
case 0: return [4 /*yield*/, initConnection()];
|
|
51
|
-
case 1:
|
|
52
|
-
_a.sent();
|
|
53
|
-
expect(NativeModules.RNIapModule.initConnection).toBeCalled();
|
|
54
|
-
expect(NativeModules.RNIapAmazonModule.initConnection).not.toBeCalled();
|
|
55
|
-
return [2 /*return*/];
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
}); });
|
|
59
|
-
});
|
package/src/hooks/useIAP.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { Product, Purchase, PurchaseError, Subscription } from '../types';
|
|
2
|
-
import { requestPurchase as iapRequestPurchase, requestSubscription as iapRequestSubscription } from '../iap';
|
|
3
|
-
declare type IAP_STATUS = {
|
|
4
|
-
connected: boolean;
|
|
5
|
-
products: Product[];
|
|
6
|
-
promotedProductsIOS: Product[];
|
|
7
|
-
subscriptions: Subscription[];
|
|
8
|
-
purchaseHistories: Purchase[];
|
|
9
|
-
availablePurchases: Purchase[];
|
|
10
|
-
currentPurchase?: Purchase;
|
|
11
|
-
currentPurchaseError?: PurchaseError;
|
|
12
|
-
finishTransaction: (purchase: Purchase, isConsumable?: boolean, developerPayloadAndroid?: string) => Promise<string | void>;
|
|
13
|
-
getAvailablePurchases: () => Promise<void>;
|
|
14
|
-
getPurchaseHistories: () => Promise<void>;
|
|
15
|
-
getProducts: (skus: string[]) => Promise<void>;
|
|
16
|
-
getSubscriptions: (skus: string[]) => Promise<void>;
|
|
17
|
-
requestPurchase: typeof iapRequestPurchase;
|
|
18
|
-
requestSubscription: typeof iapRequestSubscription;
|
|
19
|
-
};
|
|
20
|
-
export declare function useIAP(): IAP_STATUS;
|
|
21
|
-
export {};
|
package/src/hooks/useIAP.js
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
-
function step(op) {
|
|
15
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
-
while (_) try {
|
|
17
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
-
switch (op[0]) {
|
|
20
|
-
case 0: case 1: t = op; break;
|
|
21
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
-
default:
|
|
25
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
-
if (t[2]) _.ops.pop();
|
|
30
|
-
_.trys.pop(); continue;
|
|
31
|
-
}
|
|
32
|
-
op = body.call(thisArg, _);
|
|
33
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
import { getPurchaseHistory, finishTransaction as iapFinishTransaction, getAvailablePurchases as iapGetAvailablePurchases, getProducts as iapGetProducts, getSubscriptions as iapGetSubscriptions, requestPurchase as iapRequestPurchase, requestSubscription as iapRequestSubscription, } from '../iap';
|
|
38
|
-
import { useCallback } from 'react';
|
|
39
|
-
import { useIAPContext } from './withIAPContext';
|
|
40
|
-
export function useIAP() {
|
|
41
|
-
var _this = this;
|
|
42
|
-
var _a = useIAPContext(), connected = _a.connected, products = _a.products, promotedProductsIOS = _a.promotedProductsIOS, subscriptions = _a.subscriptions, purchaseHistories = _a.purchaseHistories, availablePurchases = _a.availablePurchases, currentPurchase = _a.currentPurchase, currentPurchaseError = _a.currentPurchaseError, setProducts = _a.setProducts, setSubscriptions = _a.setSubscriptions, setAvailablePurchases = _a.setAvailablePurchases, setPurchaseHistories = _a.setPurchaseHistories, setCurrentPurchase = _a.setCurrentPurchase, setCurrentPurchaseError = _a.setCurrentPurchaseError;
|
|
43
|
-
var getProducts = useCallback(function (skus) { return __awaiter(_this, void 0, void 0, function () {
|
|
44
|
-
var _a;
|
|
45
|
-
return __generator(this, function (_b) {
|
|
46
|
-
switch (_b.label) {
|
|
47
|
-
case 0:
|
|
48
|
-
_a = setProducts;
|
|
49
|
-
return [4 /*yield*/, iapGetProducts(skus)];
|
|
50
|
-
case 1:
|
|
51
|
-
_a.apply(void 0, [_b.sent()]);
|
|
52
|
-
return [2 /*return*/];
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
}); }, [setProducts]);
|
|
56
|
-
var getSubscriptions = useCallback(function (skus) { return __awaiter(_this, void 0, void 0, function () {
|
|
57
|
-
var _a;
|
|
58
|
-
return __generator(this, function (_b) {
|
|
59
|
-
switch (_b.label) {
|
|
60
|
-
case 0:
|
|
61
|
-
_a = setSubscriptions;
|
|
62
|
-
return [4 /*yield*/, iapGetSubscriptions(skus)];
|
|
63
|
-
case 1:
|
|
64
|
-
_a.apply(void 0, [_b.sent()]);
|
|
65
|
-
return [2 /*return*/];
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
}); }, [setSubscriptions]);
|
|
69
|
-
var getAvailablePurchases = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
70
|
-
var _a;
|
|
71
|
-
return __generator(this, function (_b) {
|
|
72
|
-
switch (_b.label) {
|
|
73
|
-
case 0:
|
|
74
|
-
_a = setAvailablePurchases;
|
|
75
|
-
return [4 /*yield*/, iapGetAvailablePurchases()];
|
|
76
|
-
case 1:
|
|
77
|
-
_a.apply(void 0, [_b.sent()]);
|
|
78
|
-
return [2 /*return*/];
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
}); }, [setAvailablePurchases]);
|
|
82
|
-
var getPurchaseHistories = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
83
|
-
var _a;
|
|
84
|
-
return __generator(this, function (_b) {
|
|
85
|
-
switch (_b.label) {
|
|
86
|
-
case 0:
|
|
87
|
-
_a = setPurchaseHistories;
|
|
88
|
-
return [4 /*yield*/, getPurchaseHistory()];
|
|
89
|
-
case 1:
|
|
90
|
-
_a.apply(void 0, [_b.sent()]);
|
|
91
|
-
return [2 /*return*/];
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
}); }, [setPurchaseHistories]);
|
|
95
|
-
var finishTransaction = useCallback(function (purchase, isConsumable, developerPayloadAndroid) { return __awaiter(_this, void 0, void 0, function () {
|
|
96
|
-
var err_1;
|
|
97
|
-
return __generator(this, function (_a) {
|
|
98
|
-
switch (_a.label) {
|
|
99
|
-
case 0:
|
|
100
|
-
_a.trys.push([0, 2, 3, 4]);
|
|
101
|
-
return [4 /*yield*/, iapFinishTransaction(purchase, isConsumable, developerPayloadAndroid)];
|
|
102
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
103
|
-
case 2:
|
|
104
|
-
err_1 = _a.sent();
|
|
105
|
-
throw err_1;
|
|
106
|
-
case 3:
|
|
107
|
-
if (purchase.productId === (currentPurchase === null || currentPurchase === void 0 ? void 0 : currentPurchase.productId)) {
|
|
108
|
-
setCurrentPurchase(undefined);
|
|
109
|
-
}
|
|
110
|
-
if (purchase.productId === (currentPurchaseError === null || currentPurchaseError === void 0 ? void 0 : currentPurchaseError.productId)) {
|
|
111
|
-
setCurrentPurchaseError(undefined);
|
|
112
|
-
}
|
|
113
|
-
return [7 /*endfinally*/];
|
|
114
|
-
case 4: return [2 /*return*/];
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
}); }, [
|
|
118
|
-
currentPurchase === null || currentPurchase === void 0 ? void 0 : currentPurchase.productId,
|
|
119
|
-
currentPurchaseError === null || currentPurchaseError === void 0 ? void 0 : currentPurchaseError.productId,
|
|
120
|
-
setCurrentPurchase,
|
|
121
|
-
setCurrentPurchaseError,
|
|
122
|
-
]);
|
|
123
|
-
return {
|
|
124
|
-
connected: connected,
|
|
125
|
-
products: products,
|
|
126
|
-
promotedProductsIOS: promotedProductsIOS,
|
|
127
|
-
subscriptions: subscriptions,
|
|
128
|
-
purchaseHistories: purchaseHistories,
|
|
129
|
-
availablePurchases: availablePurchases,
|
|
130
|
-
currentPurchase: currentPurchase,
|
|
131
|
-
currentPurchaseError: currentPurchaseError,
|
|
132
|
-
finishTransaction: finishTransaction,
|
|
133
|
-
getProducts: getProducts,
|
|
134
|
-
getSubscriptions: getSubscriptions,
|
|
135
|
-
getAvailablePurchases: getAvailablePurchases,
|
|
136
|
-
getPurchaseHistories: getPurchaseHistories,
|
|
137
|
-
requestPurchase: iapRequestPurchase,
|
|
138
|
-
requestSubscription: iapRequestSubscription,
|
|
139
|
-
};
|
|
140
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Product, Purchase, PurchaseError, Subscription } from '../types';
|
|
3
|
-
declare type IAPContextType = {
|
|
4
|
-
connected: boolean;
|
|
5
|
-
products: Product[];
|
|
6
|
-
promotedProductsIOS: Product[];
|
|
7
|
-
subscriptions: Subscription[];
|
|
8
|
-
purchaseHistories: Purchase[];
|
|
9
|
-
availablePurchases: Purchase[];
|
|
10
|
-
currentPurchase?: Purchase;
|
|
11
|
-
currentPurchaseError?: PurchaseError;
|
|
12
|
-
setProducts: (products: Product[]) => void;
|
|
13
|
-
setSubscriptions: (subscriptions: Subscription[]) => void;
|
|
14
|
-
setPurchaseHistories: (purchaseHistories: Purchase[]) => void;
|
|
15
|
-
setAvailablePurchases: (availablePurchases: Purchase[]) => void;
|
|
16
|
-
setCurrentPurchase: (currentPurchase: Purchase | undefined) => void;
|
|
17
|
-
setCurrentPurchaseError: (currentPurchaseError: PurchaseError | undefined) => void;
|
|
18
|
-
};
|
|
19
|
-
export declare function useIAPContext(): IAPContextType;
|
|
20
|
-
export declare function withIAPContext<T>(Component: React.ComponentType<T>): (props: T) => JSX.Element;
|
|
21
|
-
export {};
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
-
function step(op) {
|
|
15
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
-
while (_) try {
|
|
17
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
-
switch (op[0]) {
|
|
20
|
-
case 0: case 1: t = op; break;
|
|
21
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
-
default:
|
|
25
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
-
if (t[2]) _.ops.pop();
|
|
30
|
-
_.trys.pop(); continue;
|
|
31
|
-
}
|
|
32
|
-
op = body.call(thisArg, _);
|
|
33
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
38
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
39
|
-
if (ar || !(i in from)) {
|
|
40
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
41
|
-
ar[i] = from[i];
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
45
|
-
};
|
|
46
|
-
import React, { useContext, useEffect, useMemo, useState } from 'react';
|
|
47
|
-
import { NativeEventEmitter, NativeModules } from 'react-native';
|
|
48
|
-
import { getPromotedProductIOS, initConnection, purchaseErrorListener, purchaseUpdatedListener, } from '../iap';
|
|
49
|
-
var RNIapIos = NativeModules.RNIapIos;
|
|
50
|
-
var IAPEmitter = new NativeEventEmitter(RNIapIos);
|
|
51
|
-
// @ts-ignore
|
|
52
|
-
var IAPContext = React.createContext(null);
|
|
53
|
-
export function useIAPContext() {
|
|
54
|
-
var ctx = useContext(IAPContext);
|
|
55
|
-
if (!ctx) {
|
|
56
|
-
throw new Error('You need wrap your app with withIAPContext HOC');
|
|
57
|
-
}
|
|
58
|
-
return ctx;
|
|
59
|
-
}
|
|
60
|
-
export function withIAPContext(Component) {
|
|
61
|
-
return function WrapperComponent(props) {
|
|
62
|
-
var _this = this;
|
|
63
|
-
var _a = useState(false), connected = _a[0], setConnected = _a[1];
|
|
64
|
-
var _b = useState([]), products = _b[0], setProducts = _b[1];
|
|
65
|
-
var _c = useState([]), promotedProductsIOS = _c[0], setPromotedProductsIOS = _c[1];
|
|
66
|
-
var _d = useState([]), subscriptions = _d[0], setSubscriptions = _d[1];
|
|
67
|
-
var _e = useState([]), purchaseHistories = _e[0], setPurchaseHistories = _e[1];
|
|
68
|
-
var _f = useState([]), availablePurchases = _f[0], setAvailablePurchases = _f[1];
|
|
69
|
-
var _g = useState(), currentPurchase = _g[0], setCurrentPurchase = _g[1];
|
|
70
|
-
var _h = useState(), currentPurchaseError = _h[0], setCurrentPurchaseError = _h[1];
|
|
71
|
-
var context = useMemo(function () { return ({
|
|
72
|
-
connected: connected,
|
|
73
|
-
products: products,
|
|
74
|
-
subscriptions: subscriptions,
|
|
75
|
-
promotedProductsIOS: promotedProductsIOS,
|
|
76
|
-
purchaseHistories: purchaseHistories,
|
|
77
|
-
availablePurchases: availablePurchases,
|
|
78
|
-
currentPurchase: currentPurchase,
|
|
79
|
-
currentPurchaseError: currentPurchaseError,
|
|
80
|
-
setProducts: setProducts,
|
|
81
|
-
setSubscriptions: setSubscriptions,
|
|
82
|
-
setPurchaseHistories: setPurchaseHistories,
|
|
83
|
-
setAvailablePurchases: setAvailablePurchases,
|
|
84
|
-
setCurrentPurchase: setCurrentPurchase,
|
|
85
|
-
setCurrentPurchaseError: setCurrentPurchaseError,
|
|
86
|
-
}); }, [
|
|
87
|
-
connected,
|
|
88
|
-
products,
|
|
89
|
-
subscriptions,
|
|
90
|
-
promotedProductsIOS,
|
|
91
|
-
purchaseHistories,
|
|
92
|
-
availablePurchases,
|
|
93
|
-
currentPurchase,
|
|
94
|
-
currentPurchaseError,
|
|
95
|
-
setProducts,
|
|
96
|
-
setSubscriptions,
|
|
97
|
-
setPurchaseHistories,
|
|
98
|
-
setAvailablePurchases,
|
|
99
|
-
setCurrentPurchase,
|
|
100
|
-
setCurrentPurchaseError,
|
|
101
|
-
]);
|
|
102
|
-
useEffect(function () {
|
|
103
|
-
initConnection().then(setConnected);
|
|
104
|
-
}, []);
|
|
105
|
-
useEffect(function () {
|
|
106
|
-
if (!connected) {
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
var purchaseUpdateSubscription = purchaseUpdatedListener(function (purchase) { return __awaiter(_this, void 0, void 0, function () {
|
|
110
|
-
return __generator(this, function (_a) {
|
|
111
|
-
setCurrentPurchaseError(undefined);
|
|
112
|
-
setCurrentPurchase(purchase);
|
|
113
|
-
return [2 /*return*/];
|
|
114
|
-
});
|
|
115
|
-
}); });
|
|
116
|
-
var purchaseErrorSubscription = purchaseErrorListener(function (error) {
|
|
117
|
-
setCurrentPurchase(undefined);
|
|
118
|
-
setCurrentPurchaseError(error);
|
|
119
|
-
});
|
|
120
|
-
var promotedProductsSubscription = IAPEmitter.addListener('iap-promoted-product', function () { return __awaiter(_this, void 0, void 0, function () {
|
|
121
|
-
var product;
|
|
122
|
-
return __generator(this, function (_a) {
|
|
123
|
-
switch (_a.label) {
|
|
124
|
-
case 0: return [4 /*yield*/, getPromotedProductIOS()];
|
|
125
|
-
case 1:
|
|
126
|
-
product = _a.sent();
|
|
127
|
-
setPromotedProductsIOS(function (prevProducts) { return __spreadArray(__spreadArray([], prevProducts, true), (product ? [product] : []), true); });
|
|
128
|
-
return [2 /*return*/];
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
}); });
|
|
132
|
-
return function () {
|
|
133
|
-
purchaseUpdateSubscription.remove();
|
|
134
|
-
purchaseErrorSubscription.remove();
|
|
135
|
-
promotedProductsSubscription.remove();
|
|
136
|
-
};
|
|
137
|
-
}, [connected]);
|
|
138
|
-
return (<IAPContext.Provider value={context}>
|
|
139
|
-
<Component {...props}/>
|
|
140
|
-
</IAPContext.Provider>);
|
|
141
|
-
};
|
|
142
|
-
}
|