@chipmobilesdk/rn-payment 0.4.0 → 0.5.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 +482 -334
- package/README.md +925 -897
- package/package.json +52 -54
- package/skills/sdk-rn-payment/SKILL.md +175 -174
- package/src/adapter/createStoreProvider.ts +116 -118
- package/src/adapter/iap-adapter.ts +627 -660
- package/src/adapter/port.ts +209 -215
- package/src/config/types.ts +298 -310
- package/src/config/validate.ts +224 -232
- package/src/core/mutex.ts +25 -128
- package/src/core/retry.ts +95 -133
- package/src/core/timers.ts +272 -267
- package/src/diagnostics/errors.ts +124 -117
- package/src/diagnostics/events.ts +282 -266
- package/src/diagnostics/messageKeys.ts +93 -95
- package/src/engine/engine.ts +921 -999
- package/src/engine/finalize.ts +343 -346
- package/src/engine/foreground.ts +29 -0
- package/src/engine/products.ts +259 -259
- package/src/engine/purchase.ts +589 -614
- package/src/engine/subscriptions.ts +146 -157
- package/src/entitlements/aggregate.ts +261 -242
- package/src/entitlements/mapping.ts +67 -67
- package/src/entitlements/policy.ts +121 -129
- package/src/index.ts +5 -9
- package/src/persistence/mmkv-store.ts +158 -158
- package/src/persistence/snapshot.ts +220 -247
- package/src/react/PaymentProvider.tsx +90 -79
- package/src/react/hooks.ts +236 -274
- package/src/testing/conformance.ts +169 -0
- package/src/testing/fakeStore.ts +360 -393
- package/src/testing/index.ts +19 -10
|
@@ -1,95 +1,93 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Stable, localizable message keys with English default copy (FR-084, FR-085).
|
|
3
|
-
*
|
|
4
|
-
* The package takes no i18n runtime dependency: consuming apps map these keys to
|
|
5
|
-
* localized strings through whatever i18n system they already run. This is plain
|
|
6
|
-
* data, and the package never resolves or renders it.
|
|
7
|
-
*
|
|
8
|
-
* Message keys are **public API**: renaming one is a breaking change, on the
|
|
9
|
-
* same footing as an error code (FR-078).
|
|
10
|
-
*
|
|
11
|
-
* User-actionable copy and developer/configuration copy are kept in separate
|
|
12
|
-
* maps so an app cannot accidentally show "Payment catalog is invalid" to a
|
|
13
|
-
* customer — a configuration fault is a developer's problem, not a user's.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
/** Copy an end user may reasonably be shown. */
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
'payment.
|
|
21
|
-
'payment.
|
|
22
|
-
'payment.restore
|
|
23
|
-
'payment.
|
|
24
|
-
'payment.
|
|
25
|
-
'payment.error.
|
|
26
|
-
'payment.error.
|
|
27
|
-
'payment.
|
|
28
|
-
'payment.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
'payment.config.
|
|
36
|
-
'payment.config.
|
|
37
|
-
'payment.config.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
export type
|
|
45
|
-
export type
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
'payment.state.
|
|
50
|
-
'payment.
|
|
51
|
-
'payment.restore
|
|
52
|
-
'payment.restore.
|
|
53
|
-
'payment.
|
|
54
|
-
'payment.error.
|
|
55
|
-
|
|
56
|
-
'payment.error.unavailable': "Purchases aren't available on this device",
|
|
57
|
-
'payment.error.disabled': 'Purchases are currently unavailable',
|
|
58
|
-
'payment.subscription.grace': "There's a problem with your payment method",
|
|
59
|
-
'payment.subscription.hold':
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
'payment.config.
|
|
65
|
-
'payment.config.
|
|
66
|
-
'
|
|
67
|
-
'payment.config.
|
|
68
|
-
'
|
|
69
|
-
'payment.config.
|
|
70
|
-
'
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
/** True for keys safe to show an end user. Lets an app assert that at its boundary. */
|
|
91
|
-
export function isUserMessageKey(
|
|
92
|
-
key
|
|
93
|
-
|
|
94
|
-
return key in DEFAULT_USER_MESSAGES;
|
|
95
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Stable, localizable message keys with English default copy (FR-084, FR-085).
|
|
3
|
+
*
|
|
4
|
+
* The package takes no i18n runtime dependency: consuming apps map these keys to
|
|
5
|
+
* localized strings through whatever i18n system they already run. This is plain
|
|
6
|
+
* data, and the package never resolves or renders it.
|
|
7
|
+
*
|
|
8
|
+
* Message keys are **public API**: renaming one is a breaking change, on the
|
|
9
|
+
* same footing as an error code (FR-078).
|
|
10
|
+
*
|
|
11
|
+
* User-actionable copy and developer/configuration copy are kept in separate
|
|
12
|
+
* maps so an app cannot accidentally show "Payment catalog is invalid" to a
|
|
13
|
+
* customer — a configuration fault is a developer's problem, not a user's.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** Copy an end user may reasonably be shown. */
|
|
17
|
+
import { defineMessages } from '@chipmobilesdk/rn-core';
|
|
18
|
+
|
|
19
|
+
export interface PaymentUserMessageMap {
|
|
20
|
+
'payment.state.pending': string;
|
|
21
|
+
'payment.state.alreadyOwned': string;
|
|
22
|
+
'payment.action.restore': string;
|
|
23
|
+
'payment.restore.succeeded': string;
|
|
24
|
+
'payment.restore.nothingFound': string;
|
|
25
|
+
'payment.error.cancelled': string;
|
|
26
|
+
'payment.error.network': string;
|
|
27
|
+
'payment.error.unavailable': string;
|
|
28
|
+
'payment.error.disabled': string;
|
|
29
|
+
'payment.subscription.grace': string;
|
|
30
|
+
'payment.subscription.hold': string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Copy for developers and operators. **Never** surfaced to an end user. */
|
|
34
|
+
export interface PaymentDeveloperMessageMap {
|
|
35
|
+
'payment.config.invalidCatalog': string;
|
|
36
|
+
'payment.config.missingStoreId': string;
|
|
37
|
+
'payment.config.productionInNonProductionBuild': string;
|
|
38
|
+
'payment.config.storageUnavailable': string;
|
|
39
|
+
'payment.config.environmentBlocked': string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type PaymentMessageMap = PaymentUserMessageMap & PaymentDeveloperMessageMap;
|
|
43
|
+
|
|
44
|
+
export type PaymentUserMessageKey = keyof PaymentUserMessageMap;
|
|
45
|
+
export type PaymentDeveloperMessageKey = keyof PaymentDeveloperMessageMap;
|
|
46
|
+
export type PaymentMessageKey = keyof PaymentMessageMap;
|
|
47
|
+
|
|
48
|
+
export const DEFAULT_USER_MESSAGES: PaymentUserMessageMap = {
|
|
49
|
+
'payment.state.pending': 'Waiting for your payment to complete',
|
|
50
|
+
'payment.state.alreadyOwned': 'You already own this',
|
|
51
|
+
'payment.action.restore': 'Restore purchases',
|
|
52
|
+
'payment.restore.succeeded': 'Your purchases have been restored',
|
|
53
|
+
'payment.restore.nothingFound': 'No previous purchases found',
|
|
54
|
+
'payment.error.cancelled': 'Purchase cancelled',
|
|
55
|
+
'payment.error.network': "Couldn't reach the store. Check your connection and try again.",
|
|
56
|
+
'payment.error.unavailable': "Purchases aren't available on this device",
|
|
57
|
+
'payment.error.disabled': 'Purchases are currently unavailable',
|
|
58
|
+
'payment.subscription.grace': "There's a problem with your payment method",
|
|
59
|
+
'payment.subscription.hold': 'Your subscription is paused until payment is updated',
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const DEFAULT_DEVELOPER_MESSAGES: PaymentDeveloperMessageMap = {
|
|
63
|
+
'payment.config.invalidCatalog': 'Payment catalog is invalid',
|
|
64
|
+
'payment.config.missingStoreId': 'Product is missing a store identifier for this platform',
|
|
65
|
+
'payment.config.productionInNonProductionBuild':
|
|
66
|
+
'Production payment configuration in a non-production build',
|
|
67
|
+
'payment.config.storageUnavailable':
|
|
68
|
+
'Local storage unavailable; entitlements will not survive restart',
|
|
69
|
+
'payment.config.environmentBlocked':
|
|
70
|
+
'Purchase blocked: this environment may not create a real transaction',
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The catalog as an rn-core message set. Register `paymentMessages.user` with
|
|
75
|
+
* rn-i18n to translate it like app copy; the developer copy stays out of bundles.
|
|
76
|
+
*/
|
|
77
|
+
export const paymentMessages = defineMessages({
|
|
78
|
+
user: DEFAULT_USER_MESSAGES,
|
|
79
|
+
developer: DEFAULT_DEVELOPER_MESSAGES,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
export const DEFAULT_MESSAGES: PaymentMessageMap = paymentMessages.defaults;
|
|
83
|
+
|
|
84
|
+
/** Every user-actionable key, for an app building its translation resource. */
|
|
85
|
+
export const USER_MESSAGE_KEYS = paymentMessages.userKeys as PaymentUserMessageKey[];
|
|
86
|
+
|
|
87
|
+
/** Every developer-facing key, so an app can exclude them from user-visible bundles. */
|
|
88
|
+
export const DEVELOPER_MESSAGE_KEYS = paymentMessages.developerKeys as PaymentDeveloperMessageKey[];
|
|
89
|
+
|
|
90
|
+
/** True for keys safe to show an end user. Lets an app assert that at its boundary. */
|
|
91
|
+
export function isUserMessageKey(key: PaymentMessageKey): key is PaymentUserMessageKey {
|
|
92
|
+
return paymentMessages.audienceOf(key) === 'user';
|
|
93
|
+
}
|