expo-iap 2.8.0 → 2.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +57 -1
- package/CLAUDE.md +44 -7
- package/android/src/main/java/expo/modules/iap/ExpoIapModule.kt +52 -35
- package/build/ExpoIap.types.d.ts +26 -23
- package/build/ExpoIap.types.d.ts.map +1 -1
- package/build/ExpoIap.types.js +0 -1
- package/build/ExpoIap.types.js.map +1 -1
- package/build/index.d.ts +6 -6
- package/build/index.d.ts.map +1 -1
- package/build/index.js +3 -5
- package/build/index.js.map +1 -1
- package/build/modules/ios.d.ts +8 -8
- package/build/modules/ios.d.ts.map +1 -1
- package/build/modules/ios.js +3 -3
- package/build/modules/ios.js.map +1 -1
- package/build/types/ExpoIapAndroid.types.d.ts +50 -15
- package/build/types/ExpoIapAndroid.types.d.ts.map +1 -1
- package/build/types/ExpoIapAndroid.types.js +11 -6
- package/build/types/ExpoIapAndroid.types.js.map +1 -1
- package/build/types/ExpoIapIOS.types.d.ts +43 -22
- package/build/types/ExpoIapIOS.types.d.ts.map +1 -1
- package/build/types/ExpoIapIOS.types.js.map +1 -1
- package/build/useIAP.d.ts +6 -6
- package/build/useIAP.d.ts.map +1 -1
- package/build/useIAP.js.map +1 -1
- package/bun.lock +122 -456
- package/ios/ExpoIapModule.swift +87 -5
- package/package.json +1 -1
- package/src/ExpoIap.types.ts +45 -45
- package/src/index.ts +14 -24
- package/src/modules/ios.ts +13 -20
- package/src/types/ExpoIapAndroid.types.ts +62 -15
- package/src/types/ExpoIapIOS.types.ts +49 -25
- package/src/useIAP.ts +11 -19
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {PurchaseCommon, ProductCommon} from '../ExpoIap.types';
|
|
2
2
|
|
|
3
3
|
type SubscriptionIosPeriod = 'DAY' | 'WEEK' | 'MONTH' | 'YEAR' | '';
|
|
4
4
|
type PaymentMode = '' | 'FREETRIAL' | 'PAYASYOUGO' | 'PAYUPFRONT';
|
|
@@ -26,10 +26,27 @@ type SubscriptionInfo = {
|
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
-
export type ProductIOS =
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
export type ProductIOS = ProductCommon & {
|
|
30
|
+
displayNameIOS: string;
|
|
31
|
+
isFamilyShareableIOS: boolean;
|
|
32
|
+
jsonRepresentationIOS: string;
|
|
33
|
+
platform: 'ios';
|
|
34
|
+
subscriptionInfoIOS?: SubscriptionInfo;
|
|
35
|
+
/**
|
|
36
|
+
* @deprecated Use `displayNameIOS` instead. This field will be removed in v2.9.0.
|
|
37
|
+
*/
|
|
38
|
+
displayName?: string;
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated Use `isFamilyShareableIOS` instead. This field will be removed in v2.9.0.
|
|
41
|
+
*/
|
|
42
|
+
isFamilyShareable?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* @deprecated Use `jsonRepresentationIOS` instead. This field will be removed in v2.9.0.
|
|
45
|
+
*/
|
|
46
|
+
jsonRepresentation?: string;
|
|
47
|
+
/**
|
|
48
|
+
* @deprecated Use `subscriptionInfoIOS` instead. This field will be removed in v2.9.0.
|
|
49
|
+
*/
|
|
33
50
|
subscription?: SubscriptionInfo;
|
|
34
51
|
introductoryPriceNumberOfPeriodsIOS?: string;
|
|
35
52
|
introductoryPriceSubscriptionPeriodIOS?: SubscriptionIosPeriod;
|
|
@@ -45,17 +62,29 @@ export type Discount = {
|
|
|
45
62
|
subscriptionPeriod: string;
|
|
46
63
|
};
|
|
47
64
|
|
|
48
|
-
export type
|
|
49
|
-
|
|
50
|
-
|
|
65
|
+
export type ProductSubscriptionIOS = ProductIOS & {
|
|
66
|
+
discountsIOS?: Discount[];
|
|
67
|
+
introductoryPriceIOS?: string;
|
|
51
68
|
introductoryPriceAsAmountIOS?: string;
|
|
52
69
|
introductoryPricePaymentModeIOS?: PaymentMode;
|
|
53
70
|
introductoryPriceNumberOfPeriodsIOS?: string;
|
|
54
71
|
introductoryPriceSubscriptionPeriodIOS?: SubscriptionIosPeriod;
|
|
72
|
+
platform: 'ios';
|
|
55
73
|
subscriptionPeriodNumberIOS?: string;
|
|
56
74
|
subscriptionPeriodUnitIOS?: SubscriptionIosPeriod;
|
|
75
|
+
/**
|
|
76
|
+
* @deprecated Use `discountsIOS` instead. This field will be removed in v2.9.0.
|
|
77
|
+
*/
|
|
78
|
+
discounts?: Discount[];
|
|
79
|
+
/**
|
|
80
|
+
* @deprecated Use `introductoryPriceIOS` instead. This field will be removed in v2.9.0.
|
|
81
|
+
*/
|
|
82
|
+
introductoryPrice?: string;
|
|
57
83
|
};
|
|
58
84
|
|
|
85
|
+
// Legacy naming for backward compatibility
|
|
86
|
+
export type SubscriptionProductIOS = ProductSubscriptionIOS;
|
|
87
|
+
|
|
59
88
|
export type PaymentDiscount = {
|
|
60
89
|
/**
|
|
61
90
|
* A string used to uniquely identify a discount offer for a product.
|
|
@@ -79,9 +108,9 @@ export type PaymentDiscount = {
|
|
|
79
108
|
timestamp: number;
|
|
80
109
|
};
|
|
81
110
|
|
|
82
|
-
export type
|
|
111
|
+
export type RequestPurchaseIosProps = {
|
|
83
112
|
sku: string;
|
|
84
|
-
|
|
113
|
+
andDangerouslyFinishTransactionAutomatically?: boolean;
|
|
85
114
|
/**
|
|
86
115
|
* UUID representing user account
|
|
87
116
|
*/
|
|
@@ -90,18 +119,6 @@ export type RequestPurchaseIOSProps = {
|
|
|
90
119
|
withOffer?: PaymentDiscount;
|
|
91
120
|
};
|
|
92
121
|
|
|
93
|
-
export type RequestSubscriptionIOSProps = RequestPurchaseIOSProps;
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* @deprecated Use RequestPurchaseIOSProps instead. This alias will be removed in v3.0.0.
|
|
97
|
-
*/
|
|
98
|
-
export type RequestPurchaseIosProps = RequestPurchaseIOSProps;
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* @deprecated Use RequestSubscriptionIOSProps instead. This alias will be removed in v3.0.0.
|
|
102
|
-
*/
|
|
103
|
-
export type RequestSubscriptionIosProps = RequestSubscriptionIOSProps;
|
|
104
|
-
|
|
105
122
|
type SubscriptionStatus =
|
|
106
123
|
| 'expired'
|
|
107
124
|
| 'inBillingRetryPeriod'
|
|
@@ -120,8 +137,10 @@ export type ProductStatusIOS = {
|
|
|
120
137
|
renewalInfo?: RenewalInfo;
|
|
121
138
|
};
|
|
122
139
|
|
|
123
|
-
|
|
140
|
+
// Legacy naming for backward compatibility
|
|
141
|
+
export type ProductPurchaseIOS = PurchaseCommon & {
|
|
124
142
|
// iOS basic fields
|
|
143
|
+
platform: 'ios';
|
|
125
144
|
quantityIOS?: number;
|
|
126
145
|
originalTransactionDateIOS?: number;
|
|
127
146
|
originalTransactionIdentifierIOS?: string;
|
|
@@ -146,8 +165,10 @@ export type ProductPurchaseIOS = PurchaseBase & {
|
|
|
146
165
|
type: string;
|
|
147
166
|
paymentMode: string;
|
|
148
167
|
};
|
|
149
|
-
|
|
150
|
-
|
|
168
|
+
// Price locale fields
|
|
169
|
+
currencyCodeIOS?: string;
|
|
170
|
+
currencySymbolIOS?: string;
|
|
171
|
+
countryCodeIOS?: string;
|
|
151
172
|
/**
|
|
152
173
|
* @deprecated Use `purchaseToken` instead. This field will be removed in a future version.
|
|
153
174
|
* iOS 15+ JWS representation is now available through the `purchaseToken` field.
|
|
@@ -155,6 +176,9 @@ export type ProductPurchaseIOS = PurchaseBase & {
|
|
|
155
176
|
jwsRepresentationIOS?: string;
|
|
156
177
|
};
|
|
157
178
|
|
|
179
|
+
// Preferred naming
|
|
180
|
+
export type PurchaseIOS = ProductPurchaseIOS;
|
|
181
|
+
|
|
158
182
|
export type AppTransactionIOS = {
|
|
159
183
|
appTransactionId?: string; // Only available in iOS 18.4+
|
|
160
184
|
originalPlatform?: string; // Only available in iOS 18.4+
|
package/src/useIAP.ts
CHANGED
|
@@ -29,12 +29,10 @@ import {
|
|
|
29
29
|
// Types
|
|
30
30
|
import {
|
|
31
31
|
Product,
|
|
32
|
-
ProductPurchase,
|
|
33
32
|
Purchase,
|
|
34
33
|
PurchaseError,
|
|
35
34
|
PurchaseResult,
|
|
36
35
|
SubscriptionProduct,
|
|
37
|
-
SubscriptionPurchase,
|
|
38
36
|
RequestPurchaseProps,
|
|
39
37
|
RequestSubscriptionProps,
|
|
40
38
|
} from './ExpoIap.types';
|
|
@@ -42,12 +40,12 @@ import {
|
|
|
42
40
|
type UseIap = {
|
|
43
41
|
connected: boolean;
|
|
44
42
|
products: Product[];
|
|
45
|
-
promotedProductsIOS:
|
|
43
|
+
promotedProductsIOS: Purchase[];
|
|
46
44
|
promotedProductIdIOS?: string;
|
|
47
45
|
subscriptions: SubscriptionProduct[];
|
|
48
|
-
purchaseHistories:
|
|
49
|
-
availablePurchases:
|
|
50
|
-
currentPurchase?:
|
|
46
|
+
purchaseHistories: Purchase[];
|
|
47
|
+
availablePurchases: Purchase[];
|
|
48
|
+
currentPurchase?: Purchase;
|
|
51
49
|
currentPurchaseError?: PurchaseError;
|
|
52
50
|
promotedProductIOS?: Product;
|
|
53
51
|
activeSubscriptions: ActiveSubscription[];
|
|
@@ -99,9 +97,7 @@ type UseIap = {
|
|
|
99
97
|
};
|
|
100
98
|
|
|
101
99
|
export interface UseIAPOptions {
|
|
102
|
-
onPurchaseSuccess?: (
|
|
103
|
-
purchase: ProductPurchase | SubscriptionPurchase,
|
|
104
|
-
) => void;
|
|
100
|
+
onPurchaseSuccess?: (purchase: Purchase) => void;
|
|
105
101
|
onPurchaseError?: (error: PurchaseError) => void;
|
|
106
102
|
onSyncError?: (error: Error) => void;
|
|
107
103
|
shouldAutoSyncPurchases?: boolean; // New option to control auto-syncing
|
|
@@ -111,15 +107,11 @@ export interface UseIAPOptions {
|
|
|
111
107
|
export function useIAP(options?: UseIAPOptions): UseIap {
|
|
112
108
|
const [connected, setConnected] = useState<boolean>(false);
|
|
113
109
|
const [products, setProducts] = useState<Product[]>([]);
|
|
114
|
-
const [promotedProductsIOS] = useState<
|
|
110
|
+
const [promotedProductsIOS] = useState<Purchase[]>([]);
|
|
115
111
|
const [subscriptions, setSubscriptions] = useState<SubscriptionProduct[]>([]);
|
|
116
|
-
const [purchaseHistories, setPurchaseHistories] = useState<
|
|
117
|
-
|
|
118
|
-
);
|
|
119
|
-
const [availablePurchases, setAvailablePurchases] = useState<
|
|
120
|
-
ProductPurchase[]
|
|
121
|
-
>([]);
|
|
122
|
-
const [currentPurchase, setCurrentPurchase] = useState<ProductPurchase>();
|
|
112
|
+
const [purchaseHistories, setPurchaseHistories] = useState<Purchase[]>([]);
|
|
113
|
+
const [availablePurchases, setAvailablePurchases] = useState<Purchase[]>([]);
|
|
114
|
+
const [currentPurchase, setCurrentPurchase] = useState<Purchase>();
|
|
123
115
|
const [promotedProductIOS, setPromotedProductIOS] = useState<Product>();
|
|
124
116
|
const [currentPurchaseError, setCurrentPurchaseError] =
|
|
125
117
|
useState<PurchaseError>();
|
|
@@ -289,7 +281,7 @@ export function useIAP(options?: UseIAPOptions): UseIap {
|
|
|
289
281
|
purchase,
|
|
290
282
|
isConsumable,
|
|
291
283
|
}: {
|
|
292
|
-
purchase:
|
|
284
|
+
purchase: Purchase;
|
|
293
285
|
isConsumable?: boolean;
|
|
294
286
|
}): Promise<PurchaseResult | boolean> => {
|
|
295
287
|
try {
|
|
@@ -382,7 +374,7 @@ export function useIAP(options?: UseIAPOptions): UseIap {
|
|
|
382
374
|
|
|
383
375
|
if (result) {
|
|
384
376
|
subscriptionsRef.current.purchaseUpdate = purchaseUpdatedListener(
|
|
385
|
-
async (purchase: Purchase
|
|
377
|
+
async (purchase: Purchase) => {
|
|
386
378
|
setCurrentPurchaseError(undefined);
|
|
387
379
|
setCurrentPurchase(purchase);
|
|
388
380
|
|