expo-iap 2.0.0 → 2.2.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -19
- package/android/src/main/java/expo/modules/iap/ExpoIapModule.kt +10 -9
- package/build/ExpoIap.types.d.ts +31 -40
- package/build/ExpoIap.types.d.ts.map +1 -1
- package/build/ExpoIap.types.js +0 -11
- package/build/ExpoIap.types.js.map +1 -1
- package/build/index.d.ts +3 -4
- package/build/index.d.ts.map +1 -1
- package/build/index.js +33 -46
- package/build/index.js.map +1 -1
- package/build/modules/android.d.ts +12 -4
- package/build/modules/android.d.ts.map +1 -1
- package/build/modules/android.js +8 -4
- package/build/modules/android.js.map +1 -1
- package/build/modules/ios.d.ts +16 -8
- package/build/modules/ios.d.ts.map +1 -1
- package/build/modules/ios.js +9 -5
- package/build/modules/ios.js.map +1 -1
- package/build/types/ExpoIapAndroid.types.d.ts +31 -31
- package/build/types/ExpoIapAndroid.types.d.ts.map +1 -1
- package/build/types/ExpoIapAndroid.types.js +6 -0
- package/build/types/ExpoIapAndroid.types.js.map +1 -1
- package/build/types/ExpoIapIos.types.d.ts +31 -34
- package/build/types/ExpoIapIos.types.d.ts.map +1 -1
- package/build/types/ExpoIapIos.types.js.map +1 -1
- package/build/useIap.d.ts +23 -0
- package/build/useIap.d.ts.map +1 -0
- package/build/useIap.js +100 -0
- package/build/useIap.js.map +1 -0
- package/bun.lockb +0 -0
- package/iap.md +161 -0
- package/ios/ExpoIapModule.swift +124 -31
- package/package.json +5 -5
- package/plugin/build/withIAP.d.ts +0 -3
- package/plugin/build/withIAP.js +31 -49
- package/plugin/src/withIAP.ts +39 -86
- package/src/ExpoIap.types.ts +48 -48
- package/src/index.ts +50 -96
- package/src/modules/android.ts +16 -12
- package/src/modules/ios.ts +21 -18
- package/src/types/ExpoIapAndroid.types.ts +37 -33
- package/src/types/ExpoIapIos.types.ts +36 -40
- package/src/useIap.ts +185 -0
package/README.md
CHANGED
|
@@ -1,32 +1,28 @@
|
|
|
1
|
-
<img src="https://github.com/user-attachments/assets/f51a4b1b-b257-47bf-afe7-5ef8692f0594"
|
|
1
|
+
<img src="https://github.com/user-attachments/assets/f51a4b1b-b257-47bf-afe7-5ef8692f0594" />
|
|
2
|
+
|
|
3
|
+
[](https://npmjs.org/package/expo-iap) [](https://npmjs.org/package/expo-iap) [](https://app.fossa.com/projects/git%2Bgithub.com%2Fhyochan%2Fexpo-iap?ref=badge_shield&issueType=license)
|
|
2
4
|
|
|
3
5
|
In App Purchase module in Expo
|
|
4
6
|
|
|
7
|
+
# Notice
|
|
8
|
+
|
|
9
|
+
The `expo-iap` module has been migrated from [react-native-iap](https://github.com/dooboolab/react-native-iap). Moving forward, the `react-native-iap` repository will gradually be deprecated, and `expo-iap` will become the actively maintained module. Please take note of this transition. For more details, refer to the [Future Roadmap and Discussion in react-native-iap](https://github.com/dooboolab-community/react-native-iap/discussions/2754). Additionally, you can check the [Current Project Status comment](https://github.com/dooboolab-community/react-native-iap/discussions/2754#discussioncomment-10510249) to stay updated on the project's progress.
|
|
10
|
+
|
|
5
11
|
# API documentation
|
|
6
12
|
|
|
7
13
|
- [Documentation for the main branch](https://github.com/expo/expo/blob/main/docs/pages/versions/unversioned/sdk/iap.md)
|
|
8
14
|
- [Documentation for the latest stable release](https://docs.expo.dev/versions/latest/sdk/iap/)
|
|
9
15
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
For [managed](https://docs.expo.dev/archive/managed-vs-bare/) Expo projects, please follow the installation instructions in the [API documentation for the latest stable release](#api-documentation). If you follow the link and there is no documentation available then this library is not yet usable within managed projects — it is likely to be included in an upcoming Expo SDK release.
|
|
13
|
-
|
|
14
|
-
# Installation in bare React Native projects
|
|
15
|
-
|
|
16
|
-
For bare React Native projects, you must ensure that you have [installed and configured the `expo` package](https://docs.expo.dev/bare/installing-expo-modules/) before continuing.
|
|
16
|
+
> The updated documentation hasn’t been published to Expo yet. I’d love for you to take a look at [iap.md](./iap.md) and share your thoughts—any feedback would be greatly appreciated!
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
## Sponsors
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
npm install expo-iap
|
|
22
|
-
```
|
|
20
|
+
### <p style="color: gold;">Gold Tier</p>
|
|
23
21
|
|
|
24
|
-
|
|
22
|
+
<a href="https://www.courier.com/?utm_source=react-native-iap&utm_campaign=osssponsors">
|
|
23
|
+
<img width="420" alt="courier_dot_com" src="https://github.com/user-attachments/assets/319d8966-6839-498d-8ead-ce8cc72c3bca" />
|
|
24
|
+
</a>
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
## Past Sponsors
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
"ios": {
|
|
30
|
-
"deploymentTarget": "15.0"
|
|
31
|
-
},
|
|
32
|
-
```
|
|
28
|
+
<a href="https://namiml.com"><img src="https://github.com/hyochan/react-native-iap/assets/27461460/89d71f61-bb73-400a-83bd-fe0f96eb726e" width="280"/></a>
|
|
@@ -71,8 +71,8 @@ class ExpoIapModule :
|
|
|
71
71
|
purchases.forEach { purchase ->
|
|
72
72
|
val item =
|
|
73
73
|
mutableMapOf<String, Any?>(
|
|
74
|
-
"
|
|
75
|
-
"
|
|
74
|
+
"id" to purchase.products.firstOrNull() as Any?,
|
|
75
|
+
"ids" to purchase.products,
|
|
76
76
|
"transactionId" to purchase.orderId,
|
|
77
77
|
"transactionDate" to purchase.purchaseTime.toDouble(),
|
|
78
78
|
"transactionReceipt" to purchase.originalJson,
|
|
@@ -160,11 +160,12 @@ class ExpoIapModule :
|
|
|
160
160
|
skus[productDetails.productId] = productDetails
|
|
161
161
|
|
|
162
162
|
mapOf(
|
|
163
|
-
"
|
|
163
|
+
"id" to productDetails.productId,
|
|
164
164
|
"title" to productDetails.title,
|
|
165
165
|
"description" to productDetails.description,
|
|
166
|
-
"
|
|
167
|
-
"
|
|
166
|
+
"type" to productDetails.productType,
|
|
167
|
+
"displayName" to productDetails.name,
|
|
168
|
+
"platform" to "android", // Add platform identifier
|
|
168
169
|
"oneTimePurchaseOfferDetails" to
|
|
169
170
|
productDetails.oneTimePurchaseOfferDetails?.let {
|
|
170
171
|
mapOf(
|
|
@@ -220,8 +221,8 @@ class ExpoIapModule :
|
|
|
220
221
|
val item =
|
|
221
222
|
mutableMapOf<String, Any?>(
|
|
222
223
|
// kept for convenience/backward-compatibility. productIds has the complete list
|
|
223
|
-
"
|
|
224
|
-
"
|
|
224
|
+
"id" to purchase.products.firstOrNull() as Any?,
|
|
225
|
+
"ids" to purchase.products,
|
|
225
226
|
"transactionId" to purchase.orderId,
|
|
226
227
|
"transactionDate" to purchase.purchaseTime.toDouble(),
|
|
227
228
|
"transactionReceipt" to purchase.originalJson,
|
|
@@ -268,8 +269,8 @@ class ExpoIapModule :
|
|
|
268
269
|
purchaseHistoryRecordList?.forEach { purchase ->
|
|
269
270
|
val item =
|
|
270
271
|
mutableMapOf<String, Any?>(
|
|
271
|
-
"
|
|
272
|
-
"
|
|
272
|
+
"id" to purchase.products.firstOrNull() as Any?,
|
|
273
|
+
"ids" to purchase.products,
|
|
273
274
|
"transactionDate" to purchase.purchaseTime.toDouble(),
|
|
274
275
|
"transactionReceipt" to purchase.originalJson,
|
|
275
276
|
"purchaseToken" to purchase.purchaseToken,
|
package/build/ExpoIap.types.d.ts
CHANGED
|
@@ -1,55 +1,47 @@
|
|
|
1
|
-
import { ProductAndroid, RequestPurchaseAndroidProps, RequestSubscriptionAndroidProps, SubscriptionProductAndroid } from './types/ExpoIapAndroid.types';
|
|
2
|
-
import { ProductIos, RequestPurchaseIosProps, RequestSubscriptionIosProps, SubscriptionProductIos } from './types/ExpoIapIos.types';
|
|
1
|
+
import { ProductAndroid, ProductPurchaseAndroid, RequestPurchaseAndroidProps, RequestSubscriptionAndroidProps, SubscriptionProductAndroid } from './types/ExpoIapAndroid.types';
|
|
2
|
+
import { ProductIos, ProductPurchaseIos, RequestPurchaseIosProps, RequestSubscriptionIosProps, SubscriptionProductIos } from './types/ExpoIapIos.types';
|
|
3
3
|
export type ChangeEventPayload = {
|
|
4
4
|
value: string;
|
|
5
5
|
};
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Base product type with common properties shared between iOS and Android
|
|
8
|
+
*/
|
|
9
|
+
export type ProductBase = {
|
|
10
|
+
id: string;
|
|
11
|
+
title: string;
|
|
12
|
+
description: string;
|
|
13
|
+
type: ProductType;
|
|
14
|
+
displayName?: string;
|
|
15
|
+
displayPrice?: string;
|
|
16
|
+
price?: number;
|
|
17
|
+
currency?: string;
|
|
18
|
+
};
|
|
19
|
+
export type IosPlatform = {
|
|
20
|
+
platform: 'ios';
|
|
21
|
+
};
|
|
22
|
+
export type AndroidPlatform = {
|
|
23
|
+
platform: 'android';
|
|
24
|
+
};
|
|
7
25
|
export declare enum ProductType {
|
|
8
26
|
InAppPurchase = "inapp",
|
|
9
27
|
Subscription = "subs"
|
|
10
28
|
}
|
|
11
|
-
export type
|
|
12
|
-
|
|
13
|
-
declare enum PurchaseStateAndroid {
|
|
14
|
-
UNSPECIFIED_STATE = 0,
|
|
15
|
-
PURCHASED = 1,
|
|
16
|
-
PENDING = 2
|
|
17
|
-
}
|
|
18
|
-
export type ProductPurchase = {
|
|
19
|
-
productId: string;
|
|
29
|
+
export type PurchaseBase = {
|
|
30
|
+
id: string;
|
|
20
31
|
transactionId?: string;
|
|
21
32
|
transactionDate: number;
|
|
22
33
|
transactionReceipt: string;
|
|
23
34
|
purchaseToken?: string;
|
|
24
|
-
quantityIOS?: number;
|
|
25
|
-
originalTransactionDateIOS?: number;
|
|
26
|
-
originalTransactionIdentifierIOS?: string;
|
|
27
|
-
verificationResultIOS?: string;
|
|
28
|
-
appAccountToken?: string;
|
|
29
|
-
productIds?: string[];
|
|
30
|
-
dataAndroid?: string;
|
|
31
|
-
signatureAndroid?: string;
|
|
32
|
-
autoRenewingAndroid?: boolean;
|
|
33
|
-
purchaseStateAndroid?: PurchaseStateAndroid;
|
|
34
|
-
isAcknowledgedAndroid?: boolean;
|
|
35
|
-
packageNameAndroid?: string;
|
|
36
|
-
developerPayloadAndroid?: string;
|
|
37
|
-
obfuscatedAccountIdAndroid?: string;
|
|
38
|
-
obfuscatedProfileIdAndroid?: string;
|
|
39
35
|
};
|
|
40
|
-
export type
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
export type SubscriptionPurchase = {
|
|
46
|
-
autoRenewingAndroid?: boolean;
|
|
47
|
-
originalTransactionDateIOS?: number;
|
|
48
|
-
originalTransactionIdentifierIOS?: string;
|
|
49
|
-
verificationResultIOS?: string;
|
|
50
|
-
transactionReasonIOS?: TransactionReason | string;
|
|
51
|
-
} & ProductPurchase;
|
|
36
|
+
export type Product = (ProductAndroid & AndroidPlatform) | (ProductIos & IosPlatform);
|
|
37
|
+
export type ProductPurchase = (ProductPurchaseAndroid & AndroidPlatform) | (ProductPurchaseIos & IosPlatform);
|
|
38
|
+
export type SubscriptionPurchase = (ProductPurchaseAndroid & AndroidPlatform & {
|
|
39
|
+
autoRenewingAndroid: boolean;
|
|
40
|
+
}) | (ProductPurchaseIos & IosPlatform);
|
|
52
41
|
export type Purchase = ProductPurchase | SubscriptionPurchase;
|
|
42
|
+
export type RequestPurchaseProps = RequestPurchaseIosProps | RequestPurchaseAndroidProps;
|
|
43
|
+
export type SubscriptionProduct = (SubscriptionProductAndroid & AndroidPlatform) | (SubscriptionProductIos & IosPlatform);
|
|
44
|
+
export type RequestSubscriptionProps = RequestSubscriptionAndroidProps | RequestSubscriptionIosProps;
|
|
53
45
|
export type PurchaseResult = {
|
|
54
46
|
responseCode?: number;
|
|
55
47
|
debugMessage?: string;
|
|
@@ -85,5 +77,4 @@ export declare class PurchaseError implements Error {
|
|
|
85
77
|
productId?: string | undefined;
|
|
86
78
|
constructor(name: string, message: string, responseCode?: number | undefined, debugMessage?: string | undefined, code?: ErrorCode | undefined, productId?: string | undefined);
|
|
87
79
|
}
|
|
88
|
-
export {};
|
|
89
80
|
//# sourceMappingURL=ExpoIap.types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoIap.types.d.ts","sourceRoot":"","sources":["../src/ExpoIap.types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,2BAA2B,EAC3B,+BAA+B,EAC/B,0BAA0B,EAC3B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,UAAU,EACV,uBAAuB,EACvB,2BAA2B,EAC3B,sBAAsB,EACvB,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"ExpoIap.types.d.ts","sourceRoot":"","sources":["../src/ExpoIap.types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,sBAAsB,EACtB,2BAA2B,EAC3B,+BAA+B,EAC/B,0BAA0B,EAC3B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,UAAU,EACV,kBAAkB,EAClB,uBAAuB,EACvB,2BAA2B,EAC3B,sBAAsB,EACvB,MAAM,0BAA0B,CAAC;AAElC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,WAAW,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAGF,MAAM,MAAM,WAAW,GAAG;IAAC,QAAQ,EAAE,KAAK,CAAA;CAAC,CAAC;AAC5C,MAAM,MAAM,eAAe,GAAG;IAAC,QAAQ,EAAE,SAAS,CAAA;CAAC,CAAC;AAEpD,oBAAY,WAAW;IACrB,aAAa,UAAU;IACvB,Y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mBAAmB;IACjC,eAAe,oBAAoB;IACnC,eAAe,oBAAoB;IACnC,gBAAgB,qBAAqB;IACrC,yBAAyB,8BAA8B;IACvD,cAAc,mBAAmB;IACjC,WAAW,gBAAgB;IAC3B,eAAe,oBAAoB;IACnC,iBAAiB,sBAAsB;IACvC,mCAAmC,wCAAwC;IAC3E,kBAAkB,uBAAuB;IACzC,aAAa,kBAAkB;IAC/B,mBAAmB,wBAAwB;CAC5C;AAED,qBAAa,aAAc,YAAW,KAAK;IAEhC,IAAI,EAAE,MAAM;IACZ,OAAO,EAAE,MAAM;IACf,YAAY,CAAC;IACb,YAAY,CAAC;IACb,IAAI,CAAC;IACL,SAAS,CAAC;gBALV,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,YAAY,CAAC,oBAAQ,EACrB,YAAY,CAAC,oBAAQ,EACrB,IAAI,CAAC,uBAAW,EAChB,SAAS,CAAC,oBAAQ;CAS5B"}
|
package/build/ExpoIap.types.js
CHANGED
|
@@ -3,17 +3,6 @@ export var ProductType;
|
|
|
3
3
|
ProductType["InAppPurchase"] = "inapp";
|
|
4
4
|
ProductType["Subscription"] = "subs";
|
|
5
5
|
})(ProductType || (ProductType = {}));
|
|
6
|
-
var PurchaseStateAndroid;
|
|
7
|
-
(function (PurchaseStateAndroid) {
|
|
8
|
-
PurchaseStateAndroid[PurchaseStateAndroid["UNSPECIFIED_STATE"] = 0] = "UNSPECIFIED_STATE";
|
|
9
|
-
PurchaseStateAndroid[PurchaseStateAndroid["PURCHASED"] = 1] = "PURCHASED";
|
|
10
|
-
PurchaseStateAndroid[PurchaseStateAndroid["PENDING"] = 2] = "PENDING";
|
|
11
|
-
})(PurchaseStateAndroid || (PurchaseStateAndroid = {}));
|
|
12
|
-
var TransactionReason;
|
|
13
|
-
(function (TransactionReason) {
|
|
14
|
-
TransactionReason["PURCHASE"] = "PURCHASE";
|
|
15
|
-
TransactionReason["RENEWAL"] = "RENEWAL";
|
|
16
|
-
})(TransactionReason || (TransactionReason = {}));
|
|
17
6
|
export var ErrorCode;
|
|
18
7
|
(function (ErrorCode) {
|
|
19
8
|
ErrorCode["E_UNKNOWN"] = "E_UNKNOWN";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoIap.types.js","sourceRoot":"","sources":["../src/ExpoIap.types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ExpoIap.types.js","sourceRoot":"","sources":["../src/ExpoIap.types.ts"],"names":[],"mappings":"AAqCA,MAAM,CAAN,IAAY,WAGX;AAHD,WAAY,WAAW;IACrB,sCAAuB,CAAA;IACvB,oCAAqB,CAAA;AACvB,CAAC,EAHW,WAAW,KAAX,WAAW,QAGtB;AAgDD,MAAM,CAAN,IAAY,SAkBX;AAlBD,WAAY,SAAS;IACnB,oCAAuB,CAAA;IACvB,kDAAqC,CAAA;IACrC,0CAA6B,CAAA;IAC7B,sDAAyC,CAAA;IACzC,8CAAiC,CAAA;IACjC,gDAAmC,CAAA;IACnC,gDAAmC,CAAA;IACnC,kDAAqC,CAAA;IACrC,oEAAuD,CAAA;IACvD,8CAAiC,CAAA;IACjC,wCAA2B,CAAA;IAC3B,gDAAmC,CAAA;IACnC,oDAAuC,CAAA;IACvC,wFAA2E,CAAA;IAC3E,sDAAyC,CAAA;IACzC,4CAA+B,CAAA;IAC/B,wDAA2C,CAAA;AAC7C,CAAC,EAlBW,SAAS,KAAT,SAAS,QAkBpB;AAED,MAAM,OAAO,aAAa;IAEf;IACA;IACA;IACA;IACA;IACA;IANT,YACS,IAAY,EACZ,OAAe,EACf,YAAqB,EACrB,YAAqB,EACrB,IAAgB,EAChB,SAAkB;QALlB,SAAI,GAAJ,IAAI,CAAQ;QACZ,YAAO,GAAP,OAAO,CAAQ;QACf,iBAAY,GAAZ,YAAY,CAAS;QACrB,iBAAY,GAAZ,YAAY,CAAS;QACrB,SAAI,GAAJ,IAAI,CAAY;QAChB,cAAS,GAAT,SAAS,CAAS;QAEzB,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;QACxC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;CACF","sourcesContent":["import {\n ProductAndroid,\n ProductPurchaseAndroid,\n RequestPurchaseAndroidProps,\n RequestSubscriptionAndroidProps,\n SubscriptionProductAndroid,\n} from './types/ExpoIapAndroid.types';\nimport {\n ProductIos,\n ProductPurchaseIos,\n RequestPurchaseIosProps,\n RequestSubscriptionIosProps,\n SubscriptionProductIos,\n} from './types/ExpoIapIos.types';\n\nexport type ChangeEventPayload = {\n value: string;\n};\n\n/**\n * Base product type with common properties shared between iOS and Android\n */\nexport type ProductBase = {\n id: string;\n title: string;\n description: string;\n type: ProductType;\n displayName?: string;\n displayPrice?: string;\n price?: number;\n currency?: string;\n};\n\n// Define literal platform types for better type discrimination\nexport type IosPlatform = {platform: 'ios'};\nexport type AndroidPlatform = {platform: 'android'};\n\nexport enum ProductType {\n InAppPurchase = 'inapp',\n Subscription = 'subs',\n}\n\n// Common base purchase type\nexport type PurchaseBase = {\n id: string;\n transactionId?: string;\n transactionDate: number;\n transactionReceipt: string;\n purchaseToken?: string;\n};\n\n// Union type for platform-specific product types with proper discriminators\nexport type Product =\n | (ProductAndroid & AndroidPlatform)\n | (ProductIos & IosPlatform);\n\n// Union type for platform-specific purchase types with proper discriminators\nexport type ProductPurchase =\n | (ProductPurchaseAndroid & AndroidPlatform)\n | (ProductPurchaseIos & IosPlatform);\n\n// Union type for platform-specific subscription purchase types with proper discriminators\nexport type SubscriptionPurchase =\n | (ProductPurchaseAndroid & AndroidPlatform & { autoRenewingAndroid: boolean })\n | (ProductPurchaseIos & IosPlatform);\n\nexport type Purchase = ProductPurchase | SubscriptionPurchase;\n\nexport type RequestPurchaseProps =\n | RequestPurchaseIosProps\n | RequestPurchaseAndroidProps;\n\nexport type SubscriptionProduct =\n | (SubscriptionProductAndroid & AndroidPlatform)\n | (SubscriptionProductIos & IosPlatform);\n\nexport type RequestSubscriptionProps =\n | RequestSubscriptionAndroidProps\n | RequestSubscriptionIosProps;\n\nexport type PurchaseResult = {\n responseCode?: number;\n debugMessage?: string;\n code?: string;\n message?: string;\n purchaseToken?: string;\n};\n\nexport enum ErrorCode {\n E_UNKNOWN = 'E_UNKNOWN',\n E_USER_CANCELLED = 'E_USER_CANCELLED',\n E_USER_ERROR = 'E_USER_ERROR',\n E_ITEM_UNAVAILABLE = 'E_ITEM_UNAVAILABLE',\n E_REMOTE_ERROR = 'E_REMOTE_ERROR',\n E_NETWORK_ERROR = 'E_NETWORK_ERROR',\n E_SERVICE_ERROR = 'E_SERVICE_ERROR',\n E_RECEIPT_FAILED = 'E_RECEIPT_FAILED',\n E_RECEIPT_FINISHED_FAILED = 'E_RECEIPT_FINISHED_FAILED',\n E_NOT_PREPARED = 'E_NOT_PREPARED',\n E_NOT_ENDED = 'E_NOT_ENDED',\n E_ALREADY_OWNED = 'E_ALREADY_OWNED',\n E_DEVELOPER_ERROR = 'E_DEVELOPER_ERROR',\n E_BILLING_RESPONSE_JSON_PARSE_ERROR = 'E_BILLING_RESPONSE_JSON_PARSE_ERROR',\n E_DEFERRED_PAYMENT = 'E_DEFERRED_PAYMENT',\n E_INTERRUPTED = 'E_INTERRUPTED',\n E_IAP_NOT_AVAILABLE = 'E_IAP_NOT_AVAILABLE',\n}\n\nexport class PurchaseError implements Error {\n constructor(\n public name: string,\n public message: string,\n public responseCode?: number,\n public debugMessage?: string,\n public code?: ErrorCode,\n public productId?: string,\n ) {\n this.name = '[expo-iap]: PurchaseError';\n this.message = message;\n this.responseCode = responseCode;\n this.debugMessage = debugMessage;\n this.code = code;\n this.productId = productId;\n }\n}\n"]}
|
package/build/index.d.ts
CHANGED
|
@@ -18,14 +18,12 @@ export declare function initConnection(): any;
|
|
|
18
18
|
export declare const getProducts: (skus: string[]) => Promise<Product[]>;
|
|
19
19
|
export declare const getSubscriptions: (skus: string[]) => Promise<SubscriptionProduct[]>;
|
|
20
20
|
export declare function endConnection(): Promise<boolean>;
|
|
21
|
-
export declare const getPurchaseHistory: ({ alsoPublishToEventListener,
|
|
21
|
+
export declare const getPurchaseHistory: ({ alsoPublishToEventListener, onlyIncludeActiveItems, }?: {
|
|
22
22
|
alsoPublishToEventListener?: boolean;
|
|
23
|
-
automaticallyFinishRestoredTransactions?: boolean;
|
|
24
23
|
onlyIncludeActiveItems?: boolean;
|
|
25
24
|
}) => Promise<ProductPurchase[]>;
|
|
26
|
-
export declare const getAvailablePurchases: ({ alsoPublishToEventListener,
|
|
25
|
+
export declare const getAvailablePurchases: ({ alsoPublishToEventListener, onlyIncludeActiveItems, }?: {
|
|
27
26
|
alsoPublishToEventListener?: boolean;
|
|
28
|
-
automaticallyFinishRestoredTransactions?: boolean;
|
|
29
27
|
onlyIncludeActiveItems?: boolean;
|
|
30
28
|
}) => Promise<ProductPurchase[]>;
|
|
31
29
|
export declare const requestPurchase: (request: RequestPurchaseIosProps | RequestPurchaseAndroidProps) => Promise<ProductPurchase | ProductPurchase[] | void>;
|
|
@@ -35,4 +33,5 @@ export declare const finishTransaction: ({ purchase, isConsumable, developerPayl
|
|
|
35
33
|
isConsumable?: boolean;
|
|
36
34
|
developerPayloadAndroid?: string;
|
|
37
35
|
}) => Promise<PurchaseResult | boolean>;
|
|
36
|
+
export * from './useIap';
|
|
38
37
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAqB,YAAY,EAAC,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":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AAC,EAAE,OAAO,CAAC;CAClC,KAAQ,QAAQ,eAAe,EAAE,CAoB7B,CAAC;AAiBN,eAAO,MAAM,eAAe,YACjB,uBAAuB,GAAG,2BAA2B,KAC7D,QAAQ,eAAe,GAAG,eAAe,EAAE,GAAG,IAAI,CA6ChD,CAAC;AAEN,eAAO,MAAM,mBAAmB,YACrB,wBAAwB,KAChC,QAAQ,oBAAoB,GAAG,oBAAoB,EAAE,GAAG,IAAI,GAAG,IAAI,CA6CjE,CAAC;AAEN,eAAO,MAAM,iBAAiB,yDAI3B;IACD,QAAQ,EAAE,QAAQ,CAAC;IACnB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,uBAAuB,CAAC,EAAE,MAAM,CAAC;CAClC,KAAG,QAAQ,cAAc,GAAG,OAAO,CAiCnC,CAAC;AAEF,cAAc,UAAU,CAAC"}
|
package/build/index.js
CHANGED
|
@@ -4,7 +4,8 @@ import { NativeModulesProxy, EventEmitter } from 'expo-modules-core';
|
|
|
4
4
|
import { Platform } from 'react-native';
|
|
5
5
|
import { ProductType, } from './ExpoIap.types';
|
|
6
6
|
import ExpoIapModule from './ExpoIapModule';
|
|
7
|
-
import { isProductIos } from './modules/ios';
|
|
7
|
+
import { isProductIos, isSubscriptionProductIos } from './modules/ios';
|
|
8
|
+
import { isProductAndroid, isSubscriptionProductAndroid, } from './modules/android';
|
|
8
9
|
export * from './modules/android';
|
|
9
10
|
export * from './modules/ios';
|
|
10
11
|
// Get the native constant value.
|
|
@@ -30,17 +31,19 @@ export function initConnection() {
|
|
|
30
31
|
return ExpoIapModule.initConnection();
|
|
31
32
|
}
|
|
32
33
|
export const getProducts = async (skus) => {
|
|
34
|
+
console.log('getProducts', skus);
|
|
33
35
|
if (!skus?.length) {
|
|
34
36
|
return Promise.reject(new Error('"skus" is required'));
|
|
35
37
|
}
|
|
36
38
|
return Platform.select({
|
|
37
39
|
ios: async () => {
|
|
38
|
-
const items =
|
|
40
|
+
const items = await ExpoIapModule.getItems(skus);
|
|
41
|
+
console.log('items', items);
|
|
39
42
|
return items.filter((item) => isProductIos(item));
|
|
40
43
|
},
|
|
41
44
|
android: async () => {
|
|
42
45
|
const products = await ExpoIapModule.getItemsByType(ProductType.InAppPurchase, skus);
|
|
43
|
-
return products;
|
|
46
|
+
return products.filter((product) => isProductAndroid(product));
|
|
44
47
|
},
|
|
45
48
|
default: () => Promise.reject(new Error('Unsupported Platform')),
|
|
46
49
|
})();
|
|
@@ -51,11 +54,28 @@ export const getSubscriptions = async (skus) => {
|
|
|
51
54
|
}
|
|
52
55
|
return Platform.select({
|
|
53
56
|
ios: async () => {
|
|
54
|
-
const
|
|
55
|
-
return
|
|
57
|
+
const rawItems = await ExpoIapModule.getItems(skus);
|
|
58
|
+
return rawItems.filter((item) => {
|
|
59
|
+
if (!isSubscriptionProductIos(item))
|
|
60
|
+
return false;
|
|
61
|
+
return (typeof item === 'object' &&
|
|
62
|
+
item !== null &&
|
|
63
|
+
'id' in item &&
|
|
64
|
+
typeof item.id === 'string' &&
|
|
65
|
+
skus.includes(item.id));
|
|
66
|
+
});
|
|
56
67
|
},
|
|
57
68
|
android: async () => {
|
|
58
|
-
|
|
69
|
+
const rawItems = await ExpoIapModule.getItemsByType('subs', skus);
|
|
70
|
+
return rawItems.filter((item) => {
|
|
71
|
+
if (!isSubscriptionProductAndroid(item))
|
|
72
|
+
return false;
|
|
73
|
+
return (typeof item === 'object' &&
|
|
74
|
+
item !== null &&
|
|
75
|
+
'id' in item &&
|
|
76
|
+
typeof item.id === 'string' &&
|
|
77
|
+
skus.includes(item.id));
|
|
78
|
+
});
|
|
59
79
|
},
|
|
60
80
|
default: () => Promise.reject(new Error('Unsupported Platform')),
|
|
61
81
|
})();
|
|
@@ -63,7 +83,7 @@ export const getSubscriptions = async (skus) => {
|
|
|
63
83
|
export async function endConnection() {
|
|
64
84
|
return ExpoIapModule.endConnection();
|
|
65
85
|
}
|
|
66
|
-
export const getPurchaseHistory = ({ alsoPublishToEventListener = false,
|
|
86
|
+
export const getPurchaseHistory = ({ alsoPublishToEventListener = false, onlyIncludeActiveItems = false, } = {}) => (Platform.select({
|
|
67
87
|
ios: async () => {
|
|
68
88
|
return ExpoIapModule.getAvailableItems(alsoPublishToEventListener, onlyIncludeActiveItems);
|
|
69
89
|
},
|
|
@@ -73,7 +93,7 @@ export const getPurchaseHistory = ({ alsoPublishToEventListener = false, automat
|
|
|
73
93
|
return products.concat(subscriptions);
|
|
74
94
|
},
|
|
75
95
|
}) || (() => Promise.resolve([])))();
|
|
76
|
-
export const getAvailablePurchases = ({ alsoPublishToEventListener = false,
|
|
96
|
+
export const getAvailablePurchases = ({ alsoPublishToEventListener = false, onlyIncludeActiveItems = true, } = {}) => (Platform.select({
|
|
77
97
|
ios: () => ExpoIapModule.getAvailableItems(alsoPublishToEventListener, onlyIncludeActiveItems),
|
|
78
98
|
android: async () => {
|
|
79
99
|
const products = await ExpoIapModule.getAvailableItemsByType(ProductType.InAppPurchase);
|
|
@@ -93,44 +113,14 @@ const offerToRecordIos = (offer) => {
|
|
|
93
113
|
timestamp: offer.timestamp.toString(),
|
|
94
114
|
};
|
|
95
115
|
};
|
|
96
|
-
const iosTransactionToPurchaseMap = ({ id, originalPurchaseDate, productID, purchaseDate, purchasedQuantity, originalID, verificationResult, appAccountToken, jsonRepresentation, }) => {
|
|
97
|
-
let transactionReasonIOS;
|
|
98
|
-
try {
|
|
99
|
-
if (jsonRepresentation) {
|
|
100
|
-
const transactionData = JSON.parse(jsonRepresentation);
|
|
101
|
-
transactionReasonIOS = transactionData.transactionReason;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
catch (e) {
|
|
105
|
-
console.log('SK2 Error parsing jsonRepresentation', e);
|
|
106
|
-
}
|
|
107
|
-
const purchase = {
|
|
108
|
-
productId: productID,
|
|
109
|
-
transactionId: String(id),
|
|
110
|
-
transactionDate: purchaseDate, //??
|
|
111
|
-
transactionReceipt: '', // Not available
|
|
112
|
-
purchaseToken: '', //Not available
|
|
113
|
-
quantityIOS: purchasedQuantity,
|
|
114
|
-
originalTransactionDateIOS: originalPurchaseDate,
|
|
115
|
-
originalTransactionIdentifierIOS: originalID,
|
|
116
|
-
verificationResultIOS: verificationResult ?? '',
|
|
117
|
-
appAccountToken: appAccountToken ?? '',
|
|
118
|
-
transactionReasonIOS: transactionReasonIOS ?? '',
|
|
119
|
-
};
|
|
120
|
-
return purchase;
|
|
121
|
-
};
|
|
122
116
|
export const requestPurchase = (request) => (Platform.select({
|
|
123
117
|
ios: async () => {
|
|
124
118
|
if (!('sku' in request)) {
|
|
125
119
|
throw new Error('sku is required for iOS purchase');
|
|
126
120
|
}
|
|
127
|
-
const { sku,
|
|
128
|
-
if (andDangerouslyFinishTransactionAutomaticallyIOS) {
|
|
129
|
-
console.warn('You are dangerously allowing expo-iap to finish your transaction automatically. You should set andDangerouslyFinishTransactionAutomatically to false when calling requestPurchase and call finishTransaction manually when you have delivered the purchased goods to the user. It defaults to true to provide backwards compatibility. Will default to false in version 4.0.0.');
|
|
130
|
-
}
|
|
121
|
+
const { sku, appAccountToken, quantity, withOffer } = request;
|
|
131
122
|
const offer = offerToRecordIos(withOffer);
|
|
132
|
-
const
|
|
133
|
-
const purchase = iosTransactionToPurchaseMap(result);
|
|
123
|
+
const purchase = await ExpoIapModule.buyProduct(sku, appAccountToken, quantity ?? -1, offer);
|
|
134
124
|
return Promise.resolve(purchase);
|
|
135
125
|
},
|
|
136
126
|
android: async () => {
|
|
@@ -155,16 +145,12 @@ export const requestSubscription = (request) => (Platform.select({
|
|
|
155
145
|
if (!('sku' in request)) {
|
|
156
146
|
throw new Error('sku is required for iOS subscriptions');
|
|
157
147
|
}
|
|
158
|
-
const { sku,
|
|
159
|
-
if (andDangerouslyFinishTransactionAutomaticallyIOS) {
|
|
160
|
-
console.warn('You are dangerously allowing expo-iap to finish your transaction automatically. You should set andDangerouslyFinishTransactionAutomatically to false when calling requestPurchase and call finishTransaction manually when you have delivered the purchased goods to the user. It defaults to true to provide backwards compatibility. Will default to false in version 4.0.0.');
|
|
161
|
-
}
|
|
148
|
+
const { sku, appAccountToken, quantity, withOffer } = request;
|
|
162
149
|
const offer = offerToRecordIos(withOffer);
|
|
163
|
-
const purchase =
|
|
150
|
+
const purchase = await ExpoIapModule.buyProduct(sku, appAccountToken, quantity ?? -1, offer);
|
|
164
151
|
return Promise.resolve(purchase);
|
|
165
152
|
},
|
|
166
153
|
android: async () => {
|
|
167
|
-
console.log('requestSubscription', request);
|
|
168
154
|
const { skus, isOfferPersonalized, obfuscatedAccountIdAndroid, obfuscatedProfileIdAndroid, subscriptionOffers, replacementModeAndroid, purchaseTokenAndroid, } = request;
|
|
169
155
|
return ExpoIapModule.buyItemByType({
|
|
170
156
|
type: ProductType.Subscription,
|
|
@@ -199,4 +185,5 @@ export const finishTransaction = ({ purchase, isConsumable, developerPayloadAndr
|
|
|
199
185
|
},
|
|
200
186
|
}) || (() => Promise.reject(new Error('Unsupported Platform'))))();
|
|
201
187
|
};
|
|
188
|
+
export * from './useIap';
|
|
202
189
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,wCAAwC;AACxC,OAAO,EAAC,kBAAkB,EAAE,YAAY,EAAC,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAC,QAAQ,EAAC,MAAM,cAAc,CAAC;AAEtC,OAAO,EAGL,WAAW,GAOZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAa5C,OAAO,EAAC,YAAY,EAAC,MAAM,eAAe,CAAC;AAE3C,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAE9B,iCAAiC;AACjC,MAAM,CAAC,MAAM,EAAE,GAAG,aAAa,CAAC,EAAE,CAAC;AAEnC,MAAM,CAAN,IAAY,QAIX;AAJD,WAAY,QAAQ;I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AAO,OAAO,CAAC,MAAM,CACnB,IAAI,KAAK,CAAC,0CAA0C,CAAC,CACtD,CAAC;gBACJ,CAAC;gBAED,OAAO,aAAa,CAAC,cAAc,CACjC,QAAQ,CAAC,aAAa,EACtB,uBAAuB,CACxB,CAAC;YACJ,CAAC;YACD,OAAO,OAAO,CAAC,MAAM,CACnB,IAAI,KAAK,CAAC,0CAA0C,CAAC,CACtD,CAAC;QACJ,CAAC;KACF,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAChE,EAAE,CAAC;AACN,CAAC,CAAC","sourcesContent":["// Import the native module. On web, it will be resolved to ExpoIap.web.ts\n// and on native platforms to ExpoIap.ts\nimport {NativeModulesProxy, EventEmitter} from 'expo-modules-core';\nimport {Platform} from 'react-native';\n\nimport {\n Product,\n ProductPurchase,\n ProductType,\n Purchase,\n PurchaseError,\n PurchaseResult,\n RequestSubscriptionProps,\n SubscriptionProduct,\n SubscriptionPurchase,\n} from './ExpoIap.types';\nimport ExpoIapModule from './ExpoIapModule';\nimport {\n RequestPurchaseAndroidProps,\n RequestSubscriptionAndroidProps,\n} from './types/ExpoIapAndroid.types';\nimport {\n PaymentDiscount,\n ProductIos,\n RequestPurchaseIosProps,\n RequestSubscriptionIosProps,\n SubscriptionProductIos,\n TransactionSk2,\n} from './types/ExpoIapIos.types';\nimport {isProductIos} from './modules/ios';\n\nexport * from './modules/android';\nexport * from './modules/ios';\n\n// Get the native constant value.\nexport const PI = ExpoIapModule.PI;\n\nexport enum IapEvent {\n PurchaseUpdated = 'purchase-updated',\n PurchaseError = 'purchase-error',\n TransactionIapUpdated = 'iap-transaction-updated',\n}\n\nexport async function setValueAsync(value: string) {\n return await ExpoIapModule.setValueAsync(value);\n}\n\nexport const emitter = new EventEmitter(\n ExpoIapModule ?? NativeModulesProxy.ExpoIap,\n);\n\nexport const purchaseUpdatedListener = (\n listener: (event: Purchase) => void,\n) => {\n const emitterSubscription = emitter.addListener(\n IapEvent.PurchaseUpdated,\n listener,\n );\n return emitterSubscription;\n};\n\nexport const purchaseErrorListener = (\n listener: (error: PurchaseError) => void,\n) => {\n return emitter.addListener<PurchaseError>(IapEvent.PurchaseError, listener);\n};\n\nexport function initConnection() {\n return ExpoIapModule.initConnection();\n}\n\nexport const getProducts = async (skus: string[]): Promise<Product[]> => {\n if (!skus?.length) {\n return Promise.reject(new Error('\"skus\" is required'));\n }\n\n return Platform.select({\n ios: async () => {\n const items = (await ExpoIapModule.getItems(skus)) as ProductIos[];\n return items.filter((item: ProductIos) => isProductIos(item));\n },\n android: async () => {\n const products = await ExpoIapModule.getItemsByType(\n ProductType.InAppPurchase,\n skus,\n );\n\n return products;\n },\n default: () => Promise.reject(new Error('Unsupported Platform')),\n })();\n};\n\nexport const getSubscriptions = async (\n skus: string[],\n): Promise<SubscriptionProduct[]> => {\n if (!skus?.length) {\n return Promise.reject(new Error('\"skus\" is required'));\n }\n\n return Platform.select({\n ios: async (): Promise<SubscriptionProductIos[]> => {\n const items: SubscriptionProductIos[] = (\n (await ExpoIapModule.getItems(skus)) as SubscriptionProductIos[]\n ).filter((item: SubscriptionProductIos) => skus.includes(item.id));\n\n return items;\n },\n android: async () => {\n return ExpoIapModule.getItemsByType('subs', skus);\n },\n default: () => Promise.reject(new Error('Unsupported Platform')),\n })();\n};\n\nexport async function endConnection(): Promise<boolean> {\n return ExpoIapModule.endConnection();\n}\n\nexport const getPurchaseHistory = ({\n alsoPublishToEventListener = false,\n automaticallyFinishRestoredTransactions = true,\n onlyIncludeActiveItems = false,\n}: {\n alsoPublishToEventListener?: boolean;\n automaticallyFinishRestoredTransactions?: boolean;\n onlyIncludeActiveItems?: boolean;\n} = {}): Promise<ProductPurchase[]> =>\n (\n Platform.select({\n ios: async () => {\n return ExpoIapModule.getAvailableItems(\n alsoPublishToEventListener,\n onlyIncludeActiveItems,\n );\n },\n android: async () => {\n const products = await ExpoIapModule.getPurchaseHistoryByType(\n ProductType.InAppPurchase,\n );\n\n const subscriptions = await ExpoIapModule.getPurchaseHistoryByType(\n ProductType.Subscription,\n );\n\n return products.concat(subscriptions);\n },\n }) || (() => Promise.resolve([]))\n )();\n\nexport const getAvailablePurchases = ({\n alsoPublishToEventListener = false,\n automaticallyFinishRestoredTransactions = false,\n onlyIncludeActiveItems = true,\n}: {\n alsoPublishToEventListener?: boolean;\n automaticallyFinishRestoredTransactions?: boolean;\n onlyIncludeActiveItems?: boolean;\n} = {}): Promise<ProductPurchase[]> =>\n (\n Platform.select({\n ios: () =>\n ExpoIapModule.getAvailableItems(\n alsoPublishToEventListener,\n onlyIncludeActiveItems,\n ),\n android: async () => {\n const products = await ExpoIapModule.getAvailableItemsByType(\n ProductType.InAppPurchase,\n );\n\n const subscriptions = await ExpoIapModule.getAvailableItemsByType(\n ProductType.Subscription,\n );\n\n return products.concat(subscriptions);\n },\n }) || (() => Promise.resolve([]))\n )();\n\nconst offerToRecordIos = (\n offer: PaymentDiscount | undefined,\n): Record<keyof PaymentDiscount, string> | undefined => {\n if (!offer) {\n return undefined;\n }\n return {\n identifier: offer.identifier,\n keyIdentifier: offer.keyIdentifier,\n nonce: offer.nonce,\n signature: offer.signature,\n timestamp: offer.timestamp.toString(),\n };\n};\n\nconst iosTransactionToPurchaseMap = ({\n id,\n originalPurchaseDate,\n productID,\n purchaseDate,\n purchasedQuantity,\n originalID,\n verificationResult,\n appAccountToken,\n jsonRepresentation,\n}: TransactionSk2): Purchase => {\n let transactionReasonIOS;\n\n try {\n if (jsonRepresentation) {\n const transactionData = JSON.parse(jsonRepresentation);\n transactionReasonIOS = transactionData.transactionReason;\n }\n } catch (e) {\n console.log('SK2 Error parsing jsonRepresentation', e);\n }\n const purchase: Purchase = {\n productId: productID,\n transactionId: String(id),\n transactionDate: purchaseDate, //??\n transactionReceipt: '', // Not available\n purchaseToken: '', //Not available\n quantityIOS: purchasedQuantity,\n originalTransactionDateIOS: originalPurchaseDate,\n originalTransactionIdentifierIOS: originalID,\n verificationResultIOS: verificationResult ?? '',\n appAccountToken: appAccountToken ?? '',\n transactionReasonIOS: transactionReasonIOS ?? '',\n };\n return purchase;\n};\n\nexport const requestPurchase = (\n request: RequestPurchaseIosProps | RequestPurchaseAndroidProps,\n): Promise<ProductPurchase | ProductPurchase[] | void> =>\n (\n Platform.select({\n ios: async () => {\n if (!('sku' in request)) {\n throw new Error('sku is required for iOS purchase');\n }\n\n const {\n sku,\n andDangerouslyFinishTransactionAutomaticallyIOS = false,\n appAccountToken,\n quantity,\n withOffer,\n } = request;\n\n if (andDangerouslyFinishTransactionAutomaticallyIOS) {\n console.warn(\n 'You are dangerously allowing expo-iap to finish your transaction automatically. You should set andDangerouslyFinishTransactionAutomatically to false when calling requestPurchase and call finishTransaction manually when you have delivered the purchased goods to the user. It defaults to true to provide backwards compatibility. Will default to false in version 4.0.0.',\n );\n }\n\n const offer = offerToRecordIos(withOffer);\n\n const result = await ExpoIapModule.buyProduct(\n sku,\n andDangerouslyFinishTransactionAutomaticallyIOS,\n appAccountToken,\n quantity ?? -1,\n offer,\n );\n\n const purchase = iosTransactionToPurchaseMap(result);\n return Promise.resolve(purchase);\n },\n android: async () => {\n if (!('skus' in request) || !request.skus.length) {\n throw new Error('skus is required for Android purchase');\n }\n\n const {\n skus,\n obfuscatedAccountIdAndroid,\n obfuscatedProfileIdAndroid,\n isOfferPersonalized,\n } = request;\n\n return ExpoIapModule.buyItemByType({\n type: ProductType.InAppPurchase,\n skuArr: skus,\n purchaseToken: undefined,\n replacementMode: -1,\n obfuscatedAccountId: obfuscatedAccountIdAndroid,\n obfuscatedProfileId: obfuscatedProfileIdAndroid,\n offerTokenArr: [],\n isOfferPersonalized: isOfferPersonalized ?? false,\n });\n },\n }) || Promise.resolve\n )();\n\nexport const requestSubscription = (\n request: RequestSubscriptionProps,\n): Promise<SubscriptionPurchase | SubscriptionPurchase[] | null | void> =>\n (\n Platform.select({\n ios: async () => {\n if (!('sku' in request)) {\n throw new Error('sku is required for iOS subscriptions');\n }\n\n const {\n sku,\n andDangerouslyFinishTransactionAutomaticallyIOS = false,\n appAccountToken,\n quantity,\n withOffer,\n } = request as RequestSubscriptionIosProps;\n\n if (andDangerouslyFinishTransactionAutomaticallyIOS) {\n console.warn(\n 'You are dangerously allowing expo-iap to finish your transaction automatically. You should set andDangerouslyFinishTransactionAutomatically to false when calling requestPurchase and call finishTransaction manually when you have delivered the purchased goods to the user. It defaults to true to provide backwards compatibility. Will default to false in version 4.0.0.',\n );\n }\n\n const offer = offerToRecordIos(withOffer);\n\n const purchase = iosTransactionToPurchaseMap(\n await ExpoIapModule.buyProduct(\n sku,\n andDangerouslyFinishTransactionAutomaticallyIOS,\n appAccountToken,\n quantity ?? -1,\n offer,\n ),\n );\n return Promise.resolve(purchase);\n },\n android: async () => {\n console.log('requestSubscription', request);\n const {\n skus,\n isOfferPersonalized,\n obfuscatedAccountIdAndroid,\n obfuscatedProfileIdAndroid,\n subscriptionOffers,\n replacementModeAndroid,\n purchaseTokenAndroid,\n } = request as RequestSubscriptionAndroidProps;\n\n return ExpoIapModule.buyItemByType({\n type: ProductType.Subscription,\n skuArr: skus.map((so) => so),\n purchaseToken: purchaseTokenAndroid,\n replacementMode: replacementModeAndroid,\n obfuscatedAccountId: obfuscatedAccountIdAndroid,\n obfuscatedProfileId: obfuscatedProfileIdAndroid,\n offerTokenArr: subscriptionOffers.map((so) => so.offerToken),\n isOfferPersonalized: isOfferPersonalized ?? false,\n });\n },\n }) || (() => Promise.resolve(null))\n )();\n\nexport const finishTransaction = ({\n purchase,\n isConsumable,\n developerPayloadAndroid,\n}: {\n purchase: Purchase;\n isConsumable?: boolean;\n developerPayloadAndroid?: string;\n}): Promise<PurchaseResult | boolean> => {\n return (\n Platform.select({\n ios: async () => {\n const transactionId = purchase.transactionId;\n\n if (!transactionId) {\n return Promise.reject(\n new Error('transactionId required to finish iOS transaction'),\n );\n }\n await ExpoIapModule.finishTransaction(transactionId);\n return Promise.resolve(true);\n },\n android: async () => {\n if (purchase?.purchaseToken) {\n if (!isConsumable) {\n return Promise.reject(\n new Error('purchase is not suitable to be purchased'),\n );\n }\n\n return ExpoIapModule.consumeProduct(\n purchase.purchaseToken,\n developerPayloadAndroid,\n );\n }\n return Promise.reject(\n new Error('purchase is not suitable to be purchased'),\n );\n },\n }) || (() => Promise.reject(new Error('Unsupported Platform')))\n )();\n};\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,wCAAwC;AACxC,OAAO,EAAC,kBAAkB,EAAE,YAAY,EAAC,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAC,QAAQ,EAAC,MAAM,cAAc,CAAC;AACtC,OAAO,EAGL,WAAW,GAOZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAU5C,OAAO,EAAC,YAAY,EAAE,wBAAwB,EAAC,MAAM,eAAe,CAAC;AACrE,OAAO,EACL,gBAAgB,EAChB,4BAA4B,GAC7B,MAAM,mBAAmB,CAAC;AAE3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAE9B,iCAAiC;AACjC,MAAM,CAAC,MAAM,EAAE,GAAG,aAAa,CAAC,EAAE,CAAC;AAEnC,MAAM,CAAN,IAAY,QAIX;AAJD,WAAY,QAAQ;IAClB,gDAAoC,CAAA;IACpC,4CAAgC,CAAA;IAChC,6DAAiD,CAAA;AACnD,CAAC,EAJW,QAAQ,KAAR,QAAQ,QAInB;AAED,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,KAAa;IAC/C,OAAO,MAAM,aAAa,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,YAAY,CACrC,aAAa,IAAI,kBAAkB,CAAC,OAAO,CAC5C,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,Q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CAAC;YACJ,CAAC;YACD,MAAM,aAAa,CAAC,iBAAiB,CAAC,aAAa,CAAC,CAAC;YACrD,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC/B,CAAC;QACD,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,IAAI,QAAQ,EAAE,aAAa,EAAE,CAAC;gBAC5B,IAAI,CAAC,YAAY,EAAE,CAAC;oBAClB,OAAO,OAAO,CAAC,MAAM,CACnB,IAAI,KAAK,CAAC,0CAA0C,CAAC,CACtD,CAAC;gBACJ,CAAC;gBAED,OAAO,aAAa,CAAC,cAAc,CACjC,QAAQ,CAAC,aAAa,EACtB,uBAAuB,CACxB,CAAC;YACJ,CAAC;YACD,OAAO,OAAO,CAAC,MAAM,CACnB,IAAI,KAAK,CAAC,0CAA0C,CAAC,CACtD,CAAC;QACJ,CAAC;KACF,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAChE,EAAE,CAAC;AACN,CAAC,CAAC;AAEF,cAAc,UAAU,CAAC","sourcesContent":["// Import the native module. On web, it will be resolved to ExpoIap.web.ts\n// and on native platforms to ExpoIap.ts\nimport {NativeModulesProxy, EventEmitter} from 'expo-modules-core';\nimport {Platform} from 'react-native';\nimport {\n Product,\n ProductPurchase,\n ProductType,\n Purchase,\n PurchaseError,\n PurchaseResult,\n RequestSubscriptionProps,\n SubscriptionProduct,\n SubscriptionPurchase,\n} from './ExpoIap.types';\nimport ExpoIapModule from './ExpoIapModule';\nimport {\n RequestPurchaseAndroidProps,\n RequestSubscriptionAndroidProps,\n} from './types/ExpoIapAndroid.types';\nimport {\n PaymentDiscount,\n RequestPurchaseIosProps,\n RequestSubscriptionIosProps,\n} from './types/ExpoIapIos.types';\nimport {isProductIos, isSubscriptionProductIos} from './modules/ios';\nimport {\n isProductAndroid,\n isSubscriptionProductAndroid,\n} from './modules/android';\n\nexport * from './modules/android';\nexport * from './modules/ios';\n\n// Get the native constant value.\nexport const PI = ExpoIapModule.PI;\n\nexport enum IapEvent {\n PurchaseUpdated = 'purchase-updated',\n PurchaseError = 'purchase-error',\n TransactionIapUpdated = 'iap-transaction-updated',\n}\n\nexport async function setValueAsync(value: string) {\n return await ExpoIapModule.setValueAsync(value);\n}\n\nexport const emitter = new EventEmitter(\n ExpoIapModule ?? NativeModulesProxy.ExpoIap,\n);\n\nexport const purchaseUpdatedListener = (\n listener: (event: Purchase) => void,\n) => {\n const emitterSubscription = emitter.addListener(\n IapEvent.PurchaseUpdated,\n listener,\n );\n return emitterSubscription;\n};\n\nexport const purchaseErrorListener = (\n listener: (error: PurchaseError) => void,\n) => {\n return emitter.addListener<PurchaseError>(IapEvent.PurchaseError, listener);\n};\n\nexport function initConnection() {\n return ExpoIapModule.initConnection();\n}\n\nexport const getProducts = async (skus: string[]): Promise<Product[]> => {\n console.log('getProducts', skus);\n if (!skus?.length) {\n return Promise.reject(new Error('\"skus\" is required'));\n }\n\n return Platform.select({\n ios: async () => {\n const items = await ExpoIapModule.getItems(skus);\n console.log('items', items);\n return items.filter((item: unknown) => isProductIos<Product>(item));\n },\n android: async () => {\n const products = await ExpoIapModule.getItemsByType(\n ProductType.InAppPurchase,\n skus,\n );\n return products.filter((product: unknown) =>\n isProductAndroid<Product>(product),\n );\n },\n default: () => Promise.reject(new Error('Unsupported Platform')),\n })();\n};\n\nexport const getSubscriptions = async (\n skus: string[],\n): Promise<SubscriptionProduct[]> => {\n if (!skus?.length) {\n return Promise.reject(new Error('\"skus\" is required'));\n }\n\n return Platform.select({\n ios: async () => {\n const rawItems = await ExpoIapModule.getItems(skus);\n\n return rawItems.filter((item: unknown) => {\n if (!isSubscriptionProductIos(item)) return false;\n return (\n typeof item === 'object' &&\n item !== null &&\n 'id' in item &&\n typeof item.id === 'string' &&\n skus.includes(item.id)\n );\n }) as SubscriptionProduct[];\n },\n android: async () => {\n const rawItems = await ExpoIapModule.getItemsByType('subs', skus);\n\n return rawItems.filter((item: unknown) => {\n if (!isSubscriptionProductAndroid(item)) return false;\n return (\n typeof item === 'object' &&\n item !== null &&\n 'id' in item &&\n typeof item.id === 'string' &&\n skus.includes(item.id)\n );\n }) as SubscriptionProduct[];\n },\n default: () => Promise.reject(new Error('Unsupported Platform')),\n })();\n};\n\nexport async function endConnection(): Promise<boolean> {\n return ExpoIapModule.endConnection();\n}\n\nexport const getPurchaseHistory = ({\n alsoPublishToEventListener = false,\n onlyIncludeActiveItems = false,\n}: {\n alsoPublishToEventListener?: boolean;\n onlyIncludeActiveItems?: boolean;\n} = {}): Promise<ProductPurchase[]> =>\n (\n Platform.select({\n ios: async () => {\n return ExpoIapModule.getAvailableItems(\n alsoPublishToEventListener,\n onlyIncludeActiveItems,\n );\n },\n android: async () => {\n const products = await ExpoIapModule.getPurchaseHistoryByType(\n ProductType.InAppPurchase,\n );\n\n const subscriptions = await ExpoIapModule.getPurchaseHistoryByType(\n ProductType.Subscription,\n );\n\n return products.concat(subscriptions);\n },\n }) || (() => Promise.resolve([]))\n )();\n\nexport const getAvailablePurchases = ({\n alsoPublishToEventListener = false,\n onlyIncludeActiveItems = true,\n}: {\n alsoPublishToEventListener?: boolean;\n onlyIncludeActiveItems?: boolean;\n} = {}): Promise<ProductPurchase[]> =>\n (\n Platform.select({\n ios: () =>\n ExpoIapModule.getAvailableItems(\n alsoPublishToEventListener,\n onlyIncludeActiveItems,\n ),\n android: async () => {\n const products = await ExpoIapModule.getAvailableItemsByType(\n ProductType.InAppPurchase,\n );\n\n const subscriptions = await ExpoIapModule.getAvailableItemsByType(\n ProductType.Subscription,\n );\n\n return products.concat(subscriptions);\n },\n }) || (() => Promise.resolve([]))\n )();\n\nconst offerToRecordIos = (\n offer: PaymentDiscount | undefined,\n): Record<keyof PaymentDiscount, string> | undefined => {\n if (!offer) {\n return undefined;\n }\n return {\n identifier: offer.identifier,\n keyIdentifier: offer.keyIdentifier,\n nonce: offer.nonce,\n signature: offer.signature,\n timestamp: offer.timestamp.toString(),\n };\n};\n\nexport const requestPurchase = (\n request: RequestPurchaseIosProps | RequestPurchaseAndroidProps,\n): Promise<ProductPurchase | ProductPurchase[] | void> =>\n (\n Platform.select({\n ios: async () => {\n if (!('sku' in request)) {\n throw new Error('sku is required for iOS purchase');\n }\n\n const {sku, appAccountToken, quantity, withOffer} = request;\n\n const offer = offerToRecordIos(withOffer);\n\n const purchase = await ExpoIapModule.buyProduct(\n sku,\n appAccountToken,\n quantity ?? -1,\n offer,\n );\n\n return Promise.resolve(purchase);\n },\n android: async () => {\n if (!('skus' in request) || !request.skus.length) {\n throw new Error('skus is required for Android purchase');\n }\n\n const {\n skus,\n obfuscatedAccountIdAndroid,\n obfuscatedProfileIdAndroid,\n isOfferPersonalized,\n } = request;\n\n return ExpoIapModule.buyItemByType({\n type: ProductType.InAppPurchase,\n skuArr: skus,\n purchaseToken: undefined,\n replacementMode: -1,\n obfuscatedAccountId: obfuscatedAccountIdAndroid,\n obfuscatedProfileId: obfuscatedProfileIdAndroid,\n offerTokenArr: [],\n isOfferPersonalized: isOfferPersonalized ?? false,\n });\n },\n }) || Promise.resolve\n )();\n\nexport const requestSubscription = (\n request: RequestSubscriptionProps,\n): Promise<SubscriptionPurchase | SubscriptionPurchase[] | null | void> =>\n (\n Platform.select({\n ios: async () => {\n if (!('sku' in request)) {\n throw new Error('sku is required for iOS subscriptions');\n }\n\n const {sku, appAccountToken, quantity, withOffer} =\n request as RequestSubscriptionIosProps;\n\n const offer = offerToRecordIos(withOffer);\n\n const purchase = await ExpoIapModule.buyProduct(\n sku,\n appAccountToken,\n quantity ?? -1,\n offer,\n );\n\n return Promise.resolve(purchase as SubscriptionPurchase);\n },\n android: async () => {\n const {\n skus,\n isOfferPersonalized,\n obfuscatedAccountIdAndroid,\n obfuscatedProfileIdAndroid,\n subscriptionOffers,\n replacementModeAndroid,\n purchaseTokenAndroid,\n } = request as RequestSubscriptionAndroidProps;\n\n return ExpoIapModule.buyItemByType({\n type: ProductType.Subscription,\n skuArr: skus.map((so) => so),\n purchaseToken: purchaseTokenAndroid,\n replacementMode: replacementModeAndroid,\n obfuscatedAccountId: obfuscatedAccountIdAndroid,\n obfuscatedProfileId: obfuscatedProfileIdAndroid,\n offerTokenArr: subscriptionOffers.map((so) => so.offerToken),\n isOfferPersonalized: isOfferPersonalized ?? false,\n });\n },\n }) || (() => Promise.resolve(null))\n )();\n\nexport const finishTransaction = ({\n purchase,\n isConsumable,\n developerPayloadAndroid,\n}: {\n purchase: Purchase;\n isConsumable?: boolean;\n developerPayloadAndroid?: string;\n}): Promise<PurchaseResult | boolean> => {\n return (\n Platform.select({\n ios: async () => {\n const transactionId = purchase.transactionId;\n\n if (!transactionId) {\n return Promise.reject(\n new Error('transactionId required to finish iOS transaction'),\n );\n }\n await ExpoIapModule.finishTransaction(transactionId);\n return Promise.resolve(true);\n },\n android: async () => {\n if (purchase?.purchaseToken) {\n if (!isConsumable) {\n return Promise.reject(\n new Error('purchase is not suitable to be purchased'),\n );\n }\n\n return ExpoIapModule.consumeProduct(\n purchase.purchaseToken,\n developerPayloadAndroid,\n );\n }\n return Promise.reject(\n new Error('purchase is not suitable to be purchased'),\n );\n },\n }) || (() => Promise.reject(new Error('Unsupported Platform')))\n )();\n};\n\nexport * from './useIap';\n"]}
|
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export declare function isProductAndroid
|
|
4
|
-
|
|
1
|
+
import { PurchaseResult } from '../ExpoIap.types';
|
|
2
|
+
import { ReceiptAndroid } from '../types/ExpoIapAndroid.types';
|
|
3
|
+
export declare function isProductAndroid<T extends {
|
|
4
|
+
platform?: string;
|
|
5
|
+
}>(item: unknown): item is T & {
|
|
6
|
+
platform: 'android';
|
|
7
|
+
};
|
|
8
|
+
export declare function isSubscriptionProductAndroid<T extends {
|
|
9
|
+
platform?: string;
|
|
10
|
+
}>(item: unknown): item is T & {
|
|
11
|
+
platform: 'android';
|
|
12
|
+
};
|
|
5
13
|
/**
|
|
6
14
|
* Deep link to subscriptions screen on Android.
|
|
7
15
|
* @param {string} sku The product's SKU (on Android)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"android.d.ts","sourceRoot":"","sources":["../../src/modules/android.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"android.d.ts","sourceRoot":"","sources":["../../src/modules/android.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAC,cAAc,EAAC,MAAM,+BAA+B,CAAC;AAI7D,wBAAgB,gBAAgB,CAAC,CAAC,SAAS;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAC,EAC5D,IAAI,EAAE,OAAO,GACZ,IAAI,IAAI,CAAC,GAAG;IAAC,QAAQ,EAAE,SAAS,CAAA;CAAC,CAOnC;AAED,wBAAgB,4BAA4B,CAAC,CAAC,SAAS;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAC,EACxE,IAAI,EAAE,OAAO,GACZ,IAAI,IAAI,CAAC,GAAG;IAAC,QAAQ,EAAE,SAAS,CAAA;CAAC,CAEnC;AAED;;;;GAIG;AACH,eAAO,MAAM,8BAA8B,aAExC;IACD,GAAG,EAAE,MAAM,CAAC;CACb,KAAG,QAAQ,IAAI,CAIf,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,sBAAsB,kEAMhC;IACD,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,KAAG,QAAQ,cAAc,CAsBzB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,iCAGpC;IACD,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,KAAG,QAAQ,cAAc,GAAG,OAAO,GAAG,IAAI,CAE1C,CAAC"}
|
package/build/modules/android.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { Linking } from 'react-native';
|
|
2
2
|
import ExpoIapModule from '../ExpoIapModule';
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
// Type guards
|
|
4
|
+
export function isProductAndroid(item) {
|
|
5
|
+
return (item != null &&
|
|
6
|
+
typeof item === 'object' &&
|
|
7
|
+
'platform' in item &&
|
|
8
|
+
item.platform === 'android');
|
|
5
9
|
}
|
|
6
|
-
export function isSubscriptionProductAndroid(
|
|
7
|
-
return
|
|
10
|
+
export function isSubscriptionProductAndroid(item) {
|
|
11
|
+
return isProductAndroid(item);
|
|
8
12
|
}
|
|
9
13
|
/**
|
|
10
14
|
* Deep link to subscriptions screen on Android.
|