@chipmobilesdk/rn-payment 0.5.0 → 0.7.0
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/CHANGELOG.md +172 -0
- package/README.md +47 -16
- package/lib/commonjs/adapter/createStoreProvider.js +110 -0
- package/lib/commonjs/adapter/createStoreProvider.js.map +1 -0
- package/lib/commonjs/adapter/iap-adapter.js +393 -0
- package/lib/commonjs/adapter/iap-adapter.js.map +1 -0
- package/lib/commonjs/adapter/iapShapes.js +169 -0
- package/lib/commonjs/adapter/iapShapes.js.map +1 -0
- package/lib/commonjs/adapter/port.js +6 -0
- package/lib/commonjs/adapter/port.js.map +1 -0
- package/lib/commonjs/config/types.js +2 -0
- package/lib/commonjs/config/types.js.map +1 -0
- package/lib/commonjs/config/validate.js +181 -0
- package/lib/commonjs/config/validate.js.map +1 -0
- package/lib/commonjs/core/mutex.js +31 -0
- package/lib/commonjs/core/mutex.js.map +1 -0
- package/lib/commonjs/core/retry.js +37 -0
- package/lib/commonjs/core/retry.js.map +1 -0
- package/lib/commonjs/core/timers.js +207 -0
- package/lib/commonjs/core/timers.js.map +1 -0
- package/lib/commonjs/diagnostics/errors.js +83 -0
- package/lib/commonjs/diagnostics/errors.js.map +1 -0
- package/lib/commonjs/diagnostics/events.js +126 -0
- package/lib/commonjs/diagnostics/events.js.map +1 -0
- package/lib/commonjs/diagnostics/messageKeys.js +70 -0
- package/lib/commonjs/diagnostics/messageKeys.js.map +1 -0
- package/lib/commonjs/engine/connection.js +189 -0
- package/lib/commonjs/engine/connection.js.map +1 -0
- package/lib/commonjs/engine/engine.js +279 -0
- package/lib/commonjs/engine/engine.js.map +1 -0
- package/lib/commonjs/engine/finalize.js +325 -0
- package/lib/commonjs/engine/finalize.js.map +1 -0
- package/lib/commonjs/engine/foreground.js +26 -0
- package/lib/commonjs/engine/foreground.js.map +1 -0
- package/lib/commonjs/engine/internals.js +31 -0
- package/lib/commonjs/engine/internals.js.map +1 -0
- package/lib/commonjs/engine/pending.js +102 -0
- package/lib/commonjs/engine/pending.js.map +1 -0
- package/lib/commonjs/engine/products.js +198 -0
- package/lib/commonjs/engine/products.js.map +1 -0
- package/lib/commonjs/engine/purchase.js +395 -0
- package/lib/commonjs/engine/purchase.js.map +1 -0
- package/lib/commonjs/engine/purchaseFailure.js +77 -0
- package/lib/commonjs/engine/purchaseFailure.js.map +1 -0
- package/lib/commonjs/engine/receiptValidation.js +90 -0
- package/lib/commonjs/engine/receiptValidation.js.map +1 -0
- package/lib/commonjs/engine/state.js +201 -0
- package/lib/commonjs/engine/state.js.map +1 -0
- package/lib/commonjs/engine/subscriptions.js +122 -0
- package/lib/commonjs/engine/subscriptions.js.map +1 -0
- package/lib/commonjs/engine/sync.js +163 -0
- package/lib/commonjs/engine/sync.js.map +1 -0
- package/lib/commonjs/entitlements/aggregate.js +212 -0
- package/lib/commonjs/entitlements/aggregate.js.map +1 -0
- package/lib/commonjs/entitlements/mapping.js +41 -0
- package/lib/commonjs/entitlements/mapping.js.map +1 -0
- package/lib/commonjs/entitlements/policy.js +110 -0
- package/lib/commonjs/entitlements/policy.js.map +1 -0
- package/lib/commonjs/index.js +266 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/persistence/mmkv-store.js +149 -0
- package/lib/commonjs/persistence/mmkv-store.js.map +1 -0
- package/lib/commonjs/persistence/snapshot.js +229 -0
- package/lib/commonjs/persistence/snapshot.js.map +1 -0
- package/lib/commonjs/react/PaymentProvider.js +96 -0
- package/lib/commonjs/react/PaymentProvider.js.map +1 -0
- package/lib/commonjs/react/hooks.js +202 -0
- package/lib/commonjs/react/hooks.js.map +1 -0
- package/lib/commonjs/testing/conformance.js +136 -0
- package/lib/commonjs/testing/conformance.js.map +1 -0
- package/lib/commonjs/testing/fakeStore.js +281 -0
- package/lib/commonjs/testing/fakeStore.js.map +1 -0
- package/lib/commonjs/testing/index.js +45 -0
- package/lib/commonjs/testing/index.js.map +1 -0
- package/lib/module/adapter/createStoreProvider.js +106 -0
- package/lib/module/adapter/createStoreProvider.js.map +1 -0
- package/lib/module/adapter/iap-adapter.js +383 -0
- package/lib/module/adapter/iap-adapter.js.map +1 -0
- package/lib/module/adapter/iapShapes.js +160 -0
- package/lib/module/adapter/iapShapes.js.map +1 -0
- package/lib/module/adapter/port.js +4 -0
- package/lib/module/adapter/port.js.map +1 -0
- package/lib/module/config/types.js +2 -0
- package/lib/module/config/types.js.map +1 -0
- package/lib/module/config/validate.js +175 -0
- package/lib/module/config/validate.js.map +1 -0
- package/lib/module/core/mutex.js +22 -0
- package/lib/module/core/mutex.js.map +1 -0
- package/lib/module/core/retry.js +33 -0
- package/lib/module/core/retry.js.map +1 -0
- package/lib/module/core/timers.js +198 -0
- package/lib/module/core/timers.js.map +1 -0
- package/lib/module/diagnostics/errors.js +76 -0
- package/lib/module/diagnostics/errors.js.map +1 -0
- package/lib/module/diagnostics/events.js +117 -0
- package/lib/module/diagnostics/events.js.map +1 -0
- package/lib/module/diagnostics/messageKeys.js +64 -0
- package/lib/module/diagnostics/messageKeys.js.map +1 -0
- package/lib/module/engine/connection.js +185 -0
- package/lib/module/engine/connection.js.map +1 -0
- package/lib/module/engine/engine.js +274 -0
- package/lib/module/engine/engine.js.map +1 -0
- package/lib/module/engine/finalize.js +322 -0
- package/lib/module/engine/finalize.js.map +1 -0
- package/lib/module/engine/foreground.js +21 -0
- package/lib/module/engine/foreground.js.map +1 -0
- package/lib/module/engine/internals.js +26 -0
- package/lib/module/engine/internals.js.map +1 -0
- package/lib/module/engine/pending.js +95 -0
- package/lib/module/engine/pending.js.map +1 -0
- package/lib/module/engine/products.js +195 -0
- package/lib/module/engine/products.js.map +1 -0
- package/lib/module/engine/purchase.js +390 -0
- package/lib/module/engine/purchase.js.map +1 -0
- package/lib/module/engine/purchaseFailure.js +72 -0
- package/lib/module/engine/purchaseFailure.js.map +1 -0
- package/lib/module/engine/receiptValidation.js +87 -0
- package/lib/module/engine/receiptValidation.js.map +1 -0
- package/lib/module/engine/state.js +196 -0
- package/lib/module/engine/state.js.map +1 -0
- package/lib/module/engine/subscriptions.js +119 -0
- package/lib/module/engine/subscriptions.js.map +1 -0
- package/lib/module/engine/sync.js +158 -0
- package/lib/module/engine/sync.js.map +1 -0
- package/lib/module/entitlements/aggregate.js +204 -0
- package/lib/module/entitlements/aggregate.js.map +1 -0
- package/lib/module/entitlements/mapping.js +35 -0
- package/lib/module/entitlements/mapping.js.map +1 -0
- package/lib/module/entitlements/policy.js +104 -0
- package/lib/module/entitlements/policy.js.map +1 -0
- package/lib/module/index.js +59 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/persistence/mmkv-store.js +144 -0
- package/lib/module/persistence/mmkv-store.js.map +1 -0
- package/lib/module/persistence/snapshot.js +221 -0
- package/lib/module/persistence/snapshot.js.map +1 -0
- package/lib/module/react/PaymentProvider.js +90 -0
- package/lib/module/react/PaymentProvider.js.map +1 -0
- package/lib/module/react/hooks.js +192 -0
- package/lib/module/react/hooks.js.map +1 -0
- package/lib/module/testing/conformance.js +130 -0
- package/lib/module/testing/conformance.js.map +1 -0
- package/lib/module/testing/fakeStore.js +276 -0
- package/lib/module/testing/fakeStore.js.map +1 -0
- package/lib/module/testing/index.js +13 -0
- package/lib/module/testing/index.js.map +1 -0
- package/lib/typescript/commonjs/adapter/createStoreProvider.d.ts +45 -0
- package/lib/typescript/commonjs/adapter/createStoreProvider.d.ts.map +1 -0
- package/lib/typescript/commonjs/adapter/iap-adapter.d.ts +80 -0
- package/lib/typescript/commonjs/adapter/iap-adapter.d.ts.map +1 -0
- package/lib/typescript/commonjs/adapter/iapShapes.d.ts +94 -0
- package/lib/typescript/commonjs/adapter/iapShapes.d.ts.map +1 -0
- package/lib/typescript/commonjs/adapter/port.d.ts +184 -0
- package/lib/typescript/commonjs/adapter/port.d.ts.map +1 -0
- package/lib/typescript/commonjs/config/types.d.ts +326 -0
- package/lib/typescript/commonjs/config/types.d.ts.map +1 -0
- package/lib/typescript/commonjs/config/validate.d.ts +63 -0
- package/lib/typescript/commonjs/config/validate.d.ts.map +1 -0
- package/lib/typescript/commonjs/core/mutex.d.ts +17 -0
- package/lib/typescript/commonjs/core/mutex.d.ts.map +1 -0
- package/lib/typescript/commonjs/core/retry.d.ts +19 -0
- package/lib/typescript/commonjs/core/retry.d.ts.map +1 -0
- package/lib/typescript/commonjs/core/timers.d.ts +142 -0
- package/lib/typescript/commonjs/core/timers.d.ts.map +1 -0
- package/lib/typescript/commonjs/diagnostics/errors.d.ts +55 -0
- package/lib/typescript/commonjs/diagnostics/errors.d.ts.map +1 -0
- package/lib/typescript/commonjs/diagnostics/events.d.ts +158 -0
- package/lib/typescript/commonjs/diagnostics/events.d.ts.map +1 -0
- package/lib/typescript/commonjs/diagnostics/messageKeys.d.ts +54 -0
- package/lib/typescript/commonjs/diagnostics/messageKeys.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/connection.d.ts +30 -0
- package/lib/typescript/commonjs/engine/connection.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/engine.d.ts +93 -0
- package/lib/typescript/commonjs/engine/engine.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/finalize.d.ts +53 -0
- package/lib/typescript/commonjs/engine/finalize.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/foreground.d.ts +15 -0
- package/lib/typescript/commonjs/engine/foreground.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/internals.d.ts +28 -0
- package/lib/typescript/commonjs/engine/internals.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/pending.d.ts +51 -0
- package/lib/typescript/commonjs/engine/pending.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/products.d.ts +82 -0
- package/lib/typescript/commonjs/engine/products.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/purchase.d.ts +61 -0
- package/lib/typescript/commonjs/engine/purchase.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/purchaseFailure.d.ts +15 -0
- package/lib/typescript/commonjs/engine/purchaseFailure.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/receiptValidation.d.ts +42 -0
- package/lib/typescript/commonjs/engine/receiptValidation.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/state.d.ts +46 -0
- package/lib/typescript/commonjs/engine/state.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/subscriptions.d.ts +61 -0
- package/lib/typescript/commonjs/engine/subscriptions.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/sync.d.ts +36 -0
- package/lib/typescript/commonjs/engine/sync.d.ts.map +1 -0
- package/lib/typescript/commonjs/entitlements/aggregate.d.ts +97 -0
- package/lib/typescript/commonjs/entitlements/aggregate.d.ts.map +1 -0
- package/lib/typescript/commonjs/entitlements/mapping.d.ts +27 -0
- package/lib/typescript/commonjs/entitlements/mapping.d.ts.map +1 -0
- package/lib/typescript/commonjs/entitlements/policy.d.ts +75 -0
- package/lib/typescript/commonjs/entitlements/policy.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +44 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/persistence/mmkv-store.d.ts +45 -0
- package/lib/typescript/commonjs/persistence/mmkv-store.d.ts.map +1 -0
- package/lib/typescript/commonjs/persistence/snapshot.d.ts +106 -0
- package/lib/typescript/commonjs/persistence/snapshot.d.ts.map +1 -0
- package/lib/typescript/commonjs/react/PaymentProvider.d.ts +57 -0
- package/lib/typescript/commonjs/react/PaymentProvider.d.ts.map +1 -0
- package/lib/typescript/commonjs/react/hooks.d.ts +80 -0
- package/lib/typescript/commonjs/react/hooks.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/conformance.d.ts +41 -0
- package/lib/typescript/commonjs/testing/conformance.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/fakeStore.d.ts +69 -0
- package/lib/typescript/commonjs/testing/fakeStore.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/index.d.ts +12 -0
- package/lib/typescript/commonjs/testing/index.d.ts.map +1 -0
- package/lib/typescript/module/adapter/createStoreProvider.d.ts +45 -0
- package/lib/typescript/module/adapter/createStoreProvider.d.ts.map +1 -0
- package/lib/typescript/module/adapter/iap-adapter.d.ts +80 -0
- package/lib/typescript/module/adapter/iap-adapter.d.ts.map +1 -0
- package/lib/typescript/module/adapter/iapShapes.d.ts +94 -0
- package/lib/typescript/module/adapter/iapShapes.d.ts.map +1 -0
- package/lib/typescript/module/adapter/port.d.ts +184 -0
- package/lib/typescript/module/adapter/port.d.ts.map +1 -0
- package/lib/typescript/module/config/types.d.ts +326 -0
- package/lib/typescript/module/config/types.d.ts.map +1 -0
- package/lib/typescript/module/config/validate.d.ts +63 -0
- package/lib/typescript/module/config/validate.d.ts.map +1 -0
- package/lib/typescript/module/core/mutex.d.ts +17 -0
- package/lib/typescript/module/core/mutex.d.ts.map +1 -0
- package/lib/typescript/module/core/retry.d.ts +19 -0
- package/lib/typescript/module/core/retry.d.ts.map +1 -0
- package/lib/typescript/module/core/timers.d.ts +142 -0
- package/lib/typescript/module/core/timers.d.ts.map +1 -0
- package/lib/typescript/module/diagnostics/errors.d.ts +55 -0
- package/lib/typescript/module/diagnostics/errors.d.ts.map +1 -0
- package/lib/typescript/module/diagnostics/events.d.ts +158 -0
- package/lib/typescript/module/diagnostics/events.d.ts.map +1 -0
- package/lib/typescript/module/diagnostics/messageKeys.d.ts +54 -0
- package/lib/typescript/module/diagnostics/messageKeys.d.ts.map +1 -0
- package/lib/typescript/module/engine/connection.d.ts +30 -0
- package/lib/typescript/module/engine/connection.d.ts.map +1 -0
- package/lib/typescript/module/engine/engine.d.ts +93 -0
- package/lib/typescript/module/engine/engine.d.ts.map +1 -0
- package/lib/typescript/module/engine/finalize.d.ts +53 -0
- package/lib/typescript/module/engine/finalize.d.ts.map +1 -0
- package/lib/typescript/module/engine/foreground.d.ts +15 -0
- package/lib/typescript/module/engine/foreground.d.ts.map +1 -0
- package/lib/typescript/module/engine/internals.d.ts +28 -0
- package/lib/typescript/module/engine/internals.d.ts.map +1 -0
- package/lib/typescript/module/engine/pending.d.ts +51 -0
- package/lib/typescript/module/engine/pending.d.ts.map +1 -0
- package/lib/typescript/module/engine/products.d.ts +82 -0
- package/lib/typescript/module/engine/products.d.ts.map +1 -0
- package/lib/typescript/module/engine/purchase.d.ts +61 -0
- package/lib/typescript/module/engine/purchase.d.ts.map +1 -0
- package/lib/typescript/module/engine/purchaseFailure.d.ts +15 -0
- package/lib/typescript/module/engine/purchaseFailure.d.ts.map +1 -0
- package/lib/typescript/module/engine/receiptValidation.d.ts +42 -0
- package/lib/typescript/module/engine/receiptValidation.d.ts.map +1 -0
- package/lib/typescript/module/engine/state.d.ts +46 -0
- package/lib/typescript/module/engine/state.d.ts.map +1 -0
- package/lib/typescript/module/engine/subscriptions.d.ts +61 -0
- package/lib/typescript/module/engine/subscriptions.d.ts.map +1 -0
- package/lib/typescript/module/engine/sync.d.ts +36 -0
- package/lib/typescript/module/engine/sync.d.ts.map +1 -0
- package/lib/typescript/module/entitlements/aggregate.d.ts +97 -0
- package/lib/typescript/module/entitlements/aggregate.d.ts.map +1 -0
- package/lib/typescript/module/entitlements/mapping.d.ts +27 -0
- package/lib/typescript/module/entitlements/mapping.d.ts.map +1 -0
- package/lib/typescript/module/entitlements/policy.d.ts +75 -0
- package/lib/typescript/module/entitlements/policy.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +44 -0
- package/lib/typescript/module/index.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/persistence/mmkv-store.d.ts +45 -0
- package/lib/typescript/module/persistence/mmkv-store.d.ts.map +1 -0
- package/lib/typescript/module/persistence/snapshot.d.ts +106 -0
- package/lib/typescript/module/persistence/snapshot.d.ts.map +1 -0
- package/lib/typescript/module/react/PaymentProvider.d.ts +57 -0
- package/lib/typescript/module/react/PaymentProvider.d.ts.map +1 -0
- package/lib/typescript/module/react/hooks.d.ts +80 -0
- package/lib/typescript/module/react/hooks.d.ts.map +1 -0
- package/lib/typescript/module/testing/conformance.d.ts +41 -0
- package/lib/typescript/module/testing/conformance.d.ts.map +1 -0
- package/lib/typescript/module/testing/fakeStore.d.ts +69 -0
- package/lib/typescript/module/testing/fakeStore.d.ts.map +1 -0
- package/lib/typescript/module/testing/index.d.ts +12 -0
- package/lib/typescript/module/testing/index.d.ts.map +1 -0
- package/package.json +49 -13
- package/skills/sdk-rn-payment/SKILL.md +4 -4
- package/src/adapter/iap-adapter.ts +12 -216
- package/src/adapter/iapShapes.ts +232 -0
- package/src/config/types.ts +8 -0
- package/src/config/validate.ts +19 -4
- package/src/core/retry.ts +1 -58
- package/src/diagnostics/events.ts +1 -1
- package/src/engine/connection.ts +194 -0
- package/src/engine/engine.ts +140 -700
- package/src/engine/internals.ts +40 -0
- package/src/engine/products.ts +39 -17
- package/src/engine/purchase.ts +22 -130
- package/src/engine/purchaseFailure.ts +48 -0
- package/src/engine/receiptValidation.ts +101 -0
- package/src/engine/state.ts +253 -0
- package/src/engine/sync.ts +161 -0
- package/src/entitlements/aggregate.ts +3 -5
- package/src/entitlements/mapping.ts +0 -22
- package/src/persistence/mmkv-store.ts +10 -3
- package/src/persistence/snapshot.ts +102 -27
- package/src/react/PaymentProvider.tsx +73 -24
- package/src/react/hooks.ts +13 -3
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "CONFORMANCE_STORE", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _conformance.CONFORMANCE_STORE;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "createFakeStore", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _fakeStore.createFakeStore;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "createMemorySnapshotStore", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _mmkvStore.createMemorySnapshotStore;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "makePurchase", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _fakeStore.makePurchase;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "providerPortChecks", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _conformance.providerPortChecks;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "runProviderPortConformance", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _conformance.runProviderPortConformance;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
var _fakeStore = require("./fakeStore.js");
|
|
43
|
+
var _mmkvStore = require("../persistence/mmkv-store.js");
|
|
44
|
+
var _conformance = require("./conformance.js");
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_fakeStore","require","_mmkvStore","_conformance"],"sourceRoot":"../../../src","sources":["testing/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,IAAAA,UAAA,GAAAC,OAAA;AAEA,IAAAC,UAAA,GAAAD,OAAA;AAEA,IAAAE,YAAA,GAAAF,OAAA","ignoreList":[]}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Platform selection for the store adapter.
|
|
5
|
+
*
|
|
6
|
+
* This exists so the public surface never names a store. An app writes
|
|
7
|
+
* `createStoreProvider()`, not `createIapAdapter()` — the same call will pick the
|
|
8
|
+
* StoreKit adapter once iOS exists, and no consumer line changes (FR-002, FR-004,
|
|
9
|
+
* FR-007).
|
|
10
|
+
*
|
|
11
|
+
* On a platform with no adapter the result is a stub that reports
|
|
12
|
+
* `platform_unsupported` rather than throwing. That is what lets a host app start
|
|
13
|
+
* and run normally where selling is impossible, losing only the ability to sell
|
|
14
|
+
* (FR-021, FR-023).
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { Platform } from 'react-native';
|
|
18
|
+
import { createIapAdapter } from "./iap-adapter.js";
|
|
19
|
+
const UNSUPPORTED_CAPABILITIES = {
|
|
20
|
+
supportsSubscriptions: false,
|
|
21
|
+
supportsPlanChange: false,
|
|
22
|
+
supportsPriceChangeConfirmation: false,
|
|
23
|
+
reportsGraceAndHoldDistinctly: false,
|
|
24
|
+
supportsExternalTransactions: false,
|
|
25
|
+
/** Nothing here can charge anyone, so the environment guard has nothing to block. */
|
|
26
|
+
createsRealTransactions: false,
|
|
27
|
+
purchaseOutcomeIncludesStoreTime: false
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The no-adapter stub.
|
|
32
|
+
*
|
|
33
|
+
* Every operation fails safely and predictably. Notably `queryOwned` returns an
|
|
34
|
+
* empty list rather than throwing: the engine then computes `not_entitled` after a
|
|
35
|
+
* successful-but-empty sync, which is honest — on a platform with no store, the
|
|
36
|
+
* user genuinely holds nothing this package can verify.
|
|
37
|
+
*/
|
|
38
|
+
function createUnsupportedProvider() {
|
|
39
|
+
return {
|
|
40
|
+
async connect() {
|
|
41
|
+
return {
|
|
42
|
+
ok: false,
|
|
43
|
+
reason: 'platform_unsupported',
|
|
44
|
+
retryable: false
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
async disconnect() {
|
|
48
|
+
// Nothing was ever connected.
|
|
49
|
+
},
|
|
50
|
+
observeConnection() {
|
|
51
|
+
return () => undefined;
|
|
52
|
+
},
|
|
53
|
+
async queryProducts() {
|
|
54
|
+
return [];
|
|
55
|
+
},
|
|
56
|
+
async queryOwned() {
|
|
57
|
+
return [];
|
|
58
|
+
},
|
|
59
|
+
async launchPurchase() {
|
|
60
|
+
return {
|
|
61
|
+
ok: false,
|
|
62
|
+
reason: 'not_ready',
|
|
63
|
+
detail: 'platform_unsupported'
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
observePurchases() {
|
|
67
|
+
return () => undefined;
|
|
68
|
+
},
|
|
69
|
+
async acknowledge() {
|
|
70
|
+
// No transaction can exist to acknowledge.
|
|
71
|
+
},
|
|
72
|
+
async consume() {
|
|
73
|
+
// As above.
|
|
74
|
+
},
|
|
75
|
+
async openSubscriptionManagement() {
|
|
76
|
+
// No store screen to open.
|
|
77
|
+
},
|
|
78
|
+
async confirmPriceChange() {
|
|
79
|
+
return {
|
|
80
|
+
ok: false,
|
|
81
|
+
reason: 'not_ready'
|
|
82
|
+
};
|
|
83
|
+
},
|
|
84
|
+
capabilities: () => UNSUPPORTED_CAPABILITIES
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The platform's store adapter.
|
|
89
|
+
*
|
|
90
|
+
* iOS deliberately returns the stub today rather than throwing: the contract is
|
|
91
|
+
* prepared for StoreKit, the implementation is not, and an app running on iOS
|
|
92
|
+
* should degrade to "cannot sell here" instead of crashing.
|
|
93
|
+
*/
|
|
94
|
+
export function createStoreProvider(options = {}) {
|
|
95
|
+
if (options.forceUnsupported) {
|
|
96
|
+
return createUnsupportedProvider();
|
|
97
|
+
}
|
|
98
|
+
if (Platform.OS === 'android') {
|
|
99
|
+
return createIapAdapter();
|
|
100
|
+
}
|
|
101
|
+
return createUnsupportedProvider();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Exported for a test or a screen that needs the stub explicitly. */
|
|
105
|
+
export { createUnsupportedProvider };
|
|
106
|
+
//# sourceMappingURL=createStoreProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Platform","createIapAdapter","UNSUPPORTED_CAPABILITIES","supportsSubscriptions","supportsPlanChange","supportsPriceChangeConfirmation","reportsGraceAndHoldDistinctly","supportsExternalTransactions","createsRealTransactions","purchaseOutcomeIncludesStoreTime","createUnsupportedProvider","connect","ok","reason","retryable","disconnect","observeConnection","undefined","queryProducts","queryOwned","launchPurchase","detail","observePurchases","acknowledge","consume","openSubscriptionManagement","confirmPriceChange","capabilities","createStoreProvider","options","forceUnsupported","OS"],"sourceRoot":"../../../src","sources":["adapter/createStoreProvider.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,QAAQ,QAAQ,cAAc;AAEvC,SAASC,gBAAgB,QAAQ,kBAAe;AAWhD,MAAMC,wBAA8C,GAAG;EACtDC,qBAAqB,EAAE,KAAK;EAC5BC,kBAAkB,EAAE,KAAK;EACzBC,+BAA+B,EAAE,KAAK;EACtCC,6BAA6B,EAAE,KAAK;EACpCC,4BAA4B,EAAE,KAAK;EACnC;EACAC,uBAAuB,EAAE,KAAK;EAC9BC,gCAAgC,EAAE;AACnC,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,yBAAyBA,CAAA,EAAiB;EAClD,OAAO;IACN,MAAMC,OAAOA,CAAA,EAAoC;MAChD,OAAO;QAAEC,EAAE,EAAE,KAAK;QAAEC,MAAM,EAAE,sBAAsB;QAAEC,SAAS,EAAE;MAAM,CAAC;IACvE,CAAC;IACD,MAAMC,UAAUA,CAAA,EAAkB;MACjC;IAAA,CACA;IACDC,iBAAiBA,CAAA,EAAgB;MAChC,OAAO,MAAMC,SAAS;IACvB,CAAC;IACD,MAAMC,aAAaA,CAAA,EAA+B;MACjD,OAAO,EAAE;IACV,CAAC;IACD,MAAMC,UAAUA,CAAA,EAAgC;MAC/C,OAAO,EAAE;IACV,CAAC;IACD,MAAMC,cAAcA,CAAA,EAAqC;MACxD,OAAO;QAAER,EAAE,EAAE,KAAK;QAAEC,MAAM,EAAE,WAAW;QAAEQ,MAAM,EAAE;MAAuB,CAAC;IAC1E,CAAC;IACDC,gBAAgBA,CAAA,EAAgB;MAC/B,OAAO,MAAML,SAAS;IACvB,CAAC;IACD,MAAMM,WAAWA,CAAA,EAAkB;MAClC;IAAA,CACA;IACD,MAAMC,OAAOA,CAAA,EAAkB;MAC9B;IAAA,CACA;IACD,MAAMC,0BAA0BA,CAAA,EAAkB;MACjD;IAAA,CACA;IACD,MAAMC,kBAAkBA,CAAA,EAAwC;MAC/D,OAAO;QAAEd,EAAE,EAAE,KAAK;QAAEC,MAAM,EAAE;MAAY,CAAC;IAC1C,CAAC;IACDc,YAAY,EAAEA,CAAA,KAAMzB;EACrB,CAAC;AACF;AAYA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAAS0B,mBAAmBA,CAACC,OAA6B,GAAG,CAAC,CAAC,EAAgB;EACrF,IAAIA,OAAO,CAACC,gBAAgB,EAAE;IAC7B,OAAOpB,yBAAyB,CAAC,CAAC;EACnC;EACA,IAAIV,QAAQ,CAAC+B,EAAE,KAAK,SAAS,EAAE;IAC9B,OAAO9B,gBAAgB,CAAC,CAAC;EAC1B;EACA,OAAOS,yBAAyB,CAAC,CAAC;AACnC;;AAEA;AACA,SAASA,yBAAyB","ignoreList":[]}
|
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Android adapter over `react-native-iap` (Play Billing).
|
|
5
|
+
*
|
|
6
|
+
* **The only file in this package that touches the billing library.** Everything
|
|
7
|
+
* above it talks to `ProviderPort`, which is what keeps the binding replaceable
|
|
8
|
+
* and lets an iOS adapter be added without changing a consumer call (FR-002,
|
|
9
|
+
* FR-007). ESLint enforces that boundary.
|
|
10
|
+
*
|
|
11
|
+
* ## Verified against react-native-iap 16.7.3
|
|
12
|
+
*
|
|
13
|
+
* 0.3.0 was written before the binding was installed, from its documentation, and
|
|
14
|
+
* no purchase could complete on a device. Checked against the installed 16.7.3
|
|
15
|
+
* source for 0.3.1, two facts shape the purchase path:
|
|
16
|
+
*
|
|
17
|
+
* - The request is keyed by store: `google` / `apple`. 0.3.0 sent `android`, which
|
|
18
|
+
* the binding rejects (`empty-sku-list`) before Play opens. The request type is
|
|
19
|
+
* now the binding's own `RequestPurchaseProps`, so a renamed key fails to
|
|
20
|
+
* typecheck here instead of failing on a user's device.
|
|
21
|
+
* - On Android `requestPurchase` resolves with an **empty list** once the flow
|
|
22
|
+
* ends, whatever happened. The outcome (bought, pending, cancelled, failed)
|
|
23
|
+
* arrives only through `purchaseUpdatedListener` / `purchaseErrorListener`, so
|
|
24
|
+
* `launchPurchase` waits for those events.
|
|
25
|
+
*
|
|
26
|
+
* The module is still required lazily, and `IapModule` still names exactly the
|
|
27
|
+
* surface used. `__tests__/iap-adapter.test.ts` drives this file through a fake
|
|
28
|
+
* binding that behaves as 16.7.3 does; the rest of the suite uses the fake store.
|
|
29
|
+
*
|
|
30
|
+
* ## Known upstream defect this guards against
|
|
31
|
+
*
|
|
32
|
+
* openiap#408: the Android bridge did not clear its internal `isInitialized` flag
|
|
33
|
+
* on disconnect, so `connected` stayed true, later calls failed with
|
|
34
|
+
* `E_NOT_PREPARED`, and `reconnect()` reported success without rebuilding
|
|
35
|
+
* anything. This adapter therefore (a) tracks connection state itself rather than
|
|
36
|
+
* trusting the binding's flag, and (b) always performs a full
|
|
37
|
+
* `endConnection` + `initConnection` cycle instead of calling any reconnect
|
|
38
|
+
* shortcut.
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
import { createListenerSet, lazyPeer } from '@chipmobilesdk/rn-core';
|
|
42
|
+
import { mapErrorCode, normalizeProduct, normalizePurchase } from "./iapShapes.js";
|
|
43
|
+
import { PaymentError, redact } from "../diagnostics/errors.js";
|
|
44
|
+
// Translation lives in `iapShapes`; it is published from here, where every
|
|
45
|
+
// consumer has always imported it from.
|
|
46
|
+
export { toProviderPurchaseState } from "./iapShapes.js";
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Exactly what this adapter needs from the binding.
|
|
50
|
+
*
|
|
51
|
+
* Declared narrowly on purpose: it documents the coupling, and it means a binding
|
|
52
|
+
* upgrade that changes one of these shapes fails to typecheck here instead of
|
|
53
|
+
* failing silently at runtime on a user's device.
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* How long to wait for the outcome event after `requestPurchase` has resolved.
|
|
58
|
+
* The binding emits the event before or as it resolves, so this only bounds the
|
|
59
|
+
* case where none ever comes; it never runs while the user is in Play's UI.
|
|
60
|
+
*/
|
|
61
|
+
const RESULT_EVENT_GRACE_MS = 2_000;
|
|
62
|
+
|
|
63
|
+
/** Play's replacement modes, by the codes the engine passes (`engine/subscriptions.ts`). */
|
|
64
|
+
const REPLACEMENT_MODES = {
|
|
65
|
+
WITH_TIME_PRORATION: 'with-time-proration',
|
|
66
|
+
CHARGE_FULL_PRICE: 'charge-full-price',
|
|
67
|
+
CHARGE_PRORATED_PRICE: 'charge-prorated-price',
|
|
68
|
+
DEFERRED: 'deferred'
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/** The request in the binding's 16.7 shape: keyed `google`, not `android`. */
|
|
72
|
+
export function toRequestProps(request) {
|
|
73
|
+
const google = {
|
|
74
|
+
skus: [request.storeProductId],
|
|
75
|
+
...(request.obfuscatedAccountId ? {
|
|
76
|
+
obfuscatedAccountId: request.obfuscatedAccountId
|
|
77
|
+
} : {})
|
|
78
|
+
};
|
|
79
|
+
if (request.productType !== 'subscription') {
|
|
80
|
+
return {
|
|
81
|
+
request: {
|
|
82
|
+
google
|
|
83
|
+
},
|
|
84
|
+
type: 'in-app'
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
const replacementMode = request.prorationMode ? REPLACEMENT_MODES[request.prorationMode] : undefined;
|
|
88
|
+
return {
|
|
89
|
+
request: {
|
|
90
|
+
google: {
|
|
91
|
+
...google,
|
|
92
|
+
...(request.offerKey ? {
|
|
93
|
+
subscriptionOffers: [{
|
|
94
|
+
sku: request.storeProductId,
|
|
95
|
+
offerToken: request.offerKey
|
|
96
|
+
}]
|
|
97
|
+
} : {}),
|
|
98
|
+
// A plan change: the token of the purchase being replaced, and — for
|
|
99
|
+
// the replacement mode to apply — its product id (Billing 8.1+).
|
|
100
|
+
...(request.replacePurchaseToken ? {
|
|
101
|
+
purchaseToken: request.replacePurchaseToken
|
|
102
|
+
} : {}),
|
|
103
|
+
...(request.replacePurchaseToken && request.replaceStoreProductId && replacementMode ? {
|
|
104
|
+
subscriptionProductReplacementParams: {
|
|
105
|
+
oldProductId: request.replaceStoreProductId,
|
|
106
|
+
replacementMode
|
|
107
|
+
}
|
|
108
|
+
} : {})
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
type: 'subs'
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
const iapPeer = lazyPeer('react-native-iap', () => {
|
|
115
|
+
// Inside `try`, so Metro bundles an app that leaves this optional peer out.
|
|
116
|
+
try {
|
|
117
|
+
return require('react-native-iap');
|
|
118
|
+
} catch (cause) {
|
|
119
|
+
throw cause;
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
function loadModule() {
|
|
123
|
+
return iapPeer.require((peer, cause) => new PaymentError({
|
|
124
|
+
code: 'PAYMENT_UNAVAILABLE',
|
|
125
|
+
message: `${peer} is not installed or its native module is not linked`,
|
|
126
|
+
operation: 'initialize',
|
|
127
|
+
cause: redact(cause)
|
|
128
|
+
}));
|
|
129
|
+
}
|
|
130
|
+
const ANDROID_CAPABILITIES = {
|
|
131
|
+
supportsSubscriptions: true,
|
|
132
|
+
supportsPlanChange: true,
|
|
133
|
+
supportsPriceChangeConfirmation: false,
|
|
134
|
+
/**
|
|
135
|
+
* False, and this is a platform fact rather than a gap in this adapter.
|
|
136
|
+
*
|
|
137
|
+
* Client-side Play Billing cannot separate grace period from account hold: a
|
|
138
|
+
* grace-period subscription is still returned as active, and one in account
|
|
139
|
+
* hold stops being returned at all — indistinguishable from expired, cancelled,
|
|
140
|
+
* or refunded. The entitlement layer reads this flag and reports
|
|
141
|
+
* `indeterminate` rather than inventing a distinction (research.md R5).
|
|
142
|
+
*/
|
|
143
|
+
reportsGraceAndHoldDistinctly: false,
|
|
144
|
+
supportsExternalTransactions: false,
|
|
145
|
+
/** This one really does move money, which is what arms the environment guard. */
|
|
146
|
+
createsRealTransactions: true,
|
|
147
|
+
/** The outcome event comes only when the user leaves Play's purchase UI. */
|
|
148
|
+
purchaseOutcomeIncludesStoreTime: true
|
|
149
|
+
};
|
|
150
|
+
export function createIapAdapter(options = {}) {
|
|
151
|
+
let iap = options.module;
|
|
152
|
+
|
|
153
|
+
/** Tracked here, never read from the binding — see the openiap#408 note above. */
|
|
154
|
+
let connected = false;
|
|
155
|
+
const connectionListeners = createListenerSet();
|
|
156
|
+
const purchaseListeners = createListenerSet();
|
|
157
|
+
/** Only an in-flight `launchPurchase` listens here; see there. */
|
|
158
|
+
const purchaseErrorListeners = createListenerSet();
|
|
159
|
+
let updateSub;
|
|
160
|
+
let errorSub;
|
|
161
|
+
const module = () => {
|
|
162
|
+
if (!iap) {
|
|
163
|
+
iap = loadModule();
|
|
164
|
+
}
|
|
165
|
+
return iap;
|
|
166
|
+
};
|
|
167
|
+
const notifyConnection = (next, reason) => {
|
|
168
|
+
if (connected === next) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
connected = next;
|
|
172
|
+
connectionListeners.notify(next, reason);
|
|
173
|
+
};
|
|
174
|
+
const attachListeners = () => {
|
|
175
|
+
// Every connect attaches, so whatever an earlier connect left must go first.
|
|
176
|
+
// Overwriting the handles orphaned the old native listeners, which kept
|
|
177
|
+
// firing — every purchase update reached the engine once per connect.
|
|
178
|
+
detachListeners();
|
|
179
|
+
const mod = module();
|
|
180
|
+
updateSub = mod.purchaseUpdatedListener(raw => {
|
|
181
|
+
purchaseListeners.notify(normalizePurchase(raw));
|
|
182
|
+
});
|
|
183
|
+
errorSub = mod.purchaseErrorListener(error => {
|
|
184
|
+
// A `not-prepared` error is the one signal the binding gives that the
|
|
185
|
+
// service went away underneath us, so it is treated as a disconnect
|
|
186
|
+
// rather than as a purchase failure.
|
|
187
|
+
if (mapErrorCode(error.code) === 'not_ready') {
|
|
188
|
+
notifyConnection(false, 'not_prepared');
|
|
189
|
+
}
|
|
190
|
+
purchaseErrorListeners.notify(error);
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
const detachListeners = () => {
|
|
194
|
+
updateSub?.remove();
|
|
195
|
+
updateSub = undefined;
|
|
196
|
+
errorSub?.remove();
|
|
197
|
+
errorSub = undefined;
|
|
198
|
+
};
|
|
199
|
+
return {
|
|
200
|
+
async connect() {
|
|
201
|
+
try {
|
|
202
|
+
const mod = module();
|
|
203
|
+
// Always a full cycle. The binding's own reconnect has reported success
|
|
204
|
+
// without rebuilding anything, so we never rely on it (openiap#408).
|
|
205
|
+
if (connected) {
|
|
206
|
+
await mod.endConnection().catch(() => undefined);
|
|
207
|
+
connected = false;
|
|
208
|
+
}
|
|
209
|
+
const ok = await mod.initConnection();
|
|
210
|
+
if (!ok) {
|
|
211
|
+
return {
|
|
212
|
+
ok: false,
|
|
213
|
+
reason: 'no_billing_service',
|
|
214
|
+
retryable: true
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
attachListeners();
|
|
218
|
+
notifyConnection(true);
|
|
219
|
+
return {
|
|
220
|
+
ok: true
|
|
221
|
+
};
|
|
222
|
+
} catch (error) {
|
|
223
|
+
const code = error.code;
|
|
224
|
+
// A missing or too-old Play Services install is not the same as a
|
|
225
|
+
// transient error, and the app shows different things for each (FR-021).
|
|
226
|
+
if (code === 'E_IAP_NOT_AVAILABLE' || code === 'iap-not-available') {
|
|
227
|
+
return {
|
|
228
|
+
ok: false,
|
|
229
|
+
reason: 'no_billing_service',
|
|
230
|
+
retryable: false
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
if (code === 'E_SERVICE_ERROR') {
|
|
234
|
+
return {
|
|
235
|
+
ok: false,
|
|
236
|
+
reason: 'billing_service_outdated',
|
|
237
|
+
retryable: true
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
return {
|
|
241
|
+
ok: false,
|
|
242
|
+
reason: 'store_error',
|
|
243
|
+
retryable: true
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
async disconnect() {
|
|
248
|
+
detachListeners();
|
|
249
|
+
try {
|
|
250
|
+
await module().endConnection();
|
|
251
|
+
} catch {
|
|
252
|
+
// Already down; nothing to tear down.
|
|
253
|
+
}
|
|
254
|
+
notifyConnection(false, 'disconnect');
|
|
255
|
+
},
|
|
256
|
+
observeConnection(listener) {
|
|
257
|
+
return connectionListeners.add(listener);
|
|
258
|
+
},
|
|
259
|
+
async queryProducts(storeProductIds, productType) {
|
|
260
|
+
const raw = await module().fetchProducts({
|
|
261
|
+
skus: storeProductIds,
|
|
262
|
+
type: productType === 'subscription' ? 'subs' : 'in-app'
|
|
263
|
+
});
|
|
264
|
+
return raw.map(product => normalizeProduct(product, productType));
|
|
265
|
+
},
|
|
266
|
+
async queryOwned() {
|
|
267
|
+
const raw = await module().getAvailablePurchases();
|
|
268
|
+
// Pending purchases are mapped through, flagged rather than filtered: the
|
|
269
|
+
// engine needs to see them to raise the pending signal (FR-038).
|
|
270
|
+
return raw.map(normalizePurchase);
|
|
271
|
+
},
|
|
272
|
+
/**
|
|
273
|
+
* Settles on the first outcome event for this product: a purchase update
|
|
274
|
+
* (bought or pending) or a purchase error (cancelled, already owned, …).
|
|
275
|
+
*
|
|
276
|
+
* The binding's promise is not the outcome: on Android it resolves with an
|
|
277
|
+
* empty list when the flow ends, whatever happened. Its listeners also feed
|
|
278
|
+
* `observePurchases`, so the engine sees a bought purchase twice — here and
|
|
279
|
+
* as a store update — and grants it once (FR-044).
|
|
280
|
+
*/
|
|
281
|
+
launchPurchase(request) {
|
|
282
|
+
const sku = request.storeProductId;
|
|
283
|
+
return new Promise(resolve => {
|
|
284
|
+
let settled = false;
|
|
285
|
+
let grace;
|
|
286
|
+
const onPurchase = purchase => {
|
|
287
|
+
if (purchase.storeProductId === sku) {
|
|
288
|
+
finish({
|
|
289
|
+
ok: true,
|
|
290
|
+
purchase
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
const onError = error => {
|
|
295
|
+
if (error.productId && error.productId !== sku) {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
finish({
|
|
299
|
+
ok: false,
|
|
300
|
+
reason: mapErrorCode(error.code),
|
|
301
|
+
detail: error.code
|
|
302
|
+
});
|
|
303
|
+
};
|
|
304
|
+
const fail = error => {
|
|
305
|
+
const code = error?.code;
|
|
306
|
+
finish({
|
|
307
|
+
ok: false,
|
|
308
|
+
reason: mapErrorCode(code),
|
|
309
|
+
detail: code
|
|
310
|
+
});
|
|
311
|
+
};
|
|
312
|
+
function finish(outcome) {
|
|
313
|
+
if (settled) {
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
settled = true;
|
|
317
|
+
clearTimeout(grace);
|
|
318
|
+
stopPurchase();
|
|
319
|
+
stopError();
|
|
320
|
+
resolve(outcome);
|
|
321
|
+
}
|
|
322
|
+
const stopPurchase = purchaseListeners.add(onPurchase);
|
|
323
|
+
const stopError = purchaseErrorListeners.add(onError);
|
|
324
|
+
try {
|
|
325
|
+
module().requestPurchase(toRequestProps(request)).then(() => {
|
|
326
|
+
if (!settled) {
|
|
327
|
+
grace = setTimeout(() => finish({
|
|
328
|
+
ok: false,
|
|
329
|
+
reason: 'store_error',
|
|
330
|
+
detail: 'no purchase event'
|
|
331
|
+
}), RESULT_EVENT_GRACE_MS);
|
|
332
|
+
}
|
|
333
|
+
}, fail);
|
|
334
|
+
} catch (error) {
|
|
335
|
+
fail(error);
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
},
|
|
339
|
+
observePurchases(listener) {
|
|
340
|
+
return purchaseListeners.add(listener);
|
|
341
|
+
},
|
|
342
|
+
async acknowledge(token) {
|
|
343
|
+
// Idempotent at the store: acknowledging an already-acknowledged purchase
|
|
344
|
+
// is accepted, which is what FR-044 relies on.
|
|
345
|
+
await module().finishTransaction({
|
|
346
|
+
purchase: {
|
|
347
|
+
purchaseToken: token
|
|
348
|
+
},
|
|
349
|
+
isConsumable: false
|
|
350
|
+
});
|
|
351
|
+
},
|
|
352
|
+
async consume(token) {
|
|
353
|
+
await module().finishTransaction({
|
|
354
|
+
purchase: {
|
|
355
|
+
purchaseToken: token
|
|
356
|
+
},
|
|
357
|
+
isConsumable: true
|
|
358
|
+
});
|
|
359
|
+
},
|
|
360
|
+
async openSubscriptionManagement(storeProductId) {
|
|
361
|
+
// The store's own screen. Platforms forbid a self-built cancellation
|
|
362
|
+
// screen, so there is deliberately no alternative path here (FR-066).
|
|
363
|
+
const mod = module();
|
|
364
|
+
if (!mod.deepLinkToSubscriptions) {
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
await mod.deepLinkToSubscriptions({
|
|
368
|
+
skuAndroid: storeProductId
|
|
369
|
+
});
|
|
370
|
+
},
|
|
371
|
+
async confirmPriceChange() {
|
|
372
|
+
// Play has no client-side price-change confirmation flow; it notifies the
|
|
373
|
+
// user itself. Reported as unsupported rather than faked, matching
|
|
374
|
+
// `supportsPriceChangeConfirmation: false` (FR-067).
|
|
375
|
+
return {
|
|
376
|
+
ok: false,
|
|
377
|
+
reason: 'store_error'
|
|
378
|
+
};
|
|
379
|
+
},
|
|
380
|
+
capabilities: () => ANDROID_CAPABILITIES
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
//# sourceMappingURL=iap-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createListenerSet","lazyPeer","mapErrorCode","normalizeProduct","normalizePurchase","PaymentError","redact","toProviderPurchaseState","RESULT_EVENT_GRACE_MS","REPLACEMENT_MODES","WITH_TIME_PRORATION","CHARGE_FULL_PRICE","CHARGE_PRORATED_PRICE","DEFERRED","toRequestProps","request","google","skus","storeProductId","obfuscatedAccountId","productType","type","replacementMode","prorationMode","undefined","offerKey","subscriptionOffers","sku","offerToken","replacePurchaseToken","purchaseToken","replaceStoreProductId","subscriptionProductReplacementParams","oldProductId","iapPeer","require","cause","loadModule","peer","code","message","operation","ANDROID_CAPABILITIES","supportsSubscriptions","supportsPlanChange","supportsPriceChangeConfirmation","reportsGraceAndHoldDistinctly","supportsExternalTransactions","createsRealTransactions","purchaseOutcomeIncludesStoreTime","createIapAdapter","options","iap","module","connected","connectionListeners","purchaseListeners","purchaseErrorListeners","updateSub","errorSub","notifyConnection","next","reason","notify","attachListeners","detachListeners","mod","purchaseUpdatedListener","raw","purchaseErrorListener","error","remove","connect","endConnection","catch","ok","initConnection","retryable","disconnect","observeConnection","listener","add","queryProducts","storeProductIds","fetchProducts","map","product","queryOwned","getAvailablePurchases","launchPurchase","Promise","resolve","settled","grace","onPurchase","purchase","finish","onError","productId","detail","fail","outcome","clearTimeout","stopPurchase","stopError","requestPurchase","then","setTimeout","observePurchases","acknowledge","token","finishTransaction","isConsumable","consume","openSubscriptionManagement","deepLinkToSubscriptions","skuAndroid","confirmPriceChange","capabilities"],"sourceRoot":"../../../src","sources":["adapter/iap-adapter.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,iBAAiB,EAAEC,QAAQ,QAAQ,wBAAwB;AAKpE,SACCC,YAAY,EACZC,gBAAgB,EAChBC,iBAAiB,QAIX,gBAAa;AACpB,SAASC,YAAY,EAAEC,MAAM,QAAQ,0BAAuB;AAc5D;AACA;AACA,SAASC,uBAAuB,QAAQ,gBAAa;;AAErD;AACA;AACA;AACA;AACA;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