react-native-iap 11.0.0-rc.1 → 11.0.0-rc.3
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/ios/IapSerializationUtils.swift +50 -11
- package/ios/IapTypes.swift +1 -6
- package/ios/RNIapIos.swift +2 -1
- package/ios/RNIapIosSk2.m +2 -1
- package/ios/RNIapIosSk2.swift +29 -16
- package/lib/commonjs/eventEmitter.js +145 -2
- package/lib/commonjs/eventEmitter.js.map +1 -1
- package/lib/commonjs/hooks/withIAPContext.js +8 -1
- package/lib/commonjs/hooks/withIAPContext.js.map +1 -1
- package/lib/commonjs/iap.js +40 -26
- package/lib/commonjs/iap.js.map +1 -1
- package/lib/commonjs/internal/platform.js +1 -1
- package/lib/commonjs/internal/platform.js.map +1 -1
- package/lib/commonjs/modules/ios.js +5 -2
- package/lib/commonjs/modules/ios.js.map +1 -1
- package/lib/commonjs/modules/iosSk2.js.map +1 -1
- package/lib/commonjs/types/appleSk2.js +2 -2
- package/lib/commonjs/types/appleSk2.js.map +1 -1
- package/lib/module/eventEmitter.js +141 -1
- package/lib/module/eventEmitter.js.map +1 -1
- package/lib/module/hooks/withIAPContext.js +9 -2
- package/lib/module/hooks/withIAPContext.js.map +1 -1
- package/lib/module/iap.js +40 -26
- package/lib/module/iap.js.map +1 -1
- package/lib/module/internal/platform.js +1 -1
- package/lib/module/internal/platform.js.map +1 -1
- package/lib/module/modules/ios.js +5 -2
- package/lib/module/modules/ios.js.map +1 -1
- package/lib/module/modules/iosSk2.js.map +1 -1
- package/lib/module/types/appleSk2.js +2 -2
- package/lib/module/types/appleSk2.js.map +1 -1
- package/lib/typescript/eventEmitter.d.ts +133 -0
- package/lib/typescript/hooks/withIAPContext.d.ts +2 -0
- package/lib/typescript/iap.d.ts +10 -2
- package/lib/typescript/modules/iosSk2.d.ts +1 -1
- package/lib/typescript/types/appleSk2.d.ts +30 -1
- package/package.json +1 -1
- package/src/eventEmitter.ts +144 -2
- package/src/hooks/withIAPContext.tsx +15 -0
- package/src/iap.ts +14 -6
- package/src/internal/platform.ts +2 -1
- package/src/modules/ios.ts +5 -2
- package/src/modules/iosSk2.ts +3 -1
- package/src/types/appleSk2.ts +40 -3
|
@@ -50,9 +50,28 @@ func serialize(_ si: Product.SubscriptionInfo?) -> [String: Any?]? {
|
|
|
50
50
|
"introductoryOffer": serialize(si.introductoryOffer),
|
|
51
51
|
"promotionalOffers": si.promotionalOffers.map {(offer: Product.SubscriptionOffer) in serialize(offer)},
|
|
52
52
|
"subscriptionGroupID": si.subscriptionGroupID,
|
|
53
|
-
"subscriptionPeriod": si.subscriptionPeriod
|
|
53
|
+
"subscriptionPeriod": serialize(si.subscriptionPeriod)
|
|
54
54
|
]
|
|
55
55
|
}
|
|
56
|
+
@available(iOS 15.0, *)
|
|
57
|
+
func serialize(_ sp: Product.SubscriptionPeriod?) -> [String: Any?]? {
|
|
58
|
+
guard let sp = sp else {return nil}
|
|
59
|
+
return ["value": sp.value,
|
|
60
|
+
"unit": serialize(sp.unit)]
|
|
61
|
+
}
|
|
62
|
+
@available(iOS 15.0, *)
|
|
63
|
+
func serialize(_ sp: Product.SubscriptionPeriod.Unit?) -> String? {
|
|
64
|
+
guard let sp = sp else {return nil}
|
|
65
|
+
switch sp {
|
|
66
|
+
case .day: return "day"
|
|
67
|
+
case .week: return "week"
|
|
68
|
+
case .month: return "month"
|
|
69
|
+
case .year: return "year"
|
|
70
|
+
default:
|
|
71
|
+
return nil
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
56
75
|
@available(iOS 15.0, *)
|
|
57
76
|
func serialize(_ s: Product.SubscriptionInfo.Status?) -> [String: Any?]? {
|
|
58
77
|
guard let s = s else {return nil}
|
|
@@ -79,7 +98,7 @@ func serialize(_ rs: Product.SubscriptionInfo.RenewalState?) -> String? {
|
|
|
79
98
|
@available(iOS 15.0, *)
|
|
80
99
|
func serialize(_ ri: Product.SubscriptionInfo.RenewalInfo?) -> [String: Any?]? {
|
|
81
100
|
guard let ri = ri else {return nil}
|
|
82
|
-
return ["signedDate": ri.signedDate
|
|
101
|
+
return ["signedDate": ri.signedDate.millisecondsSince1970
|
|
83
102
|
]
|
|
84
103
|
}
|
|
85
104
|
|
|
@@ -89,14 +108,34 @@ func serialize(_ so: Product.SubscriptionOffer?) -> [String: Any?]? {
|
|
|
89
108
|
return [
|
|
90
109
|
"displayPrice": so.displayPrice,
|
|
91
110
|
"id": so.id,
|
|
92
|
-
"paymentMode": so.paymentMode,
|
|
93
|
-
"period": so.period,
|
|
111
|
+
"paymentMode": serialize(so.paymentMode),
|
|
112
|
+
"period": serialize(so.period),
|
|
94
113
|
"periodCount": so.periodCount,
|
|
95
114
|
"price": so.price,
|
|
96
|
-
"type": so.type
|
|
115
|
+
"type": serialize(so.type)
|
|
97
116
|
]
|
|
98
117
|
}
|
|
99
|
-
|
|
118
|
+
@available(iOS 15.0, *)
|
|
119
|
+
func serialize(_ pm: Product.SubscriptionOffer.PaymentMode?) -> String? {
|
|
120
|
+
guard let pm = pm else {return nil}
|
|
121
|
+
switch pm {
|
|
122
|
+
case .freeTrial: return "freeTrial"
|
|
123
|
+
case .payAsYouGo: return "payAsYouGo"
|
|
124
|
+
case .payUpFront: return "payUpFront"
|
|
125
|
+
default:
|
|
126
|
+
return nil
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
@available(iOS 15.0, *)
|
|
130
|
+
func serialize(_ ot: Product.SubscriptionOffer.OfferType?) -> String? {
|
|
131
|
+
guard let ot = ot else {return nil}
|
|
132
|
+
switch ot {
|
|
133
|
+
case .introductory: return "introductory"
|
|
134
|
+
case .promotional: return "promotional"
|
|
135
|
+
default:
|
|
136
|
+
return nil
|
|
137
|
+
}
|
|
138
|
+
}
|
|
100
139
|
@available(iOS 15.0, *)
|
|
101
140
|
func serialize(_ t: Transaction) -> [String: Any?] {
|
|
102
141
|
return ["appAccountToken": t.appAccountToken,
|
|
@@ -104,22 +143,22 @@ func serialize(_ t: Transaction) -> [String: Any?] {
|
|
|
104
143
|
"debugDescription": serializeDebug(t.debugDescription),
|
|
105
144
|
"deviceVerification": t.deviceVerification,
|
|
106
145
|
"deviceVerificationNonce": t.deviceVerificationNonce,
|
|
107
|
-
"expirationDate": t.expirationDate,
|
|
146
|
+
"expirationDate": t.expirationDate?.millisecondsSince1970,
|
|
108
147
|
"id": t.id,
|
|
109
148
|
"isUpgraded": t.isUpgraded,
|
|
110
149
|
"jsonRepresentation": serializeDebug(t.jsonRepresentation),
|
|
111
150
|
"offerID": t.offerID,
|
|
112
151
|
"offerType": serialize(t.offerType),
|
|
113
152
|
"originalID": t.originalID,
|
|
114
|
-
"originalPurchaseDate": t.originalPurchaseDate,
|
|
153
|
+
"originalPurchaseDate": t.originalPurchaseDate.millisecondsSince1970,
|
|
115
154
|
"ownershipType": serialize(t.ownershipType),
|
|
116
155
|
"productID": t.productID,
|
|
117
156
|
"productType": serialize(t.productType),
|
|
118
|
-
"purchaseDate": t.purchaseDate,
|
|
157
|
+
"purchaseDate": t.purchaseDate.millisecondsSince1970,
|
|
119
158
|
"purchasedQuantity": t.purchasedQuantity,
|
|
120
|
-
"revocationDate": t.revocationDate,
|
|
159
|
+
"revocationDate": t.revocationDate?.millisecondsSince1970,
|
|
121
160
|
"revocationReason": t.revocationReason,
|
|
122
|
-
"signedDate": t.signedDate,
|
|
161
|
+
"signedDate": t.signedDate.millisecondsSince1970,
|
|
123
162
|
"subscriptionGroupID": t.subscriptionGroupID,
|
|
124
163
|
"webOrderLineItemID": t.webOrderLineItemID
|
|
125
164
|
]
|
package/ios/IapTypes.swift
CHANGED
|
@@ -10,12 +10,6 @@ import StoreKit
|
|
|
10
10
|
|
|
11
11
|
typealias RNIapIosPromise = (RCTPromiseResolveBlock, RCTPromiseRejectBlock)
|
|
12
12
|
|
|
13
|
-
@available(iOS 15.0, *)
|
|
14
|
-
struct ProductOrError {
|
|
15
|
-
let product: Product?
|
|
16
|
-
let error: Error?
|
|
17
|
-
}
|
|
18
|
-
|
|
19
13
|
public enum StoreError: Error {
|
|
20
14
|
case failedVerification
|
|
21
15
|
}
|
|
@@ -34,6 +28,7 @@ enum IapErrors: String, CaseIterable {
|
|
|
34
28
|
case E_PURCHASE_ERROR = "E_PURCHASE_ERROR"
|
|
35
29
|
case E_SYNC_ERROR = "E_SYNC_ERROR"
|
|
36
30
|
case E_DEFERRED_PAYMENT = "E_DEFERRED_PAYMENT"
|
|
31
|
+
case E_TRANSACTION_VALIDATION_FAILED = "E_TRANSACTION_VALIDATION_FAILED"
|
|
37
32
|
func asInt() -> Int {
|
|
38
33
|
return IapErrors.allCases.firstIndex(of: self)!
|
|
39
34
|
}
|
package/ios/RNIapIos.swift
CHANGED
|
@@ -185,6 +185,7 @@ class RNIapIos: RCTEventEmitter, SKRequestDelegate, SKPaymentTransactionObserver
|
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
187
|
@objc public func getAvailableItems(
|
|
188
|
+
alsoPublishToEventListener: Bool,
|
|
188
189
|
_ resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
189
190
|
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
190
191
|
) {
|
|
@@ -831,7 +832,7 @@ class RNIapIos: RCTEventEmitter, SKRequestDelegate, SKPaymentTransactionObserver
|
|
|
831
832
|
"transactionDate": transaction.transactionDate?.millisecondsSince1970String,
|
|
832
833
|
"transactionId": transaction.transactionIdentifier,
|
|
833
834
|
"productId": transaction.payment.productIdentifier,
|
|
834
|
-
"transactionReceipt": receiptData?.base64EncodedString(options: [])
|
|
835
|
+
"transactionReceipt": receiptData?.base64EncodedString(options: [.endLineWithCarriageReturn])
|
|
835
836
|
]
|
|
836
837
|
|
|
837
838
|
// originalTransaction is available for restore purchase and purchase of cancelled/expired subscriptions
|
package/ios/RNIapIosSk2.m
CHANGED
|
@@ -18,7 +18,8 @@ RCT_EXTERN_METHOD(getItems:
|
|
|
18
18
|
reject:(RCTPromiseRejectBlock)reject)
|
|
19
19
|
|
|
20
20
|
RCT_EXTERN_METHOD(getAvailableItems:
|
|
21
|
-
(
|
|
21
|
+
alsoPublishToEventListener:(BOOL)alsoPublishToEventListener
|
|
22
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
22
23
|
reject:(RCTPromiseRejectBlock)reject)
|
|
23
24
|
|
|
24
25
|
RCT_EXTERN_METHOD(buyProduct:
|
package/ios/RNIapIosSk2.swift
CHANGED
|
@@ -52,21 +52,25 @@ class RNIapIosSk2: RCTEventEmitter {
|
|
|
52
52
|
|
|
53
53
|
if self.hasListeners {
|
|
54
54
|
self.sendEvent(withName: "purchase-updated", body: serialize(transaction))
|
|
55
|
+
self.sendEvent(withName: "iap-transaction-updated", body: ["transaction": serialize(transaction)])
|
|
55
56
|
}
|
|
56
57
|
// Always finish a transaction.
|
|
57
|
-
// await transaction.finish()
|
|
58
|
+
// await transaction.finish()
|
|
59
|
+
// The transaction is returned to the user. Once it has fullfilled the order,
|
|
60
|
+
// they can call finishTransaction
|
|
58
61
|
} catch {
|
|
59
62
|
// StoreKit has a transaction that fails verification. Don't deliver content to the user.
|
|
60
63
|
debugMessage("Transaction failed verification")
|
|
61
64
|
if self.hasListeners {
|
|
62
65
|
let err = [
|
|
63
|
-
"responseCode":
|
|
66
|
+
"responseCode": IapErrors.E_TRANSACTION_VALIDATION_FAILED.rawValue,
|
|
64
67
|
"debugMessage": error.localizedDescription,
|
|
65
|
-
"code":
|
|
68
|
+
"code": IapErrors.E_TRANSACTION_VALIDATION_FAILED.rawValue,
|
|
66
69
|
"message": error.localizedDescription
|
|
67
70
|
]
|
|
68
71
|
|
|
69
72
|
self.sendEvent(withName: "purchase-error", body: err)
|
|
73
|
+
self.sendEvent(withName: "iap-transaction-updated", body: ["error": err])
|
|
70
74
|
}
|
|
71
75
|
}
|
|
72
76
|
}
|
|
@@ -84,8 +88,13 @@ class RNIapIosSk2: RCTEventEmitter {
|
|
|
84
88
|
super.addListener(eventName)
|
|
85
89
|
}
|
|
86
90
|
|
|
91
|
+
/**
|
|
92
|
+
"iap-transaction-updated" is unique to Sk2.
|
|
93
|
+
"iap-promoted-product" is only avaiable on Sk1
|
|
94
|
+
"purchase-updated", "purchase-error" are for backward compatibility
|
|
95
|
+
*/
|
|
87
96
|
override func supportedEvents() -> [String]? {
|
|
88
|
-
return [ "
|
|
97
|
+
return [ "purchase-updated", "purchase-error", "iap-transaction-updated"]
|
|
89
98
|
}
|
|
90
99
|
|
|
91
100
|
@objc public func initConnection(
|
|
@@ -127,19 +136,23 @@ class RNIapIosSk2: RCTEventEmitter {
|
|
|
127
136
|
}
|
|
128
137
|
|
|
129
138
|
@objc public func getAvailableItems(
|
|
139
|
+
alsoPublishToEventListener: Bool,
|
|
130
140
|
_ resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
131
141
|
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
132
142
|
) {
|
|
133
143
|
Task {
|
|
134
|
-
var purchasedItems: [
|
|
144
|
+
var purchasedItems: [Transaction] = []
|
|
135
145
|
|
|
136
146
|
func addPurchase(transaction: Transaction, product: Product) {
|
|
137
|
-
purchasedItems.append(
|
|
138
|
-
|
|
147
|
+
purchasedItems.append( transaction)
|
|
148
|
+
if alsoPublishToEventListener {
|
|
149
|
+
sendEvent(withName: "purchase-update", body: serialize(transaction))
|
|
150
|
+
}
|
|
139
151
|
}
|
|
140
152
|
func addError( error: Error, errorDict: [String: String]) {
|
|
141
|
-
|
|
142
|
-
|
|
153
|
+
if alsoPublishToEventListener {
|
|
154
|
+
sendEvent(withName: "purchase-error", body: errorDict)
|
|
155
|
+
}
|
|
143
156
|
}
|
|
144
157
|
// Iterate through all of the user's purchased products.
|
|
145
158
|
for await result in Transaction.currentEntitlements {
|
|
@@ -178,20 +191,20 @@ class RNIapIosSk2: RCTEventEmitter {
|
|
|
178
191
|
break
|
|
179
192
|
}
|
|
180
193
|
} catch StoreError.failedVerification {
|
|
181
|
-
let err = [ "responseCode":
|
|
194
|
+
let err = [ "responseCode": IapErrors.E_TRANSACTION_VALIDATION_FAILED.rawValue,
|
|
182
195
|
"debugMessage": StoreError.failedVerification.localizedDescription,
|
|
183
|
-
"code":
|
|
196
|
+
"code": IapErrors.E_TRANSACTION_VALIDATION_FAILED.rawValue,
|
|
184
197
|
"message": StoreError.failedVerification.localizedDescription,
|
|
185
|
-
"productId": "unknown"
|
|
198
|
+
"productId": "unknown"
|
|
186
199
|
]
|
|
187
200
|
addError(error: StoreError.failedVerification, errorDict: err)
|
|
188
201
|
} catch {
|
|
189
202
|
debugMessage(error)
|
|
190
|
-
let err = [ "responseCode":
|
|
203
|
+
let err = [ "responseCode": IapErrors.E_UNKNOWN.rawValue,
|
|
191
204
|
"debugMessage": error.localizedDescription,
|
|
192
|
-
"code":
|
|
205
|
+
"code": IapErrors.E_UNKNOWN.rawValue,
|
|
193
206
|
"message": error.localizedDescription,
|
|
194
|
-
"productId": "unknown"
|
|
207
|
+
"productId": "unknown"
|
|
195
208
|
]
|
|
196
209
|
addError(error: StoreError.failedVerification, errorDict: err)
|
|
197
210
|
}
|
|
@@ -201,7 +214,7 @@ class RNIapIosSk2: RCTEventEmitter {
|
|
|
201
214
|
// group, so products in the subscriptions array all belong to the same group. The statuses that
|
|
202
215
|
// `product.subscription.status` returns apply to the entire subscription group.
|
|
203
216
|
// subscriptionGroupStatus = try? await subscriptions.first?.subscription?.status.first?.state
|
|
204
|
-
resolve(purchasedItems.map({(
|
|
217
|
+
resolve(purchasedItems.map({(t: Transaction) in serialize(t)}))
|
|
205
218
|
}
|
|
206
219
|
}
|
|
207
220
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.purchaseUpdatedListener = exports.purchaseErrorListener = exports.promotedProductListener = void 0;
|
|
6
|
+
exports.transactionListener = exports.purchaseUpdatedListener = exports.purchaseErrorListener = exports.promotedProductListener = void 0;
|
|
7
7
|
|
|
8
8
|
var _reactNative = require("react-native");
|
|
9
9
|
|
|
@@ -15,6 +15,35 @@ var _internal = require("./internal");
|
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Add IAP purchase event
|
|
18
|
+
* Register a callback that gets called when the store has any updates to purchases that have not yet been finished, consumed or acknowledged. Returns a React Native `EmitterSubscription` on which you can call `.remove()` to stop receiving updates. Register you listener as soon as possible and react to updates at all times.
|
|
19
|
+
|
|
20
|
+
## Signature
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
purchaseUpdatedListener((purchase: Purchase) => {});
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
```tsx
|
|
29
|
+
import React, {useEffect} from 'react';
|
|
30
|
+
import {View} from 'react-native';
|
|
31
|
+
import {purchaseUpdatedListener} from 'react-native-iap';
|
|
32
|
+
|
|
33
|
+
const App = () => {
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
const subscription = purchaseUpdatedListener((purchase: Purchase) => {
|
|
36
|
+
console.log(purchase);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return () => {
|
|
40
|
+
subscription.remove();
|
|
41
|
+
};
|
|
42
|
+
}, []);
|
|
43
|
+
|
|
44
|
+
return <View />;
|
|
45
|
+
};
|
|
46
|
+
```
|
|
18
47
|
*/
|
|
19
48
|
const purchaseUpdatedListener = listener => {
|
|
20
49
|
const eventEmitter = new _reactNative.NativeEventEmitter((0, _internal.getNativeModule)());
|
|
@@ -31,6 +60,36 @@ const purchaseUpdatedListener = listener => {
|
|
|
31
60
|
};
|
|
32
61
|
/**
|
|
33
62
|
* Add IAP purchase error event
|
|
63
|
+
* Register a callback that gets called when there has been an error with a purchase. Returns a React Native `EmitterSubscription` on which you can call `.remove()` to stop receiving updates.
|
|
64
|
+
|
|
65
|
+
## Signature
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
purchaseErrorListener((error: PurchaseError) => {});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Usage
|
|
72
|
+
|
|
73
|
+
```tsx
|
|
74
|
+
import React, {useEffect} from 'react';
|
|
75
|
+
import {View} from 'react-native';
|
|
76
|
+
import {purchaseErrorListener} from 'react-native-iap';
|
|
77
|
+
|
|
78
|
+
const App = () => {
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
const subscription = purchaseErrorListener((error: PurchaseError) => {
|
|
81
|
+
console.log(error);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
return () => {
|
|
85
|
+
subscription.remove();
|
|
86
|
+
};
|
|
87
|
+
}, []);
|
|
88
|
+
|
|
89
|
+
return <View />;
|
|
90
|
+
};
|
|
91
|
+
```
|
|
92
|
+
|
|
34
93
|
*/
|
|
35
94
|
|
|
36
95
|
|
|
@@ -42,6 +101,36 @@ const purchaseErrorListener = listener => {
|
|
|
42
101
|
};
|
|
43
102
|
/**
|
|
44
103
|
* Add IAP promoted subscription event
|
|
104
|
+
* Add IAP promoted subscription event.
|
|
105
|
+
|
|
106
|
+
## Signature
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
promotedProductListener((productId?: string) => {});
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Usage
|
|
113
|
+
|
|
114
|
+
```tsx
|
|
115
|
+
import React, {useEffect} from 'react';
|
|
116
|
+
import {View} from 'react-native';
|
|
117
|
+
import {promotedProductListener} from 'react-native-iap';
|
|
118
|
+
|
|
119
|
+
const App = () => {
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
const subscription = promotedProductListener((productId) => {
|
|
122
|
+
console.log(productId);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
return () => {
|
|
126
|
+
subscription.remove();
|
|
127
|
+
};
|
|
128
|
+
}, []);
|
|
129
|
+
|
|
130
|
+
return <View />;
|
|
131
|
+
};
|
|
132
|
+
```
|
|
133
|
+
|
|
45
134
|
*
|
|
46
135
|
* @platform iOS
|
|
47
136
|
*/
|
|
@@ -50,13 +139,67 @@ const purchaseErrorListener = listener => {
|
|
|
50
139
|
exports.purchaseErrorListener = purchaseErrorListener;
|
|
51
140
|
|
|
52
141
|
const promotedProductListener = listener => {
|
|
53
|
-
if (_internal.isIos) {
|
|
142
|
+
if (_internal.isIos && !(0, _iap.isIosStorekit2)()) {
|
|
54
143
|
const eventEmitter = new _reactNative.NativeEventEmitter((0, _internal.getIosModule)());
|
|
55
144
|
return eventEmitter.addListener('iap-promoted-product', listener);
|
|
56
145
|
}
|
|
57
146
|
|
|
58
147
|
return null;
|
|
59
148
|
};
|
|
149
|
+
/**
|
|
150
|
+
* Updated transactions for iOS Sk2
|
|
151
|
+
* Register a callback that gets called when the store has any updates to transactions related to purchases that have not yet been finished, consumed or acknowledged.
|
|
152
|
+
* Returns a React Native `EmitterSubscription` on which you can call `.remove()` to stop receiving updates. Register you listener as soon as possible and react to updates at all times.
|
|
153
|
+
|
|
154
|
+
**Warning**
|
|
155
|
+
This is only available for iOS 15 and higher and Storekit 2 is activated
|
|
156
|
+
|
|
157
|
+
## Signature
|
|
158
|
+
|
|
159
|
+
```ts
|
|
160
|
+
purchaseUpdatedListener((transactionOrError: TransactionOrError) => {});
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Usage
|
|
164
|
+
|
|
165
|
+
```tsx
|
|
166
|
+
import React, {useEffect} from 'react';
|
|
167
|
+
import {View} from 'react-native';
|
|
168
|
+
import {purchaseUpdatedListener} from 'react-native-iap';
|
|
169
|
+
|
|
170
|
+
const App = () => {
|
|
171
|
+
useEffect(() => {
|
|
172
|
+
const subscription = purchaseUpdatedListener((transactionOrError: TransactionOrError) => {
|
|
173
|
+
if(transactionOrError.transaction){
|
|
174
|
+
console.log("There's an update to a transaction", transactionOrError.transaction);
|
|
175
|
+
}else{
|
|
176
|
+
console.log("There's been an error with a received transaction")
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
return () => {
|
|
181
|
+
subscription.remove();
|
|
182
|
+
};
|
|
183
|
+
}, []);
|
|
184
|
+
|
|
185
|
+
return <View />;
|
|
186
|
+
};
|
|
187
|
+
```
|
|
188
|
+
*
|
|
189
|
+
* @platform iOS (Sk2)
|
|
190
|
+
*/
|
|
191
|
+
|
|
60
192
|
|
|
61
193
|
exports.promotedProductListener = promotedProductListener;
|
|
194
|
+
|
|
195
|
+
const transactionListener = listener => {
|
|
196
|
+
if (_internal.isIos && (0, _iap.isIosStorekit2)()) {
|
|
197
|
+
const eventEmitter = new _reactNative.NativeEventEmitter((0, _internal.getIosModule)());
|
|
198
|
+
return eventEmitter.addListener('iap-transaction-updated', listener);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return null;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
exports.transactionListener = transactionListener;
|
|
62
205
|
//# sourceMappingURL=eventEmitter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["purchaseUpdatedListener","listener","eventEmitter","NativeEventEmitter","getNativeModule","proxyListener","isIosStorekit2","event","transactionSk2Map","emitterSubscription","addListener","isAndroid","getAndroidModule","startListening","purchaseErrorListener","promotedProductListener","isIos","getIosModule"],"sources":["eventEmitter.ts"],"sourcesContent":["import {EmitterSubscription, NativeEventEmitter} from 'react-native';\n\nimport {transactionSk2Map} from './types/appleSk2';\nimport {isIosStorekit2} from './iap';\nimport {\n getAndroidModule,\n getIosModule,\n getNativeModule,\n isAndroid,\n isIos,\n} from './internal';\nimport type {PurchaseError} from './purchaseError';\nimport type {Purchase} from './types';\n\n/**\n * Add IAP purchase event\n */\nexport const purchaseUpdatedListener = (\n listener: (event: Purchase) => void,\n) => {\n const eventEmitter = new NativeEventEmitter(getNativeModule());\n const proxyListener = isIosStorekit2()\n ? (event: Purchase) => {\n listener(transactionSk2Map(event as any));\n }\n : listener;\n const emitterSubscription = eventEmitter.addListener(\n 'purchase-updated',\n proxyListener,\n );\n\n if (isAndroid) {\n getAndroidModule().startListening();\n }\n\n return emitterSubscription;\n};\n\n/**\n * Add IAP purchase error event\n */\nexport const purchaseErrorListener = (\n listener: (error: PurchaseError) => void,\n): EmitterSubscription => {\n const eventEmitter = new NativeEventEmitter(getNativeModule());\n return eventEmitter.addListener('purchase-error', listener);\n};\n\n/**\n * Add IAP promoted subscription event\n *\n * @platform iOS\n */\nexport const promotedProductListener = (listener: () => void) => {\n if (isIos) {\n const eventEmitter = new NativeEventEmitter(getIosModule());\n return eventEmitter.addListener('iap-promoted-product', listener);\n }\n\n return null;\n};\n"],"mappings":";;;;;;;AAAA;;AAEA;;AACA;;AACA;;AAUA;AACA;AACA;AACO,MAAMA,uBAAuB,GAClCC,QADqC,IAElC;EACH,MAAMC,YAAY,GAAG,IAAIC,+BAAJ,CAAuB,IAAAC,yBAAA,GAAvB,CAArB;EACA,MAAMC,aAAa,GAAG,IAAAC,mBAAA,MACjBC,KAAD,IAAqB;IACnBN,QAAQ,CAAC,IAAAO,0BAAA,EAAkBD,KAAlB,CAAD,CAAR;EACD,CAHiB,GAIlBN,QAJJ;EAKA,MAAMQ,mBAAmB,GAAGP,YAAY,CAACQ,WAAb,CAC1B,kBAD0B,EAE1BL,aAF0B,CAA5B;;EAKA,IAAIM,mBAAJ,EAAe;IACb,IAAAC,0BAAA,IAAmBC,cAAnB;EACD;;EAED,OAAOJ,mBAAP;AACD,CAnBM;AAqBP;AACA;AACA;;;;;AACO,MAAMK,qBAAqB,GAChCb,QADmC,IAEX;EACxB,MAAMC,YAAY,GAAG,IAAIC,+BAAJ,CAAuB,IAAAC,yBAAA,GAAvB,CAArB;EACA,OAAOF,YAAY,CAACQ,WAAb,CAAyB,gBAAzB,EAA2CT,QAA3C,CAAP;AACD,CALM;AAOP;AACA;AACA;AACA;AACA;;;;;AACO,MAAMc,uBAAuB,GAAId,QAAD,IAA0B;EAC/D,IAAIe,
|
|
1
|
+
{"version":3,"names":["purchaseUpdatedListener","listener","eventEmitter","NativeEventEmitter","getNativeModule","proxyListener","isIosStorekit2","event","transactionSk2Map","emitterSubscription","addListener","isAndroid","getAndroidModule","startListening","purchaseErrorListener","promotedProductListener","isIos","getIosModule","transactionListener"],"sources":["eventEmitter.ts"],"sourcesContent":["import {EmitterSubscription, NativeEventEmitter} from 'react-native';\n\nimport {TransactionEvent, transactionSk2Map} from './types/appleSk2';\nimport {isIosStorekit2} from './iap';\nimport {\n getAndroidModule,\n getIosModule,\n getNativeModule,\n isAndroid,\n isIos,\n} from './internal';\nimport type {PurchaseError} from './purchaseError';\nimport type {Purchase} from './types';\n\n/**\n * Add IAP purchase event\n * Register a callback that gets called when the store has any updates to purchases that have not yet been finished, consumed or acknowledged. Returns a React Native `EmitterSubscription` on which you can call `.remove()` to stop receiving updates. Register you listener as soon as possible and react to updates at all times.\n\n## Signature\n\n```ts\npurchaseUpdatedListener((purchase: Purchase) => {});\n```\n\n## Usage\n\n```tsx\nimport React, {useEffect} from 'react';\nimport {View} from 'react-native';\nimport {purchaseUpdatedListener} from 'react-native-iap';\n\nconst App = () => {\n useEffect(() => {\n const subscription = purchaseUpdatedListener((purchase: Purchase) => {\n console.log(purchase);\n });\n\n return () => {\n subscription.remove();\n };\n }, []);\n\n return <View />;\n};\n```\n */\nexport const purchaseUpdatedListener = (\n listener: (event: Purchase) => void,\n) => {\n const eventEmitter = new NativeEventEmitter(getNativeModule());\n const proxyListener = isIosStorekit2()\n ? (event: Purchase) => {\n listener(transactionSk2Map(event as any));\n }\n : listener;\n const emitterSubscription = eventEmitter.addListener(\n 'purchase-updated',\n proxyListener,\n );\n\n if (isAndroid) {\n getAndroidModule().startListening();\n }\n\n return emitterSubscription;\n};\n\n/**\n * Add IAP purchase error event\n * Register a callback that gets called when there has been an error with a purchase. Returns a React Native `EmitterSubscription` on which you can call `.remove()` to stop receiving updates.\n\n## Signature\n\n```ts\npurchaseErrorListener((error: PurchaseError) => {});\n```\n\n## Usage\n\n```tsx\nimport React, {useEffect} from 'react';\nimport {View} from 'react-native';\nimport {purchaseErrorListener} from 'react-native-iap';\n\nconst App = () => {\n useEffect(() => {\n const subscription = purchaseErrorListener((error: PurchaseError) => {\n console.log(error);\n });\n\n return () => {\n subscription.remove();\n };\n }, []);\n\n return <View />;\n};\n```\n\n */\nexport const purchaseErrorListener = (\n listener: (error: PurchaseError) => void,\n): EmitterSubscription => {\n const eventEmitter = new NativeEventEmitter(getNativeModule());\n return eventEmitter.addListener('purchase-error', listener);\n};\n\n/**\n * Add IAP promoted subscription event\n * Add IAP promoted subscription event.\n\n## Signature\n\n```ts\npromotedProductListener((productId?: string) => {});\n```\n\n## Usage\n\n```tsx\nimport React, {useEffect} from 'react';\nimport {View} from 'react-native';\nimport {promotedProductListener} from 'react-native-iap';\n\nconst App = () => {\n useEffect(() => {\n const subscription = promotedProductListener((productId) => {\n console.log(productId);\n });\n\n return () => {\n subscription.remove();\n };\n }, []);\n\n return <View />;\n};\n```\n\n *\n * @platform iOS\n */\nexport const promotedProductListener = (listener: () => void) => {\n if (isIos && !isIosStorekit2()) {\n const eventEmitter = new NativeEventEmitter(getIosModule());\n return eventEmitter.addListener('iap-promoted-product', listener);\n }\n\n return null;\n};\n\n/**\n * Updated transactions for iOS Sk2\n * Register a callback that gets called when the store has any updates to transactions related to purchases that have not yet been finished, consumed or acknowledged. \n * Returns a React Native `EmitterSubscription` on which you can call `.remove()` to stop receiving updates. Register you listener as soon as possible and react to updates at all times.\n\n**Warning**\nThis is only available for iOS 15 and higher and Storekit 2 is activated\n\n## Signature\n\n```ts\npurchaseUpdatedListener((transactionOrError: TransactionOrError) => {});\n```\n\n## Usage\n\n```tsx\nimport React, {useEffect} from 'react';\nimport {View} from 'react-native';\nimport {purchaseUpdatedListener} from 'react-native-iap';\n\nconst App = () => {\n useEffect(() => {\n const subscription = purchaseUpdatedListener((transactionOrError: TransactionOrError) => {\n if(transactionOrError.transaction){\n console.log(\"There's an update to a transaction\", transactionOrError.transaction);\n }else{\n console.log(\"There's been an error with a received transaction\")\n }\n });\n\n return () => {\n subscription.remove();\n };\n }, []);\n\n return <View />;\n};\n```\n *\n * @platform iOS (Sk2)\n */\nexport const transactionListener = (\n listener: (event: TransactionEvent) => void,\n) => {\n if (isIos && isIosStorekit2()) {\n const eventEmitter = new NativeEventEmitter(getIosModule());\n return eventEmitter.addListener('iap-transaction-updated', listener);\n }\n\n return null;\n};\n"],"mappings":";;;;;;;AAAA;;AAEA;;AACA;;AACA;;AAUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,uBAAuB,GAClCC,QADqC,IAElC;EACH,MAAMC,YAAY,GAAG,IAAIC,+BAAJ,CAAuB,IAAAC,yBAAA,GAAvB,CAArB;EACA,MAAMC,aAAa,GAAG,IAAAC,mBAAA,MACjBC,KAAD,IAAqB;IACnBN,QAAQ,CAAC,IAAAO,0BAAA,EAAkBD,KAAlB,CAAD,CAAR;EACD,CAHiB,GAIlBN,QAJJ;EAKA,MAAMQ,mBAAmB,GAAGP,YAAY,CAACQ,WAAb,CAC1B,kBAD0B,EAE1BL,aAF0B,CAA5B;;EAKA,IAAIM,mBAAJ,EAAe;IACb,IAAAC,0BAAA,IAAmBC,cAAnB;EACD;;EAED,OAAOJ,mBAAP;AACD,CAnBM;AAqBP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,MAAMK,qBAAqB,GAChCb,QADmC,IAEX;EACxB,MAAMC,YAAY,GAAG,IAAIC,+BAAJ,CAAuB,IAAAC,yBAAA,GAAvB,CAArB;EACA,OAAOF,YAAY,CAACQ,WAAb,CAAyB,gBAAzB,EAA2CT,QAA3C,CAAP;AACD,CALM;AAOP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,MAAMc,uBAAuB,GAAId,QAAD,IAA0B;EAC/D,IAAIe,eAAA,IAAS,CAAC,IAAAV,mBAAA,GAAd,EAAgC;IAC9B,MAAMJ,YAAY,GAAG,IAAIC,+BAAJ,CAAuB,IAAAc,sBAAA,GAAvB,CAArB;IACA,OAAOf,YAAY,CAACQ,WAAb,CAAyB,sBAAzB,EAAiDT,QAAjD,CAAP;EACD;;EAED,OAAO,IAAP;AACD,CAPM;AASP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,MAAMiB,mBAAmB,GAC9BjB,QADiC,IAE9B;EACH,IAAIe,eAAA,IAAS,IAAAV,mBAAA,GAAb,EAA+B;IAC7B,MAAMJ,YAAY,GAAG,IAAIC,+BAAJ,CAAuB,IAAAc,sBAAA,GAAvB,CAArB;IACA,OAAOf,YAAY,CAACQ,WAAb,CAAyB,yBAAzB,EAAoDT,QAApD,CAAP;EACD;;EAED,OAAO,IAAP;AACD,CATM"}
|
|
@@ -38,6 +38,7 @@ function withIAPContext(Component) {
|
|
|
38
38
|
const [purchaseHistory, setPurchaseHistory] = (0, _react.useState)([]);
|
|
39
39
|
const [availablePurchases, setAvailablePurchases] = (0, _react.useState)([]);
|
|
40
40
|
const [currentPurchase, setCurrentPurchase] = (0, _react.useState)();
|
|
41
|
+
const [currentTransaction, setCurrentTransaction] = (0, _react.useState)();
|
|
41
42
|
const [currentPurchaseError, setCurrentPurchaseError] = (0, _react.useState)();
|
|
42
43
|
const [initConnectionError, setInitConnectionError] = (0, _react.useState)();
|
|
43
44
|
const context = (0, _react.useMemo)(() => ({
|
|
@@ -48,6 +49,7 @@ function withIAPContext(Component) {
|
|
|
48
49
|
purchaseHistory,
|
|
49
50
|
availablePurchases,
|
|
50
51
|
currentPurchase,
|
|
52
|
+
currentTransaction,
|
|
51
53
|
currentPurchaseError,
|
|
52
54
|
initConnectionError,
|
|
53
55
|
setProducts,
|
|
@@ -56,7 +58,7 @@ function withIAPContext(Component) {
|
|
|
56
58
|
setAvailablePurchases,
|
|
57
59
|
setCurrentPurchase,
|
|
58
60
|
setCurrentPurchaseError
|
|
59
|
-
}), [connected, products, subscriptions, promotedProductsIOS, purchaseHistory, availablePurchases, currentPurchase, currentPurchaseError, initConnectionError, setProducts, setSubscriptions, setPurchaseHistory, setAvailablePurchases, setCurrentPurchase, setCurrentPurchaseError]);
|
|
61
|
+
}), [connected, products, subscriptions, promotedProductsIOS, purchaseHistory, availablePurchases, currentPurchase, currentTransaction, currentPurchaseError, initConnectionError, setProducts, setSubscriptions, setPurchaseHistory, setAvailablePurchases, setCurrentPurchase, setCurrentPurchaseError]);
|
|
60
62
|
(0, _react.useEffect)(() => {
|
|
61
63
|
(0, _iap.initConnection)().then(value => {
|
|
62
64
|
setInitConnectionError(undefined);
|
|
@@ -72,6 +74,10 @@ function withIAPContext(Component) {
|
|
|
72
74
|
setCurrentPurchaseError(undefined);
|
|
73
75
|
setCurrentPurchase(purchase);
|
|
74
76
|
});
|
|
77
|
+
const transactionUpdateSubscription = (0, _eventEmitter.transactionListener)(async transactionOrError => {
|
|
78
|
+
setCurrentPurchaseError(transactionOrError === null || transactionOrError === void 0 ? void 0 : transactionOrError.error);
|
|
79
|
+
setCurrentTransaction(transactionOrError === null || transactionOrError === void 0 ? void 0 : transactionOrError.transaction);
|
|
80
|
+
});
|
|
75
81
|
const purchaseErrorSubscription = (0, _eventEmitter.purchaseErrorListener)(error => {
|
|
76
82
|
setCurrentPurchase(undefined);
|
|
77
83
|
setCurrentPurchaseError(error);
|
|
@@ -84,6 +90,7 @@ function withIAPContext(Component) {
|
|
|
84
90
|
purchaseUpdateSubscription.remove();
|
|
85
91
|
purchaseErrorSubscription.remove();
|
|
86
92
|
promotedProductSubscription === null || promotedProductSubscription === void 0 ? void 0 : promotedProductSubscription.remove();
|
|
93
|
+
transactionUpdateSubscription === null || transactionUpdateSubscription === void 0 ? void 0 : transactionUpdateSubscription.remove();
|
|
87
94
|
};
|
|
88
95
|
}, [connected]);
|
|
89
96
|
return /*#__PURE__*/_react.default.createElement(IAPContext.Provider, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["IAPContext","React","createContext","useIAPContext","ctx","useContext","Error","withIAPContext","Component","WrapperComponent","props","connected","setConnected","useState","products","setProducts","promotedProductsIOS","setPromotedProductsIOS","subscriptions","setSubscriptions","purchaseHistory","setPurchaseHistory","availablePurchases","setAvailablePurchases","currentPurchase","setCurrentPurchase","currentPurchaseError","setCurrentPurchaseError","initConnectionError","setInitConnectionError","context","useMemo","useEffect","initConnection","then","value","undefined","catch","purchaseUpdateSubscription","purchaseUpdatedListener","purchase","
|
|
1
|
+
{"version":3,"names":["IAPContext","React","createContext","useIAPContext","ctx","useContext","Error","withIAPContext","Component","WrapperComponent","props","connected","setConnected","useState","products","setProducts","promotedProductsIOS","setPromotedProductsIOS","subscriptions","setSubscriptions","purchaseHistory","setPurchaseHistory","availablePurchases","setAvailablePurchases","currentPurchase","setCurrentPurchase","currentTransaction","setCurrentTransaction","currentPurchaseError","setCurrentPurchaseError","initConnectionError","setInitConnectionError","context","useMemo","useEffect","initConnection","then","value","undefined","catch","purchaseUpdateSubscription","purchaseUpdatedListener","purchase","transactionUpdateSubscription","transactionListener","transactionOrError","error","transaction","purchaseErrorSubscription","purchaseErrorListener","promotedProductSubscription","promotedProductListener","product","IapIos","getPromotedProductIOS","prevProducts","remove"],"sources":["withIAPContext.tsx"],"sourcesContent":["import React, {useContext, useEffect, useMemo, useState} from 'react';\n\nimport {\n promotedProductListener,\n purchaseErrorListener,\n purchaseUpdatedListener,\n transactionListener,\n} from '../eventEmitter';\nimport {IapIos, initConnection} from '../iap';\nimport type {PurchaseError} from '../purchaseError';\nimport type {\n Product,\n ProductPurchase,\n Purchase,\n Subscription,\n SubscriptionPurchase,\n} from '../types';\nimport type {TransactionEvent, TransactionSk2} from '../types/appleSk2';\n\ntype IAPContextType = {\n connected: boolean;\n products: Product[];\n promotedProductsIOS: Product[];\n subscriptions: Subscription[];\n purchaseHistory: Purchase[];\n availablePurchases: Purchase[];\n currentPurchase?: Purchase;\n currentTransaction?: TransactionSk2;\n currentPurchaseError?: PurchaseError;\n initConnectionError?: Error;\n setProducts: (products: Product[]) => void;\n setSubscriptions: (subscriptions: Subscription[]) => void;\n setPurchaseHistory: (purchaseHistory: Purchase[]) => void;\n setAvailablePurchases: (availablePurchases: Purchase[]) => void;\n setCurrentPurchase: (currentPurchase: Purchase | undefined) => void;\n setCurrentPurchaseError: (\n currentPurchaseError: PurchaseError | undefined,\n ) => void;\n};\n\n// @ts-ignore\nconst IAPContext = React.createContext<IAPContextType>(null);\n\nexport function useIAPContext(): IAPContextType {\n const ctx = useContext(IAPContext);\n\n if (!ctx) {\n throw new Error('You need wrap your app with withIAPContext HOC');\n }\n\n return ctx;\n}\n\nexport function withIAPContext<T>(Component: React.ComponentType<T>) {\n return function WrapperComponent(props: T) {\n const [connected, setConnected] = useState(false);\n const [products, setProducts] = useState<Product[]>([]);\n\n const [promotedProductsIOS, setPromotedProductsIOS] = useState<Product[]>(\n [],\n );\n const [subscriptions, setSubscriptions] = useState<Subscription[]>([]);\n const [purchaseHistory, setPurchaseHistory] = useState<Purchase[]>([]);\n\n const [availablePurchases, setAvailablePurchases] = useState<Purchase[]>(\n [],\n );\n const [currentPurchase, setCurrentPurchase] = useState<Purchase>();\n const [currentTransaction, setCurrentTransaction] =\n useState<TransactionSk2>();\n\n const [currentPurchaseError, setCurrentPurchaseError] =\n useState<PurchaseError>();\n\n const [initConnectionError, setInitConnectionError] = useState<Error>();\n\n const context = useMemo(\n () => ({\n connected,\n products,\n subscriptions,\n promotedProductsIOS,\n purchaseHistory,\n availablePurchases,\n currentPurchase,\n currentTransaction,\n currentPurchaseError,\n initConnectionError,\n setProducts,\n setSubscriptions,\n setPurchaseHistory,\n setAvailablePurchases,\n setCurrentPurchase,\n setCurrentPurchaseError,\n }),\n [\n connected,\n products,\n subscriptions,\n promotedProductsIOS,\n purchaseHistory,\n availablePurchases,\n currentPurchase,\n currentTransaction,\n currentPurchaseError,\n initConnectionError,\n setProducts,\n setSubscriptions,\n setPurchaseHistory,\n setAvailablePurchases,\n setCurrentPurchase,\n setCurrentPurchaseError,\n ],\n );\n\n useEffect(() => {\n initConnection()\n .then((value) => {\n setInitConnectionError(undefined);\n setConnected(value);\n })\n .catch(setInitConnectionError);\n }, []);\n\n useEffect(() => {\n if (!connected) {\n return;\n }\n\n const purchaseUpdateSubscription = purchaseUpdatedListener(\n async (purchase: ProductPurchase | SubscriptionPurchase) => {\n setCurrentPurchaseError(undefined);\n setCurrentPurchase(purchase);\n },\n );\n\n const transactionUpdateSubscription = transactionListener(\n async (transactionOrError: TransactionEvent) => {\n setCurrentPurchaseError(transactionOrError?.error);\n setCurrentTransaction(transactionOrError?.transaction);\n },\n );\n\n const purchaseErrorSubscription = purchaseErrorListener(\n (error: PurchaseError) => {\n setCurrentPurchase(undefined);\n setCurrentPurchaseError(error);\n },\n );\n\n const promotedProductSubscription = promotedProductListener(async () => {\n const product = await IapIos.getPromotedProductIOS();\n\n setPromotedProductsIOS((prevProducts) => [\n ...prevProducts,\n ...(product ? [product] : []),\n ]);\n });\n\n return () => {\n purchaseUpdateSubscription.remove();\n purchaseErrorSubscription.remove();\n promotedProductSubscription?.remove();\n transactionUpdateSubscription?.remove();\n };\n }, [connected]);\n\n return (\n <IAPContext.Provider value={context}>\n <Component {...props} />\n </IAPContext.Provider>\n );\n };\n}\n"],"mappings":";;;;;;;;AAAA;;AAEA;;AAMA;;;;;;AAgCA;AACA,MAAMA,UAAU,gBAAGC,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