expo-iap 4.5.2 → 4.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/android/src/main/java/expo/modules/iap/ExpoIapModule.kt +33 -0
- package/build/index.d.ts +2 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js.map +1 -1
- package/build/index.kepler.d.ts +1 -1
- package/build/index.kepler.d.ts.map +1 -1
- package/build/index.kepler.js +1 -1
- package/build/index.kepler.js.map +1 -1
- package/build/modules/android.d.ts +12 -6
- package/build/modules/android.d.ts.map +1 -1
- package/build/modules/android.js +45 -8
- package/build/modules/android.js.map +1 -1
- package/build/modules/ios.d.ts +2 -0
- package/build/modules/ios.d.ts.map +1 -1
- package/build/modules/ios.js +40 -1
- package/build/modules/ios.js.map +1 -1
- package/build/types.d.ts +15 -0
- package/build/types.d.ts.map +1 -1
- package/build/types.js.map +1 -1
- package/build/useIAP.d.ts +1 -0
- package/build/useIAP.d.ts.map +1 -1
- package/build/useIAP.js +3 -1
- package/build/useIAP.js.map +1 -1
- package/expo-module.config.json +1 -0
- package/openiap-versions.json +2 -2
- package/package.json +1 -1
- package/src/index.kepler.ts +3 -2
- package/src/index.ts +2 -1
- package/src/modules/android.ts +49 -10
- package/src/modules/ios.ts +41 -1
- package/src/types.ts +15 -0
- package/src/useIAP.ts +4 -0
package/build/modules/android.js
CHANGED
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
// External dependencies
|
|
2
|
-
import { Linking } from 'react-native';
|
|
2
|
+
import { Linking, Platform } from 'react-native';
|
|
3
3
|
// Internal modules
|
|
4
4
|
import ExpoIapModule from '../ExpoIapModule';
|
|
5
|
+
import { isVegaOS } from '../vega';
|
|
5
6
|
const nativeAndroidModule = ExpoIapModule;
|
|
7
|
+
/**
|
|
8
|
+
* Enforce the documented Android-only contract. Vega OS is treated as an
|
|
9
|
+
* Android store runtime (matching `isAndroidStoreRuntime` in src/index.ts),
|
|
10
|
+
* so it passes through. Without this guard, calling a suffixed wrapper on
|
|
11
|
+
* another platform falls through to the native proxy and surfaces as an
|
|
12
|
+
* opaque `TypeError: ExpoIapModule.<name> is not a function` instead of the
|
|
13
|
+
* promised platform error.
|
|
14
|
+
*/
|
|
15
|
+
const requireAndroidPlatform = (methodName) => {
|
|
16
|
+
if (Platform.OS !== 'android' && !isVegaOS()) {
|
|
17
|
+
throw new Error(`${methodName} is only available on Android and Vega OS`);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
6
20
|
// Type guards
|
|
7
21
|
export function isProductAndroid(item) {
|
|
8
22
|
return (item != null &&
|
|
@@ -85,6 +99,7 @@ export const validateReceiptAndroid = async ({ packageName, productId, productTo
|
|
|
85
99
|
* @see {@link https://openiap.dev/docs/apis/android/consume-purchase-android}
|
|
86
100
|
*/
|
|
87
101
|
export const consumePurchaseAndroid = async (purchaseToken) => {
|
|
102
|
+
requireAndroidPlatform('consumePurchaseAndroid');
|
|
88
103
|
const result = await ExpoIapModule.consumePurchaseAndroid(purchaseToken);
|
|
89
104
|
if (typeof result === 'boolean') {
|
|
90
105
|
return result;
|
|
@@ -101,14 +116,16 @@ export const consumePurchaseAndroid = async (purchaseToken) => {
|
|
|
101
116
|
throw new Error(`consumePurchaseAndroid returned an unexpected response payload: ${JSON.stringify(result)}`);
|
|
102
117
|
};
|
|
103
118
|
/**
|
|
104
|
-
* Acknowledge a
|
|
119
|
+
* Acknowledge a non-consumable purchase or subscription (Android only).
|
|
105
120
|
* @param {Object} params - The parameters object
|
|
106
121
|
* @param {string} params.token - The product's token (on Android)
|
|
107
122
|
* @returns {Promise<VoidResult | void>}
|
|
123
|
+
* @throws Error if called on a non-Android platform
|
|
108
124
|
*
|
|
109
125
|
* @see {@link https://openiap.dev/docs/apis/android/acknowledge-purchase-android}
|
|
110
126
|
*/
|
|
111
127
|
export const acknowledgePurchaseAndroid = async (purchaseToken) => {
|
|
128
|
+
requireAndroidPlatform('acknowledgePurchaseAndroid');
|
|
112
129
|
const result = await ExpoIapModule.acknowledgePurchaseAndroid(purchaseToken);
|
|
113
130
|
if (typeof result === 'boolean') {
|
|
114
131
|
return result;
|
|
@@ -125,14 +142,23 @@ export const acknowledgePurchaseAndroid = async (purchaseToken) => {
|
|
|
125
142
|
return true;
|
|
126
143
|
};
|
|
127
144
|
/**
|
|
128
|
-
* Open the Google Play
|
|
129
|
-
*
|
|
130
|
-
*
|
|
145
|
+
* Open the Google Play offer/promo code redemption flow so the user can enter a code (Android only).
|
|
146
|
+
* On Play builds, launches the Play Store redeem page. A listener can receive
|
|
147
|
+
* the purchase while the app has an active billing connection; reconcile
|
|
148
|
+
* available purchases when the app resumes. Unsupported store flavors return false.
|
|
149
|
+
* Does not require the billing client to be initialized (no Play Billing version requirement).
|
|
150
|
+
* Android counterpart of presentCodeRedemptionSheetIOS.
|
|
131
151
|
*
|
|
132
|
-
* @returns
|
|
152
|
+
* @returns Promise resolving to true when launched, or false when unsupported
|
|
153
|
+
*
|
|
154
|
+
* @see {@link https://openiap.dev/docs/apis/android/open-redeem-offer-code-android}
|
|
133
155
|
*/
|
|
134
156
|
export const openRedeemOfferCodeAndroid = async () => {
|
|
135
|
-
|
|
157
|
+
requireAndroidPlatform('openRedeemOfferCodeAndroid');
|
|
158
|
+
if (isVegaOS()) {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
return ExpoIapModule.openRedeemOfferCodeAndroid();
|
|
136
162
|
};
|
|
137
163
|
/**
|
|
138
164
|
* Check if alternative billing is available for this user/device (Android only).
|
|
@@ -154,6 +180,7 @@ export const openRedeemOfferCodeAndroid = async () => {
|
|
|
154
180
|
* @see {@link https://openiap.dev/docs/apis/android/check-alternative-billing-availability-android}
|
|
155
181
|
*/
|
|
156
182
|
export const checkAlternativeBillingAvailabilityAndroid = async () => {
|
|
183
|
+
requireAndroidPlatform('checkAlternativeBillingAvailabilityAndroid');
|
|
157
184
|
return ExpoIapModule.checkAlternativeBillingAvailabilityAndroid();
|
|
158
185
|
};
|
|
159
186
|
/**
|
|
@@ -183,6 +210,7 @@ export const checkAlternativeBillingAvailabilityAndroid = async () => {
|
|
|
183
210
|
* @see {@link https://openiap.dev/docs/apis/android/show-alternative-billing-dialog-android}
|
|
184
211
|
*/
|
|
185
212
|
export const showAlternativeBillingDialogAndroid = async () => {
|
|
213
|
+
requireAndroidPlatform('showAlternativeBillingDialogAndroid');
|
|
186
214
|
return ExpoIapModule.showAlternativeBillingDialogAndroid();
|
|
187
215
|
};
|
|
188
216
|
/**
|
|
@@ -212,6 +240,7 @@ export const showAlternativeBillingDialogAndroid = async () => {
|
|
|
212
240
|
* @see {@link https://openiap.dev/docs/apis/android/create-alternative-billing-token-android}
|
|
213
241
|
*/
|
|
214
242
|
export const createAlternativeBillingTokenAndroid = async (sku) => {
|
|
243
|
+
requireAndroidPlatform('createAlternativeBillingTokenAndroid');
|
|
215
244
|
return ExpoIapModule.createAlternativeBillingTokenAndroid(sku);
|
|
216
245
|
};
|
|
217
246
|
// ============================================================================
|
|
@@ -236,6 +265,7 @@ export const createAlternativeBillingTokenAndroid = async (sku) => {
|
|
|
236
265
|
* @see {@link https://openiap.dev/docs/apis/android/is-billing-program-available-android}
|
|
237
266
|
*/
|
|
238
267
|
export const isBillingProgramAvailableAndroid = async (program) => {
|
|
268
|
+
requireAndroidPlatform('isBillingProgramAvailableAndroid');
|
|
239
269
|
return ExpoIapModule.isBillingProgramAvailableAndroid(program);
|
|
240
270
|
};
|
|
241
271
|
/**
|
|
@@ -248,6 +278,7 @@ export const isBillingProgramAvailableAndroid = async (program) => {
|
|
|
248
278
|
* @see {@link https://openiap.dev/docs/apis/android/get-billing-choice-info-android}
|
|
249
279
|
*/
|
|
250
280
|
export const getBillingChoiceInfoAndroid = async (params = {}) => {
|
|
281
|
+
requireAndroidPlatform('getBillingChoiceInfoAndroid');
|
|
251
282
|
return ExpoIapModule.getBillingChoiceInfoAndroid({
|
|
252
283
|
billingProgram: params.billingProgram ?? 'billing-choice',
|
|
253
284
|
playBillingChoiceImageLayout: params.playBillingChoiceImageLayout ?? 'rectangular-four-by-one',
|
|
@@ -276,6 +307,7 @@ export const getBillingChoiceInfoAndroid = async (params = {}) => {
|
|
|
276
307
|
* @see {@link https://openiap.dev/docs/apis/android/launch-external-link-android}
|
|
277
308
|
*/
|
|
278
309
|
export const launchExternalLinkAndroid = async (params) => {
|
|
310
|
+
requireAndroidPlatform('launchExternalLinkAndroid');
|
|
279
311
|
return ExpoIapModule.launchExternalLinkAndroid(params);
|
|
280
312
|
};
|
|
281
313
|
/**
|
|
@@ -297,7 +329,10 @@ export const launchExternalLinkAndroid = async (params) => {
|
|
|
297
329
|
*
|
|
298
330
|
* @see {@link https://openiap.dev/docs/apis/android/create-billing-program-reporting-details-android}
|
|
299
331
|
*/
|
|
300
|
-
const createBillingProgramReportingDetailsAndroidField = async (args) =>
|
|
332
|
+
const createBillingProgramReportingDetailsAndroidField = async (args) => {
|
|
333
|
+
requireAndroidPlatform('createBillingProgramReportingDetailsAndroid');
|
|
334
|
+
return ExpoIapModule.createBillingProgramReportingDetailsAndroid(args.program, args.developerBillingType ?? null);
|
|
335
|
+
};
|
|
301
336
|
export function createBillingProgramReportingDetailsAndroid(programOrArgs, developerBillingType) {
|
|
302
337
|
const args = typeof programOrArgs === 'string'
|
|
303
338
|
? { program: programOrArgs, developerBillingType }
|
|
@@ -315,6 +350,7 @@ export function createBillingProgramReportingDetailsAndroid(programOrArgs, devel
|
|
|
315
350
|
* @see {@link https://openiap.dev/docs/apis/android/show-billing-program-information-dialog-android}
|
|
316
351
|
*/
|
|
317
352
|
export const showBillingProgramInformationDialogAndroid = async (params) => {
|
|
353
|
+
requireAndroidPlatform('showBillingProgramInformationDialogAndroid');
|
|
318
354
|
return ExpoIapModule.showBillingProgramInformationDialogAndroid({
|
|
319
355
|
billingProgram: params.billingProgram ?? 'billing-choice',
|
|
320
356
|
externalTransactionToken: params.externalTransactionToken,
|
|
@@ -330,6 +366,7 @@ export const showBillingProgramInformationDialogAndroid = async (params) => {
|
|
|
330
366
|
* @see {@link https://openiap.dev/docs/apis/android/show-in-app-messages-android}
|
|
331
367
|
*/
|
|
332
368
|
export const showInAppMessagesAndroid = async (params) => {
|
|
369
|
+
requireAndroidPlatform('showInAppMessagesAndroid');
|
|
333
370
|
return ExpoIapModule.showInAppMessagesAndroid(params ?? null);
|
|
334
371
|
};
|
|
335
372
|
//# sourceMappingURL=android.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"android.js","sourceRoot":"","sources":["../../src/modules/android.ts"],"names":[],"mappings":"AAAA,wBAAwB;AACxB,OAAO,EAAC,OAAO,EAAC,MAAM,cAAc,CAAC;AAErC,mBAAmB;AACnB,OAAO,aAAa,MAAM,kBAAkB,CAAC;AA4B7C,MAAM,mBAAmB,GAAG,aAAoC,CAAC;AAEjE,cAAc;AACd,MAAM,UAAU,gBAAgB,CAC9B,IAAa;IAEb,OAAO,CACL,IAAI,IAAI,IAAI;QACZ,OAAO,IAAI,KAAK,QAAQ;QACxB,UAAU,IAAI,IAAI;QAClB,OAAQ,IAAY,CAAC,QAAQ,KAAK,QAAQ;QACzC,IAAY,CAAC,QAAQ,CAAC,WAAW,EAAE,KAAK,SAAS,CACnD,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,KAAK,EACjD,OAAgC,EACjB,EAAE;IACjB,MAAM,GAAG,GAAG,OAAO,EAAE,UAAU,IAAI,SAAS,CAAC;IAC7C,MAAM,WAAW,GAAG,OAAO,EAAE,kBAAkB,IAAI,SAAS,CAAC;IAE7D,4DAA4D;IAC5D,IAAI,mBAAmB,EAAE,8BAA8B,EAAE,CAAC;QACxD,OAAO,mBAAmB,CAAC,8BAA8B,CAAC;YACxD,UAAU,EAAE,GAAG;YACf,kBAAkB,EAAE,WAAW;SAChC,CAAC,CAAC;IACL,CAAC;IAED,mDAAmD;IACnD,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,MAAM,IAAI,K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KAAK,EAAE,MAAM,EAAE,EAAE;IACnB,OAAO,aAAa,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAC;AACzD,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,gDAAgD,GAElD,KAAK,EACP,IAA6D,EACb,EAAE,CAClD,aAAa,CAAC,2CAA2C,CACvD,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,oBAAoB,IAAI,IAAI,CAClC,CAAC;AASJ,MAAM,UAAU,2CAA2C,CACzD,aAE2D,EAC3D,oBAAyD;IAEzD,MAAM,IAAI,GACR,OAAO,aAAa,KAAK,QAAQ;QAC/B,CAAC,CAAC,EAAC,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAC;QAChD,CAAC,CAAC,aAAa,CAAC;IACpB,OAAO,gDAAgD,CAAC,IAAI,CAAC,CAAC;AAChE,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,0CAA0C,GAEnD,KAAK,EACP,MAAoD,EACrB,EAAE;IACjC,OAAO,aAAa,CAAC,0CAA0C,CAAC;QAC9D,cAAc,EAAE,MAAM,CAAC,cAAc,IAAI,gBAAgB;QACzD,wBAAwB,EAAE,MAAM,CAAC,wBAAwB;KAC1D,CAAC,CAAC;AACL,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAEjC,KAAK,EACP,MAAyC,EACL,EAAE;IACtC,OAAO,aAAa,CAAC,wBAAwB,CAAC,MAAM,IAAI,IAAI,CAAC,CAAC;AAChE,CAAC,CAAC","sourcesContent":["// External dependencies\nimport {Linking} from 'react-native';\n\n// Internal modules\nimport ExpoIapModule from '../ExpoIapModule';\n\n// Types\nimport type {\n BillingChoiceInfoAndroid,\n BillingProgramAndroid,\n BillingProgramInformationDialogParamsAndroid,\n BillingProgramReportingDetailsAndroid,\n BillingResultAndroid,\n DeepLinkOptions,\n DeveloperBillingTypeAndroid,\n GetBillingChoiceInfoParamsAndroid,\n InAppMessageParamsAndroid,\n InAppMessageResultAndroid,\n MutationCreateBillingProgramReportingDetailsAndroidArgs,\n MutationField,\n QueryField,\n VerifyPurchaseResultAndroid,\n} from '../types';\n\ntype NativeAndroidModule = {\n deepLinkToSubscriptionsAndroid?: (params: {\n skuAndroid?: string;\n packageNameAndroid?: string;\n }) => Promise<void> | void;\n getStorefront?: () => Promise<string> | string;\n};\n\nconst nativeAndroidModule = ExpoIapModule as NativeAndroidModule;\n\n// Type guards\nexport function isProductAndroid<T extends {platform?: string}>(\n item: unknown,\n): item is T & {platform: 'android'} {\n return (\n item != null &&\n typeof item === 'object' &&\n 'platform' in item &&\n typeof (item as any).platform === 'string' &&\n (item as any).platform.toLowerCase() === 'android'\n );\n}\n\n/**\n * Deep link to subscriptions screen on Android.\n * @param {Object} params - The parameters object\n * @param {string} params.skuAndroid - The product's SKU (on Android)\n * @param {string} params.packageNameAndroid - The package name of your Android app (e.g., 'com.example.app')\n * @returns {Promise<void>}\n *\n * @example\n * ```typescript\n * await deepLinkToSubscriptionsAndroid({\n * skuAndroid: 'subscription_id',\n * packageNameAndroid: 'com.example.app'\n * });\n * ```\n */\nexport const deepLinkToSubscriptionsAndroid = async (\n options?: DeepLinkOptions | null,\n): Promise<void> => {\n const sku = options?.skuAndroid ?? undefined;\n const packageName = options?.packageNameAndroid ?? undefined;\n\n // Prefer native deep link implementation via OpenIAP module\n if (nativeAndroidModule?.deepLinkToSubscriptionsAndroid) {\n return nativeAndroidModule.deepLinkToSubscriptionsAndroid({\n skuAndroid: sku,\n packageNameAndroid: packageName,\n });\n }\n\n // Fallback to Linking if native method unavailable\n if (!packageName) {\n throw new Error(\n 'packageName is required for deepLinkToSubscriptionsAndroid',\n );\n }\n const base = `https://play.google.com/store/account/subscriptions?package=${encodeURIComponent(\n packageName,\n )}`;\n const url = sku ? `${base}&sku=${encodeURIComponent(sku)}` : base;\n return Linking.openURL(url);\n};\n\n/**\n * Validate receipt for Android. NOTE: This method is here for debugging purposes only. Including\n * your access token in the binary you ship to users is potentially dangerous.\n * Use server side validation instead for your production builds\n *\n * @deprecated Use verifyPurchase instead\n * @param {Object} params - The parameters object\n * @param {string} params.packageName - package name of your app.\n * @param {string} params.productId - product id for your in app product.\n * @param {string} params.productToken - token for your purchase (called 'token' in the API documentation).\n * @param {string} params.accessToken - OAuth access token with androidpublisher scope. Required for authentication.\n * @param {boolean} params.isSub - whether this is subscription or in-app. `true` for subscription.\n * @returns {Promise<ReceiptAndroid>}\n */\nexport const validateReceiptAndroid = async ({\n packageName,\n productId,\n productToken,\n accessToken,\n isSub,\n}: {\n packageName: string;\n productId: string;\n productToken: string;\n accessToken: string;\n isSub?: boolean;\n}): Promise<VerifyPurchaseResultAndroid> => {\n const type = isSub ? 'subscriptions' : 'products';\n\n const url =\n 'https://androidpublisher.googleapis.com/androidpublisher/v3/applications' +\n `/${packageName}/purchases/${type}/${productId}` +\n `/tokens/${productToken}`;\n\n const response = await fetch(url, {\n method: 'GET',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${accessToken}`,\n },\n });\n\n if (!response.ok) {\n throw Object.assign(new Error(response.statusText), {\n statusCode: response.status,\n });\n }\n\n return response.json();\n};\n\n/**\n * Consume a purchase token so the user can purchase the same product again\n * (Android consumable products). Prefer using `finishTransaction` with\n * `isConsumable: true`, which dispatches to this under the hood.\n *\n * @see {@link https://openiap.dev/docs/apis/android/consume-purchase-android}\n */\nexport const consumePurchaseAndroid: MutationField<\n 'consumePurchaseAndroid'\n> = async (purchaseToken) => {\n const result = await ExpoIapModule.consumePurchaseAndroid(purchaseToken);\n\n if (typeof result === 'boolean') {\n return result;\n }\n\n if (result && typeof result === 'object') {\n const record = result as Record<string, unknown>;\n if (typeof record.success === 'boolean') {\n return record.success;\n }\n if (typeof record.responseCode === 'number') {\n return record.responseCode === 0;\n }\n }\n\n throw new Error(\n `consumePurchaseAndroid returned an unexpected response payload: ${JSON.stringify(\n result,\n )}`,\n );\n};\n\n/**\n * Acknowledge a product (on Android.) No-op on iOS.\n * @param {Object} params - The parameters object\n * @param {string} params.token - The product's token (on Android)\n * @returns {Promise<VoidResult | void>}\n *\n * @see {@link https://openiap.dev/docs/apis/android/acknowledge-purchase-android}\n */\nexport const acknowledgePurchaseAndroid: MutationField<\n 'acknowledgePurchaseAndroid'\n> = async (purchaseToken) => {\n const result = await ExpoIapModule.acknowledgePurchaseAndroid(purchaseToken);\n\n if (typeof result === 'boolean') {\n return result;\n }\n\n if (result && typeof result === 'object') {\n const record = result as Record<string, unknown>;\n if (typeof record.success === 'boolean') {\n return record.success;\n }\n if (typeof record.responseCode === 'number') {\n return record.responseCode === 0;\n }\n }\n\n return true;\n};\n\n/**\n * Open the Google Play Store to redeem offer codes (Android only).\n * Note: Google Play does not provide a direct API to redeem codes within the app.\n * This function opens the Play Store where users can manually enter their codes.\n *\n * @returns {Promise<void>}\n */\nexport const openRedeemOfferCodeAndroid = async (): Promise<void> => {\n return Linking.openURL(`https://play.google.com/redeem?code=`);\n};\n\n/**\n * Check if alternative billing is available for this user/device (Android only).\n * Step 1 of alternative billing flow.\n *\n * Returns true if available, false otherwise.\n * Throws OpenIapError.NotPrepared if billing client not ready.\n *\n * @returns {Promise<boolean>}\n *\n * @example\n * ```typescript\n * const isAvailable = await checkAlternativeBillingAvailabilityAndroid();\n * if (isAvailable) {\n * // Proceed with alternative billing flow\n * }\n * ```\n *\n * @see {@link https://openiap.dev/docs/apis/android/check-alternative-billing-availability-android}\n */\nexport const checkAlternativeBillingAvailabilityAndroid: MutationField<\n 'checkAlternativeBillingAvailabilityAndroid'\n> = async () => {\n return ExpoIapModule.checkAlternativeBillingAvailabilityAndroid();\n};\n\n/**\n * Show alternative billing information dialog to user (Android only).\n * Step 2 of alternative billing flow.\n * Must be called BEFORE processing payment in your payment system.\n *\n * Returns true if user accepted, false if user canceled.\n * Throws OpenIapError.NotPrepared if billing client not ready.\n *\n * @returns {Promise<boolean>}\n *\n * @example\n * ```typescript\n * const userAccepted = await showAlternativeBillingDialogAndroid();\n * if (userAccepted) {\n * // Process payment in your payment system\n * const success = await processCustomPayment();\n * if (success) {\n * // Create reporting token\n * const token = await createAlternativeBillingTokenAndroid();\n * // Send token to your backend for Google Play reporting\n * }\n * }\n * ```\n *\n * @see {@link https://openiap.dev/docs/apis/android/show-alternative-billing-dialog-android}\n */\nexport const showAlternativeBillingDialogAndroid: MutationField<\n 'showAlternativeBillingDialogAndroid'\n> = async () => {\n return ExpoIapModule.showAlternativeBillingDialogAndroid();\n};\n\n/**\n * Create external transaction token for Google Play reporting (Android only).\n * Step 3 of alternative billing flow.\n * Must be called AFTER successful payment in your payment system.\n * Token must be reported to Google Play backend within 24 hours.\n *\n * Returns token string, or null if creation failed.\n * Throws OpenIapError.NotPrepared if billing client not ready.\n *\n * @param {string} sku - The product SKU that was purchased\n * @returns {Promise<string | null>}\n *\n * @example\n * ```typescript\n * const token = await createAlternativeBillingTokenAndroid('premium_subscription');\n * if (token) {\n * // Send token to your backend\n * await fetch('/api/report-transaction', {\n * method: 'POST',\n * body: JSON.stringify({ token, sku: 'premium_subscription' })\n * });\n * }\n * ```\n *\n * @see {@link https://openiap.dev/docs/apis/android/create-alternative-billing-token-android}\n */\nexport const createAlternativeBillingTokenAndroid: MutationField<\n 'createAlternativeBillingTokenAndroid'\n> = async (sku?: string) => {\n return ExpoIapModule.createAlternativeBillingTokenAndroid(sku);\n};\n\n// ============================================================================\n// Billing Programs API (Google Play Billing Library 8.2.0+)\n// ============================================================================\n\n/**\n * Check if a specific billing program is available for this user/device (Android only).\n * Available in Google Play Billing Library 8.2.0+. Billing Choice availability\n * details, including the configured renderer and external-link support, require 9.1.0+.\n *\n * @param program - The billing program to check\n * @returns Promise resolving to availability result\n *\n * @example\n * ```typescript\n * const result = await isBillingProgramAvailableAndroid('external-offer');\n * if (result.isAvailable) {\n * // Proceed with billing program flow\n * }\n * ```\n *\n * @see {@link https://openiap.dev/docs/apis/android/is-billing-program-available-android}\n */\nexport const isBillingProgramAvailableAndroid: MutationField<\n 'isBillingProgramAvailableAndroid'\n> = async (program) => {\n return ExpoIapModule.isBillingProgramAvailableAndroid(program);\n};\n\n/**\n * Fetch Play Billing assets and loyalty text for developer-rendered Billing Choice screens.\n * Available in Google Play Billing Library 9.1.0+.\n *\n * @param params - Billing Choice info request parameters\n * @returns Promise resolving to Play Billing Choice display information\n *\n * @see {@link https://openiap.dev/docs/apis/android/get-billing-choice-info-android}\n */\nexport const getBillingChoiceInfoAndroid: QueryField<\n 'getBillingChoiceInfoAndroid'\n> = async (\n params: GetBillingChoiceInfoParamsAndroid = {},\n): Promise<BillingChoiceInfoAndroid> => {\n return ExpoIapModule.getBillingChoiceInfoAndroid({\n billingProgram: params.billingProgram ?? 'billing-choice',\n playBillingChoiceImageLayout:\n params.playBillingChoiceImageLayout ?? 'rectangular-four-by-one',\n userLocale: params.userLocale ?? null,\n });\n};\n\n/**\n * Launch an external link for the specified billing program (Android only).\n * Available in Google Play Billing Library 8.2.0+; developer-rendered Billing\n * Choice external-link flows require 9.1.0+ and `externalTransactionToken`.\n *\n * @param params - The external link parameters\n * @returns Promise resolving to true if the link was launched successfully\n *\n * @example\n * ```typescript\n * await launchExternalLinkAndroid({\n * billingProgram: 'billing-choice',\n * externalTransactionToken: 'pre-generated-token',\n * launchMode: 'launch-in-external-browser-or-app',\n * linkType: 'link-to-digital-content-offer',\n * linkUri: 'https://your-payment-site.com',\n * });\n * ```\n *\n * @see {@link https://openiap.dev/docs/apis/android/launch-external-link-android}\n */\nexport const launchExternalLinkAndroid: MutationField<\n 'launchExternalLinkAndroid'\n> = async (params) => {\n return ExpoIapModule.launchExternalLinkAndroid(params);\n};\n\n/**\n * Create billing program reporting details for Google Play reporting (Android only).\n * Available in Google Play Billing Library 8.2.0+.\n *\n * Must be called AFTER successful payment in your payment system.\n * Token must be reported to Google Play backend within 24 hours.\n *\n * @param program - The billing program type\n * @returns Promise resolving to reporting details including the external transaction token\n *\n * @example\n * ```typescript\n * const details = await createBillingProgramReportingDetailsAndroid('external-offer');\n * // Report details.externalTransactionToken to Google Play within 24 hours\n * await reportToGooglePlay(details.externalTransactionToken);\n * ```\n *\n * @see {@link https://openiap.dev/docs/apis/android/create-billing-program-reporting-details-android}\n */\nconst createBillingProgramReportingDetailsAndroidField: MutationField<\n 'createBillingProgramReportingDetailsAndroid'\n> = async (\n args: MutationCreateBillingProgramReportingDetailsAndroidArgs,\n): Promise<BillingProgramReportingDetailsAndroid> =>\n ExpoIapModule.createBillingProgramReportingDetailsAndroid(\n args.program,\n args.developerBillingType ?? null,\n );\n\nexport function createBillingProgramReportingDetailsAndroid(\n args: MutationCreateBillingProgramReportingDetailsAndroidArgs,\n): Promise<BillingProgramReportingDetailsAndroid>;\nexport function createBillingProgramReportingDetailsAndroid(\n program: BillingProgramAndroid,\n developerBillingType?: DeveloperBillingTypeAndroid | null,\n): Promise<BillingProgramReportingDetailsAndroid>;\nexport function createBillingProgramReportingDetailsAndroid(\n programOrArgs:\n | BillingProgramAndroid\n | MutationCreateBillingProgramReportingDetailsAndroidArgs,\n developerBillingType?: DeveloperBillingTypeAndroid | null,\n): Promise<BillingProgramReportingDetailsAndroid> {\n const args =\n typeof programOrArgs === 'string'\n ? {program: programOrArgs, developerBillingType}\n : programOrArgs;\n return createBillingProgramReportingDetailsAndroidField(args);\n}\n\n/**\n * Show Google's mandatory information dialog before a developer-rendered,\n * in-app Billing Choice screen.\n * Available in Google Play Billing Library 9.1.0+.\n *\n * @param params - Dialog parameters with the external transaction token\n * @returns Promise resolving to BillingResult\n *\n * @see {@link https://openiap.dev/docs/apis/android/show-billing-program-information-dialog-android}\n */\nexport const showBillingProgramInformationDialogAndroid: MutationField<\n 'showBillingProgramInformationDialogAndroid'\n> = async (\n params: BillingProgramInformationDialogParamsAndroid,\n): Promise<BillingResultAndroid> => {\n return ExpoIapModule.showBillingProgramInformationDialogAndroid({\n billingProgram: params.billingProgram ?? 'billing-choice',\n externalTransactionToken: params.externalTransactionToken,\n });\n};\n\n/**\n * Show Play Billing in-app messages, such as transactional subscription updates.\n * Available in Google Play Billing Library 4.1.0+.\n *\n * @param params - Optional in-app message categories\n * @returns Promise resolving to in-app message result\n *\n * @see {@link https://openiap.dev/docs/apis/android/show-in-app-messages-android}\n */\nexport const showInAppMessagesAndroid: MutationField<\n 'showInAppMessagesAndroid'\n> = async (\n params?: InAppMessageParamsAndroid | null,\n): Promise<InAppMessageResultAndroid> => {\n return ExpoIapModule.showInAppMessagesAndroid(params ?? null);\n};\n"]}
|
|
1
|
+
{"version":3,"file":"android.js","sourceRoot":"","sources":["../../src/modules/android.ts"],"names":[],"mappings":"AAAA,wBAAwB;AACxB,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAC,MAAM,cAAc,CAAC;AAE/C,mBAAmB;AACnB,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAC,QAAQ,EAAC,MAAM,SAAS,CAAC;AA4BjC,MAAM,mBAAmB,GAAG,aAAoC,CAAC;AAEjE;;;;;;;GAOG;AACH,MAAM,sBAAsB,GAAG,CAAC,UAAkB,EAAQ,EAAE;IAC1D,IAAI,QAAQ,CAAC,EAAE,KAAK,SAAS,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC;QAC7C,MAAM,IAAI,KAAK,CAAC,GAAG,UAAU,2CAA2C,CAAC,CAAC;IAC5E,CAAC;AACH,CAAC,CAAC;AAEF,cAAc;AACd,MAAM,UAAU,gBAAgB,CAC9B,IAAa;IAEb,OAAO,CACL,IAAI,IAAI,IAAI;QACZ,OAAO,IAAI,KAAK,QAAQ;QACxB,UAAU,IAAI,IAAI;QAClB,OAAQ,IAAY,CAAC,QAAQ,KAAK,QAAQ;QACzC,IAAY,CAAC,QAAQ,CAAC,WAAW,EAAE,KAAK,SAAS,CACnD,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,KAAK,EACjD,OAAgC,EACjB,EAAE;IACjB,MAAM,GAAG,GAAG,OAAO,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AAK,QAAQ;QAC/B,CAAC,CAAC,EAAC,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAC;QAChD,CAAC,CAAC,aAAa,CAAC;IACpB,OAAO,gDAAgD,CAAC,IAAI,CAAC,CAAC;AAChE,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,0CAA0C,GAEnD,KAAK,EACP,MAAoD,EACrB,EAAE;IACjC,sBAAsB,CAAC,4CAA4C,CAAC,CAAC;IACrE,OAAO,aAAa,CAAC,0CAA0C,CAAC;QAC9D,cAAc,EAAE,MAAM,CAAC,cAAc,IAAI,gBAAgB;QACzD,wBAAwB,EAAE,MAAM,CAAC,wBAAwB;KAC1D,CAAC,CAAC;AACL,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAEjC,KAAK,EACP,MAAyC,EACL,EAAE;IACtC,sBAAsB,CAAC,0BAA0B,CAAC,CAAC;IACnD,OAAO,aAAa,CAAC,wBAAwB,CAAC,MAAM,IAAI,IAAI,CAAC,CAAC;AAChE,CAAC,CAAC","sourcesContent":["// External dependencies\nimport {Linking, Platform} from 'react-native';\n\n// Internal modules\nimport ExpoIapModule from '../ExpoIapModule';\nimport {isVegaOS} from '../vega';\n\n// Types\nimport type {\n BillingChoiceInfoAndroid,\n BillingProgramAndroid,\n BillingProgramInformationDialogParamsAndroid,\n BillingProgramReportingDetailsAndroid,\n BillingResultAndroid,\n DeepLinkOptions,\n DeveloperBillingTypeAndroid,\n GetBillingChoiceInfoParamsAndroid,\n InAppMessageParamsAndroid,\n InAppMessageResultAndroid,\n MutationCreateBillingProgramReportingDetailsAndroidArgs,\n MutationField,\n QueryField,\n VerifyPurchaseResultAndroid,\n} from '../types';\n\ntype NativeAndroidModule = {\n deepLinkToSubscriptionsAndroid?: (params: {\n skuAndroid?: string;\n packageNameAndroid?: string;\n }) => Promise<void> | void;\n getStorefront?: () => Promise<string> | string;\n};\n\nconst nativeAndroidModule = ExpoIapModule as NativeAndroidModule;\n\n/**\n * Enforce the documented Android-only contract. Vega OS is treated as an\n * Android store runtime (matching `isAndroidStoreRuntime` in src/index.ts),\n * so it passes through. Without this guard, calling a suffixed wrapper on\n * another platform falls through to the native proxy and surfaces as an\n * opaque `TypeError: ExpoIapModule.<name> is not a function` instead of the\n * promised platform error.\n */\nconst requireAndroidPlatform = (methodName: string): void => {\n if (Platform.OS !== 'android' && !isVegaOS()) {\n throw new Error(`${methodName} is only available on Android and Vega OS`);\n }\n};\n\n// Type guards\nexport function isProductAndroid<T extends {platform?: string}>(\n item: unknown,\n): item is T & {platform: 'android'} {\n return (\n item != null &&\n typeof item === 'object' &&\n 'platform' in item &&\n typeof (item as any).platform === 'string' &&\n (item as any).platform.toLowerCase() === 'android'\n );\n}\n\n/**\n * Deep link to subscriptions screen on Android.\n * @param {Object} params - The parameters object\n * @param {string} params.skuAndroid - The product's SKU (on Android)\n * @param {string} params.packageNameAndroid - The package name of your Android app (e.g., 'com.example.app')\n * @returns {Promise<void>}\n *\n * @example\n * ```typescript\n * await deepLinkToSubscriptionsAndroid({\n * skuAndroid: 'subscription_id',\n * packageNameAndroid: 'com.example.app'\n * });\n * ```\n */\nexport const deepLinkToSubscriptionsAndroid = async (\n options?: DeepLinkOptions | null,\n): Promise<void> => {\n const sku = options?.skuAndroid ?? undefined;\n const packageName = options?.packageNameAndroid ?? undefined;\n\n // Prefer native deep link implementation via OpenIAP module\n if (nativeAndroidModule?.deepLinkToSubscriptionsAndroid) {\n return nativeAndroidModule.deepLinkToSubscriptionsAndroid({\n skuAndroid: sku,\n packageNameAndroid: packageName,\n });\n }\n\n // Fallback to Linking if native method unavailable\n if (!packageName) {\n throw new Error(\n 'packageName is required for deepLinkToSubscriptionsAndroid',\n );\n }\n const base = `https://play.google.com/store/account/subscriptions?package=${encodeURIComponent(\n packageName,\n )}`;\n const url = sku ? `${base}&sku=${encodeURIComponent(sku)}` : base;\n return Linking.openURL(url);\n};\n\n/**\n * Validate receipt for Android. NOTE: This method is here for debugging purposes only. Including\n * your access token in the binary you ship to users is potentially dangerous.\n * Use server side validation instead for your production builds\n *\n * @deprecated Use verifyPurchase instead\n * @param {Object} params - The parameters object\n * @param {string} params.packageName - package name of your app.\n * @param {string} params.productId - product id for your in app product.\n * @param {string} params.productToken - token for your purchase (called 'token' in the API documentation).\n * @param {string} params.accessToken - OAuth access token with androidpublisher scope. Required for authentication.\n * @param {boolean} params.isSub - whether this is subscription or in-app. `true` for subscription.\n * @returns {Promise<ReceiptAndroid>}\n */\nexport const validateReceiptAndroid = async ({\n packageName,\n productId,\n productToken,\n accessToken,\n isSub,\n}: {\n packageName: string;\n productId: string;\n productToken: string;\n accessToken: string;\n isSub?: boolean;\n}): Promise<VerifyPurchaseResultAndroid> => {\n const type = isSub ? 'subscriptions' : 'products';\n\n const url =\n 'https://androidpublisher.googleapis.com/androidpublisher/v3/applications' +\n `/${packageName}/purchases/${type}/${productId}` +\n `/tokens/${productToken}`;\n\n const response = await fetch(url, {\n method: 'GET',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${accessToken}`,\n },\n });\n\n if (!response.ok) {\n throw Object.assign(new Error(response.statusText), {\n statusCode: response.status,\n });\n }\n\n return response.json();\n};\n\n/**\n * Consume a purchase token so the user can purchase the same product again\n * (Android consumable products). Prefer using `finishTransaction` with\n * `isConsumable: true`, which dispatches to this under the hood.\n *\n * @see {@link https://openiap.dev/docs/apis/android/consume-purchase-android}\n */\nexport const consumePurchaseAndroid: MutationField<\n 'consumePurchaseAndroid'\n> = async (purchaseToken) => {\n requireAndroidPlatform('consumePurchaseAndroid');\n const result = await ExpoIapModule.consumePurchaseAndroid(purchaseToken);\n\n if (typeof result === 'boolean') {\n return result;\n }\n\n if (result && typeof result === 'object') {\n const record = result as Record<string, unknown>;\n if (typeof record.success === 'boolean') {\n return record.success;\n }\n if (typeof record.responseCode === 'number') {\n return record.responseCode === 0;\n }\n }\n\n throw new Error(\n `consumePurchaseAndroid returned an unexpected response payload: ${JSON.stringify(\n result,\n )}`,\n );\n};\n\n/**\n * Acknowledge a non-consumable purchase or subscription (Android only).\n * @param {Object} params - The parameters object\n * @param {string} params.token - The product's token (on Android)\n * @returns {Promise<VoidResult | void>}\n * @throws Error if called on a non-Android platform\n *\n * @see {@link https://openiap.dev/docs/apis/android/acknowledge-purchase-android}\n */\nexport const acknowledgePurchaseAndroid: MutationField<\n 'acknowledgePurchaseAndroid'\n> = async (purchaseToken) => {\n requireAndroidPlatform('acknowledgePurchaseAndroid');\n const result = await ExpoIapModule.acknowledgePurchaseAndroid(purchaseToken);\n\n if (typeof result === 'boolean') {\n return result;\n }\n\n if (result && typeof result === 'object') {\n const record = result as Record<string, unknown>;\n if (typeof record.success === 'boolean') {\n return record.success;\n }\n if (typeof record.responseCode === 'number') {\n return record.responseCode === 0;\n }\n }\n\n return true;\n};\n\n/**\n * Open the Google Play offer/promo code redemption flow so the user can enter a code (Android only).\n * On Play builds, launches the Play Store redeem page. A listener can receive\n * the purchase while the app has an active billing connection; reconcile\n * available purchases when the app resumes. Unsupported store flavors return false.\n * Does not require the billing client to be initialized (no Play Billing version requirement).\n * Android counterpart of presentCodeRedemptionSheetIOS.\n *\n * @returns Promise resolving to true when launched, or false when unsupported\n *\n * @see {@link https://openiap.dev/docs/apis/android/open-redeem-offer-code-android}\n */\nexport const openRedeemOfferCodeAndroid: MutationField<\n 'openRedeemOfferCodeAndroid'\n> = async () => {\n requireAndroidPlatform('openRedeemOfferCodeAndroid');\n if (isVegaOS()) {\n return false;\n }\n return ExpoIapModule.openRedeemOfferCodeAndroid();\n};\n\n/**\n * Check if alternative billing is available for this user/device (Android only).\n * Step 1 of alternative billing flow.\n *\n * Returns true if available, false otherwise.\n * Throws OpenIapError.NotPrepared if billing client not ready.\n *\n * @returns {Promise<boolean>}\n *\n * @example\n * ```typescript\n * const isAvailable = await checkAlternativeBillingAvailabilityAndroid();\n * if (isAvailable) {\n * // Proceed with alternative billing flow\n * }\n * ```\n *\n * @see {@link https://openiap.dev/docs/apis/android/check-alternative-billing-availability-android}\n */\nexport const checkAlternativeBillingAvailabilityAndroid: MutationField<\n 'checkAlternativeBillingAvailabilityAndroid'\n> = async () => {\n requireAndroidPlatform('checkAlternativeBillingAvailabilityAndroid');\n return ExpoIapModule.checkAlternativeBillingAvailabilityAndroid();\n};\n\n/**\n * Show alternative billing information dialog to user (Android only).\n * Step 2 of alternative billing flow.\n * Must be called BEFORE processing payment in your payment system.\n *\n * Returns true if user accepted, false if user canceled.\n * Throws OpenIapError.NotPrepared if billing client not ready.\n *\n * @returns {Promise<boolean>}\n *\n * @example\n * ```typescript\n * const userAccepted = await showAlternativeBillingDialogAndroid();\n * if (userAccepted) {\n * // Process payment in your payment system\n * const success = await processCustomPayment();\n * if (success) {\n * // Create reporting token\n * const token = await createAlternativeBillingTokenAndroid();\n * // Send token to your backend for Google Play reporting\n * }\n * }\n * ```\n *\n * @see {@link https://openiap.dev/docs/apis/android/show-alternative-billing-dialog-android}\n */\nexport const showAlternativeBillingDialogAndroid: MutationField<\n 'showAlternativeBillingDialogAndroid'\n> = async () => {\n requireAndroidPlatform('showAlternativeBillingDialogAndroid');\n return ExpoIapModule.showAlternativeBillingDialogAndroid();\n};\n\n/**\n * Create external transaction token for Google Play reporting (Android only).\n * Step 3 of alternative billing flow.\n * Must be called AFTER successful payment in your payment system.\n * Token must be reported to Google Play backend within 24 hours.\n *\n * Returns token string, or null if creation failed.\n * Throws OpenIapError.NotPrepared if billing client not ready.\n *\n * @param {string} sku - The product SKU that was purchased\n * @returns {Promise<string | null>}\n *\n * @example\n * ```typescript\n * const token = await createAlternativeBillingTokenAndroid('premium_subscription');\n * if (token) {\n * // Send token to your backend\n * await fetch('/api/report-transaction', {\n * method: 'POST',\n * body: JSON.stringify({ token, sku: 'premium_subscription' })\n * });\n * }\n * ```\n *\n * @see {@link https://openiap.dev/docs/apis/android/create-alternative-billing-token-android}\n */\nexport const createAlternativeBillingTokenAndroid: MutationField<\n 'createAlternativeBillingTokenAndroid'\n> = async (sku?: string) => {\n requireAndroidPlatform('createAlternativeBillingTokenAndroid');\n return ExpoIapModule.createAlternativeBillingTokenAndroid(sku);\n};\n\n// ============================================================================\n// Billing Programs API (Google Play Billing Library 8.2.0+)\n// ============================================================================\n\n/**\n * Check if a specific billing program is available for this user/device (Android only).\n * Available in Google Play Billing Library 8.2.0+. Billing Choice availability\n * details, including the configured renderer and external-link support, require 9.1.0+.\n *\n * @param program - The billing program to check\n * @returns Promise resolving to availability result\n *\n * @example\n * ```typescript\n * const result = await isBillingProgramAvailableAndroid('external-offer');\n * if (result.isAvailable) {\n * // Proceed with billing program flow\n * }\n * ```\n *\n * @see {@link https://openiap.dev/docs/apis/android/is-billing-program-available-android}\n */\nexport const isBillingProgramAvailableAndroid: MutationField<\n 'isBillingProgramAvailableAndroid'\n> = async (program) => {\n requireAndroidPlatform('isBillingProgramAvailableAndroid');\n return ExpoIapModule.isBillingProgramAvailableAndroid(program);\n};\n\n/**\n * Fetch Play Billing assets and loyalty text for developer-rendered Billing Choice screens.\n * Available in Google Play Billing Library 9.1.0+.\n *\n * @param params - Billing Choice info request parameters\n * @returns Promise resolving to Play Billing Choice display information\n *\n * @see {@link https://openiap.dev/docs/apis/android/get-billing-choice-info-android}\n */\nexport const getBillingChoiceInfoAndroid: QueryField<\n 'getBillingChoiceInfoAndroid'\n> = async (\n params: GetBillingChoiceInfoParamsAndroid = {},\n): Promise<BillingChoiceInfoAndroid> => {\n requireAndroidPlatform('getBillingChoiceInfoAndroid');\n return ExpoIapModule.getBillingChoiceInfoAndroid({\n billingProgram: params.billingProgram ?? 'billing-choice',\n playBillingChoiceImageLayout:\n params.playBillingChoiceImageLayout ?? 'rectangular-four-by-one',\n userLocale: params.userLocale ?? null,\n });\n};\n\n/**\n * Launch an external link for the specified billing program (Android only).\n * Available in Google Play Billing Library 8.2.0+; developer-rendered Billing\n * Choice external-link flows require 9.1.0+ and `externalTransactionToken`.\n *\n * @param params - The external link parameters\n * @returns Promise resolving to true if the link was launched successfully\n *\n * @example\n * ```typescript\n * await launchExternalLinkAndroid({\n * billingProgram: 'billing-choice',\n * externalTransactionToken: 'pre-generated-token',\n * launchMode: 'launch-in-external-browser-or-app',\n * linkType: 'link-to-digital-content-offer',\n * linkUri: 'https://your-payment-site.com',\n * });\n * ```\n *\n * @see {@link https://openiap.dev/docs/apis/android/launch-external-link-android}\n */\nexport const launchExternalLinkAndroid: MutationField<\n 'launchExternalLinkAndroid'\n> = async (params) => {\n requireAndroidPlatform('launchExternalLinkAndroid');\n return ExpoIapModule.launchExternalLinkAndroid(params);\n};\n\n/**\n * Create billing program reporting details for Google Play reporting (Android only).\n * Available in Google Play Billing Library 8.2.0+.\n *\n * Must be called AFTER successful payment in your payment system.\n * Token must be reported to Google Play backend within 24 hours.\n *\n * @param program - The billing program type\n * @returns Promise resolving to reporting details including the external transaction token\n *\n * @example\n * ```typescript\n * const details = await createBillingProgramReportingDetailsAndroid('external-offer');\n * // Report details.externalTransactionToken to Google Play within 24 hours\n * await reportToGooglePlay(details.externalTransactionToken);\n * ```\n *\n * @see {@link https://openiap.dev/docs/apis/android/create-billing-program-reporting-details-android}\n */\nconst createBillingProgramReportingDetailsAndroidField: MutationField<\n 'createBillingProgramReportingDetailsAndroid'\n> = async (\n args: MutationCreateBillingProgramReportingDetailsAndroidArgs,\n): Promise<BillingProgramReportingDetailsAndroid> => {\n requireAndroidPlatform('createBillingProgramReportingDetailsAndroid');\n return ExpoIapModule.createBillingProgramReportingDetailsAndroid(\n args.program,\n args.developerBillingType ?? null,\n );\n};\n\nexport function createBillingProgramReportingDetailsAndroid(\n args: MutationCreateBillingProgramReportingDetailsAndroidArgs,\n): Promise<BillingProgramReportingDetailsAndroid>;\nexport function createBillingProgramReportingDetailsAndroid(\n program: BillingProgramAndroid,\n developerBillingType?: DeveloperBillingTypeAndroid | null,\n): Promise<BillingProgramReportingDetailsAndroid>;\nexport function createBillingProgramReportingDetailsAndroid(\n programOrArgs:\n | BillingProgramAndroid\n | MutationCreateBillingProgramReportingDetailsAndroidArgs,\n developerBillingType?: DeveloperBillingTypeAndroid | null,\n): Promise<BillingProgramReportingDetailsAndroid> {\n const args =\n typeof programOrArgs === 'string'\n ? {program: programOrArgs, developerBillingType}\n : programOrArgs;\n return createBillingProgramReportingDetailsAndroidField(args);\n}\n\n/**\n * Show Google's mandatory information dialog before a developer-rendered,\n * in-app Billing Choice screen.\n * Available in Google Play Billing Library 9.1.0+.\n *\n * @param params - Dialog parameters with the external transaction token\n * @returns Promise resolving to BillingResult\n *\n * @see {@link https://openiap.dev/docs/apis/android/show-billing-program-information-dialog-android}\n */\nexport const showBillingProgramInformationDialogAndroid: MutationField<\n 'showBillingProgramInformationDialogAndroid'\n> = async (\n params: BillingProgramInformationDialogParamsAndroid,\n): Promise<BillingResultAndroid> => {\n requireAndroidPlatform('showBillingProgramInformationDialogAndroid');\n return ExpoIapModule.showBillingProgramInformationDialogAndroid({\n billingProgram: params.billingProgram ?? 'billing-choice',\n externalTransactionToken: params.externalTransactionToken,\n });\n};\n\n/**\n * Show Play Billing in-app messages, such as transactional subscription updates.\n * Available in Google Play Billing Library 4.1.0+.\n *\n * @param params - Optional in-app message categories\n * @returns Promise resolving to in-app message result\n *\n * @see {@link https://openiap.dev/docs/apis/android/show-in-app-messages-android}\n */\nexport const showInAppMessagesAndroid: MutationField<\n 'showInAppMessagesAndroid'\n> = async (\n params?: InAppMessageParamsAndroid | null,\n): Promise<InAppMessageResultAndroid> => {\n requireAndroidPlatform('showInAppMessagesAndroid');\n return ExpoIapModule.showInAppMessagesAndroid(params ?? null);\n};\n"]}
|
package/build/modules/ios.d.ts
CHANGED
|
@@ -116,6 +116,8 @@ export declare const getReceiptIOS: () => Promise<string | null>;
|
|
|
116
116
|
* alias so consumers who previously imported `getStorefrontIOS` do not break.
|
|
117
117
|
*
|
|
118
118
|
* @returns {Promise<string>} ISO 3166-1 alpha-3 country code (e.g. "USA")
|
|
119
|
+
* @throws Error if called on non-iOS platform — Android callers must use the
|
|
120
|
+
* cross-platform `getStorefront` from the main index instead
|
|
119
121
|
*
|
|
120
122
|
* @platform iOS
|
|
121
123
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ios.d.ts","sourceRoot":"","sources":["../../src/modules/ios.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAKV,aAAa,EAEb,QAAQ,EAER,UAAU,EAIX,MAAM,UAAU,CAAC;AAClB,OAAO,EAGL,KAAK,aAAa,EACnB,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"ios.d.ts","sourceRoot":"","sources":["../../src/modules/ios.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAKV,aAAa,EAEb,QAAQ,EAER,UAAU,EAIX,MAAM,UAAU,CAAC;AAClB,OAAO,EAGL,KAAK,aAAa,EACnB,MAAM,uBAAuB,CAAC;AAe/B,MAAM,MAAM,gBAAgB,GAAG;IAC7B,WAAW,CAAC,EAAE,QAAQ,CAAC;IACvB,KAAK,CAAC,EAAE,aAAa,CAAC;CACvB,CAAC;AAKF,wBAAgB,YAAY,CAAC,CAAC,SAAS;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAC,EACxD,IAAI,EAAE,OAAO,GACZ,IAAI,IAAI,CAAC,GAAG;IAAC,QAAQ,EAAE,KAAK,CAAA;CAAC,CAQ/B;AAGD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,OAAO,EAAE,aAAa,CAAC,SAAS,CAG5C,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,0BAA0B,EAAE,UAAU,CACjD,4BAA4B,CAO7B,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,qBAAqB,EAAE,UAAU,CAC5C,uBAAuB,CAQxB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,qBAAqB,EAAE,UAAU,CAC5C,uBAAuB,CAQxB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,oBAAoB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GAIG;AACH,eAAO,MAAM,qBAAqB,EAAE,UAAU,CAC5C,uBAAuB,CAKxB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,EAAE,aAAa,CAC7C,qBAAqB,CAItB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,QAAO,OAAO,CAAC,IAAI,CACO,CAAC;AAElE;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,mCAAmC,EAAE,UAAU,CAC1D,qCAAqC,CAItC,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,qCAAqC,EAAE,aAAa,CAC/D,uCAAuC,CAKxC,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,8BAA8B,EAAE,aAAa,CACxD,gCAAgC,CAKjC,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,0CAA0C,EAAE,UAAU,CACjE,4CAA4C,CAI7C,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,qCAAqC,EAAE,UAAU,CAC5D,uCAAuC,CAYxC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,uCAAuC,EAAE,aAAa,CACjE,yCAAyC,CAY1C,CAAC"}
|
package/build/modules/ios.js
CHANGED
|
@@ -4,7 +4,18 @@
|
|
|
4
4
|
import ExpoIapModule from '../ExpoIapModule';
|
|
5
5
|
import { ErrorCode } from '../types';
|
|
6
6
|
import { createPurchaseError, createPurchaseErrorFromNativeException, } from '../utils/errorMapping';
|
|
7
|
-
import { Linking } from 'react-native';
|
|
7
|
+
import { Linking, Platform } from 'react-native';
|
|
8
|
+
/**
|
|
9
|
+
* Enforce the documented iOS-only contract. Without this, calling a
|
|
10
|
+
* suffixed wrapper on another platform falls through to the native proxy
|
|
11
|
+
* and surfaces as an opaque `TypeError: ExpoIapModule.<name> is not a
|
|
12
|
+
* function` instead of the promised platform error.
|
|
13
|
+
*/
|
|
14
|
+
const requireIosPlatform = (methodName) => {
|
|
15
|
+
if (Platform.OS !== 'ios') {
|
|
16
|
+
throw new Error(`${methodName} is only available on iOS`);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
8
19
|
// Listeners
|
|
9
20
|
// Type guards
|
|
10
21
|
export function isProductIOS(item) {
|
|
@@ -27,6 +38,7 @@ export function isProductIOS(item) {
|
|
|
27
38
|
* @see {@link https://openiap.dev/docs/apis/ios/sync-ios}
|
|
28
39
|
*/
|
|
29
40
|
export const syncIOS = async () => {
|
|
41
|
+
requireIosPlatform('syncIOS');
|
|
30
42
|
return !!(await ExpoIapModule.syncIOS());
|
|
31
43
|
};
|
|
32
44
|
/**
|
|
@@ -41,6 +53,7 @@ export const syncIOS = async () => {
|
|
|
41
53
|
* @see {@link https://openiap.dev/docs/apis/ios/is-eligible-for-intro-offer-ios}
|
|
42
54
|
*/
|
|
43
55
|
export const isEligibleForIntroOfferIOS = async (groupId) => {
|
|
56
|
+
requireIosPlatform('isEligibleForIntroOfferIOS');
|
|
44
57
|
if (!groupId) {
|
|
45
58
|
throw new Error('isEligibleForIntroOfferIOS requires a groupId');
|
|
46
59
|
}
|
|
@@ -58,6 +71,7 @@ export const isEligibleForIntroOfferIOS = async (groupId) => {
|
|
|
58
71
|
* @see {@link https://openiap.dev/docs/apis/ios/subscription-status-ios}
|
|
59
72
|
*/
|
|
60
73
|
export const subscriptionStatusIOS = async (sku) => {
|
|
74
|
+
requireIosPlatform('subscriptionStatusIOS');
|
|
61
75
|
if (!sku) {
|
|
62
76
|
throw new Error('subscriptionStatusIOS requires a SKU');
|
|
63
77
|
}
|
|
@@ -76,6 +90,7 @@ export const subscriptionStatusIOS = async (sku) => {
|
|
|
76
90
|
* @see {@link https://openiap.dev/docs/apis/ios/current-entitlement-ios}
|
|
77
91
|
*/
|
|
78
92
|
export const currentEntitlementIOS = async (sku) => {
|
|
93
|
+
requireIosPlatform('currentEntitlementIOS');
|
|
79
94
|
if (!sku) {
|
|
80
95
|
throw new Error('currentEntitlementIOS requires a SKU');
|
|
81
96
|
}
|
|
@@ -94,6 +109,7 @@ export const currentEntitlementIOS = async (sku) => {
|
|
|
94
109
|
* @see {@link https://openiap.dev/docs/apis/ios/latest-transaction-ios}
|
|
95
110
|
*/
|
|
96
111
|
export const latestTransactionIOS = async (sku) => {
|
|
112
|
+
requireIosPlatform('latestTransactionIOS');
|
|
97
113
|
if (!sku) {
|
|
98
114
|
throw new Error('latestTransactionIOS requires a SKU');
|
|
99
115
|
}
|
|
@@ -112,6 +128,7 @@ export const latestTransactionIOS = async (sku) => {
|
|
|
112
128
|
* @see {@link https://openiap.dev/docs/apis/ios/begin-refund-request-ios}
|
|
113
129
|
*/
|
|
114
130
|
export const beginRefundRequestIOS = async (sku) => {
|
|
131
|
+
requireIosPlatform('beginRefundRequestIOS');
|
|
115
132
|
if (!sku) {
|
|
116
133
|
throw new Error('beginRefundRequestIOS requires a SKU');
|
|
117
134
|
}
|
|
@@ -130,6 +147,7 @@ export const beginRefundRequestIOS = async (sku) => {
|
|
|
130
147
|
* @see {@link https://openiap.dev/docs/apis/ios/show-manage-subscriptions-ios}
|
|
131
148
|
*/
|
|
132
149
|
export const showManageSubscriptionsIOS = async () => {
|
|
150
|
+
requireIosPlatform('showManageSubscriptionsIOS');
|
|
133
151
|
const purchases = await ExpoIapModule.showManageSubscriptionsIOS();
|
|
134
152
|
return (purchases ?? []);
|
|
135
153
|
};
|
|
@@ -146,6 +164,7 @@ export const showManageSubscriptionsIOS = async () => {
|
|
|
146
164
|
* @see {@link https://openiap.dev/docs/apis/ios/get-receipt-data-ios}
|
|
147
165
|
*/
|
|
148
166
|
export const getReceiptDataIOS = async () => {
|
|
167
|
+
requireIosPlatform('getReceiptDataIOS');
|
|
149
168
|
return ExpoIapModule.getReceiptDataIOS();
|
|
150
169
|
};
|
|
151
170
|
export const getReceiptIOS = getReceiptDataIOS;
|
|
@@ -158,12 +177,15 @@ export const getReceiptIOS = getReceiptDataIOS;
|
|
|
158
177
|
* alias so consumers who previously imported `getStorefrontIOS` do not break.
|
|
159
178
|
*
|
|
160
179
|
* @returns {Promise<string>} ISO 3166-1 alpha-3 country code (e.g. "USA")
|
|
180
|
+
* @throws Error if called on non-iOS platform — Android callers must use the
|
|
181
|
+
* cross-platform `getStorefront` from the main index instead
|
|
161
182
|
*
|
|
162
183
|
* @platform iOS
|
|
163
184
|
*
|
|
164
185
|
* @see {@link https://openiap.dev/docs/apis/ios/get-storefront-ios}
|
|
165
186
|
*/
|
|
166
187
|
export const getStorefrontIOS = async () => {
|
|
188
|
+
requireIosPlatform('getStorefrontIOS');
|
|
167
189
|
if (typeof ExpoIapModule.getStorefront !== 'function') {
|
|
168
190
|
throw createPurchaseError({
|
|
169
191
|
code: ErrorCode.FeatureNotSupported,
|
|
@@ -203,6 +225,7 @@ export const getStorefrontIOS = async () => {
|
|
|
203
225
|
* @platform iOS
|
|
204
226
|
*/
|
|
205
227
|
export const requestReceiptRefreshIOS = async () => {
|
|
228
|
+
requireIosPlatform('requestReceiptRefreshIOS');
|
|
206
229
|
return ExpoIapModule.requestReceiptRefreshIOS();
|
|
207
230
|
};
|
|
208
231
|
/**
|
|
@@ -218,6 +241,7 @@ export const requestReceiptRefreshIOS = async () => {
|
|
|
218
241
|
* @see {@link https://openiap.dev/docs/apis/ios/is-transaction-verified-ios}
|
|
219
242
|
*/
|
|
220
243
|
export const isTransactionVerifiedIOS = async (sku) => {
|
|
244
|
+
requireIosPlatform('isTransactionVerifiedIOS');
|
|
221
245
|
if (!sku) {
|
|
222
246
|
throw new Error('isTransactionVerifiedIOS requires a SKU');
|
|
223
247
|
}
|
|
@@ -236,6 +260,7 @@ export const isTransactionVerifiedIOS = async (sku) => {
|
|
|
236
260
|
* @see {@link https://openiap.dev/docs/apis/ios/get-transaction-jws-ios}
|
|
237
261
|
*/
|
|
238
262
|
export const getTransactionJwsIOS = async (sku) => {
|
|
263
|
+
requireIosPlatform('getTransactionJwsIOS');
|
|
239
264
|
if (!sku) {
|
|
240
265
|
throw new Error('getTransactionJwsIOS requires a SKU');
|
|
241
266
|
}
|
|
@@ -261,6 +286,7 @@ export const getTransactionJwsIOS = async (sku) => {
|
|
|
261
286
|
* @see {@link https://openiap.dev/docs/apis/ios/validate-receipt-ios}
|
|
262
287
|
*/
|
|
263
288
|
const validateReceiptIOSImpl = async (props) => {
|
|
289
|
+
requireIosPlatform('validateReceiptIOS');
|
|
264
290
|
const sku = typeof props === 'string'
|
|
265
291
|
? props
|
|
266
292
|
: props?.apple?.sku;
|
|
@@ -284,6 +310,7 @@ export const validateReceiptIOS = validateReceiptIOSImpl;
|
|
|
284
310
|
* @see {@link https://openiap.dev/docs/apis/ios/present-code-redemption-sheet-ios}
|
|
285
311
|
*/
|
|
286
312
|
export const presentCodeRedemptionSheetIOS = async () => {
|
|
313
|
+
requireIosPlatform('presentCodeRedemptionSheetIOS');
|
|
287
314
|
return !!(await ExpoIapModule.presentCodeRedemptionSheetIOS());
|
|
288
315
|
};
|
|
289
316
|
/**
|
|
@@ -303,6 +330,7 @@ export const presentCodeRedemptionSheetIOS = async () => {
|
|
|
303
330
|
* @see {@link https://openiap.dev/docs/apis/ios/get-app-transaction-ios}
|
|
304
331
|
*/
|
|
305
332
|
export const getAppTransactionIOS = async () => {
|
|
333
|
+
requireIosPlatform('getAppTransactionIOS');
|
|
306
334
|
return (await ExpoIapModule.getAppTransactionIOS()) ?? null;
|
|
307
335
|
};
|
|
308
336
|
/**
|
|
@@ -318,6 +346,7 @@ export const getAppTransactionIOS = async () => {
|
|
|
318
346
|
* @see {@link https://openiap.dev/docs/apis/ios/get-promoted-product-ios}
|
|
319
347
|
*/
|
|
320
348
|
export const getPromotedProductIOS = async () => {
|
|
349
|
+
requireIosPlatform('getPromotedProductIOS');
|
|
321
350
|
const product = await ExpoIapModule.getPromotedProductIOS();
|
|
322
351
|
return (product ?? null);
|
|
323
352
|
};
|
|
@@ -336,6 +365,7 @@ export const getPromotedProductIOS = async () => {
|
|
|
336
365
|
* @see {@link https://openiap.dev/docs/apis/ios/request-purchase-on-promoted-product-ios}
|
|
337
366
|
*/
|
|
338
367
|
export const requestPurchaseOnPromotedProductIOS = async () => {
|
|
368
|
+
requireIosPlatform('requestPurchaseOnPromotedProductIOS');
|
|
339
369
|
const result = await ExpoIapModule.requestPurchaseOnPromotedProductIOS();
|
|
340
370
|
return result ?? true;
|
|
341
371
|
};
|
|
@@ -348,6 +378,7 @@ export const requestPurchaseOnPromotedProductIOS = async () => {
|
|
|
348
378
|
* @see {@link https://openiap.dev/docs/apis/ios/get-pending-transactions-ios}
|
|
349
379
|
*/
|
|
350
380
|
export const getPendingTransactionsIOS = async () => {
|
|
381
|
+
requireIosPlatform('getPendingTransactionsIOS');
|
|
351
382
|
const transactions = await ExpoIapModule.getPendingTransactionsIOS();
|
|
352
383
|
return (transactions ?? []);
|
|
353
384
|
};
|
|
@@ -357,6 +388,7 @@ export const getPendingTransactionsIOS = async () => {
|
|
|
357
388
|
* @see {@link https://openiap.dev/docs/apis/ios/get-all-transactions-ios}
|
|
358
389
|
*/
|
|
359
390
|
export const getAllTransactionsIOS = async () => {
|
|
391
|
+
requireIosPlatform('getAllTransactionsIOS');
|
|
360
392
|
const transactions = await ExpoIapModule.getAllTransactionsIOS();
|
|
361
393
|
return (transactions ?? []);
|
|
362
394
|
};
|
|
@@ -369,6 +401,7 @@ export const getAllTransactionsIOS = async () => {
|
|
|
369
401
|
* @see {@link https://openiap.dev/docs/apis/ios/clear-transaction-ios}
|
|
370
402
|
*/
|
|
371
403
|
export const clearTransactionIOS = async () => {
|
|
404
|
+
requireIosPlatform('clearTransactionIOS');
|
|
372
405
|
return !!(await ExpoIapModule.clearTransactionIOS());
|
|
373
406
|
};
|
|
374
407
|
/**
|
|
@@ -391,6 +424,7 @@ export const deepLinkToSubscriptionsIOS = () => Linking.openURL('https://apps.ap
|
|
|
391
424
|
* @see {@link https://openiap.dev/docs/apis/ios/can-present-external-purchase-notice-ios}
|
|
392
425
|
*/
|
|
393
426
|
export const canPresentExternalPurchaseNoticeIOS = async () => {
|
|
427
|
+
requireIosPlatform('canPresentExternalPurchaseNoticeIOS');
|
|
394
428
|
return !!(await ExpoIapModule.canPresentExternalPurchaseNoticeIOS());
|
|
395
429
|
};
|
|
396
430
|
/**
|
|
@@ -404,6 +438,7 @@ export const canPresentExternalPurchaseNoticeIOS = async () => {
|
|
|
404
438
|
* @see {@link https://openiap.dev/docs/apis/ios/present-external-purchase-notice-sheet-ios}
|
|
405
439
|
*/
|
|
406
440
|
export const presentExternalPurchaseNoticeSheetIOS = async () => {
|
|
441
|
+
requireIosPlatform('presentExternalPurchaseNoticeSheetIOS');
|
|
407
442
|
const result = await ExpoIapModule.presentExternalPurchaseNoticeSheetIOS();
|
|
408
443
|
return result;
|
|
409
444
|
};
|
|
@@ -417,6 +452,7 @@ export const presentExternalPurchaseNoticeSheetIOS = async () => {
|
|
|
417
452
|
* @see {@link https://openiap.dev/docs/apis/ios/present-external-purchase-link-ios}
|
|
418
453
|
*/
|
|
419
454
|
export const presentExternalPurchaseLinkIOS = async (url) => {
|
|
455
|
+
requireIosPlatform('presentExternalPurchaseLinkIOS');
|
|
420
456
|
const result = await ExpoIapModule.presentExternalPurchaseLinkIOS(url);
|
|
421
457
|
return result;
|
|
422
458
|
};
|
|
@@ -431,6 +467,7 @@ export const presentExternalPurchaseLinkIOS = async (url) => {
|
|
|
431
467
|
* @see {@link https://openiap.dev/docs/apis/ios/is-eligible-for-external-purchase-custom-link-ios}
|
|
432
468
|
*/
|
|
433
469
|
export const isEligibleForExternalPurchaseCustomLinkIOS = async () => {
|
|
470
|
+
requireIosPlatform('isEligibleForExternalPurchaseCustomLinkIOS');
|
|
434
471
|
return !!(await ExpoIapModule.isEligibleForExternalPurchaseCustomLinkIOS());
|
|
435
472
|
};
|
|
436
473
|
/**
|
|
@@ -445,6 +482,7 @@ export const isEligibleForExternalPurchaseCustomLinkIOS = async () => {
|
|
|
445
482
|
* @see {@link https://openiap.dev/docs/apis/ios/get-external-purchase-custom-link-token-ios}
|
|
446
483
|
*/
|
|
447
484
|
export const getExternalPurchaseCustomLinkTokenIOS = async (tokenType) => {
|
|
485
|
+
requireIosPlatform('getExternalPurchaseCustomLinkTokenIOS');
|
|
448
486
|
if (!tokenType) {
|
|
449
487
|
throw new Error("getExternalPurchaseCustomLinkTokenIOS requires a tokenType ('acquisition' or 'services')");
|
|
450
488
|
}
|
|
@@ -464,6 +502,7 @@ export const getExternalPurchaseCustomLinkTokenIOS = async (tokenType) => {
|
|
|
464
502
|
* @see {@link https://openiap.dev/docs/apis/ios/show-external-purchase-custom-link-notice-ios}
|
|
465
503
|
*/
|
|
466
504
|
export const showExternalPurchaseCustomLinkNoticeIOS = async (noticeType) => {
|
|
505
|
+
requireIosPlatform('showExternalPurchaseCustomLinkNoticeIOS');
|
|
467
506
|
if (!noticeType) {
|
|
468
507
|
throw new Error("showExternalPurchaseCustomLinkNoticeIOS requires a noticeType ('browser')");
|
|
469
508
|
}
|