react-native-iap 10.1.0 → 11.0.0-alpha.7

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.
@@ -0,0 +1,129 @@
1
+ //
2
+ // IapSerializationUtils.swift
3
+ // RNIap
4
+ //
5
+ // Created by Andres Aguilar on 8/18/22.
6
+ //
7
+
8
+ import Foundation
9
+ import StoreKit
10
+ @available(iOS 15.0, *)
11
+ func serialize(_ p: Product) -> [String: Any?] {
12
+ return [
13
+ "debugDescription": serializeDebug( p.debugDescription),
14
+ "description": p.description,
15
+ "displayName": p.displayName,
16
+ "displayPrice": p.displayPrice,
17
+ "id": p.id,
18
+ "isFamilyShareable": p.isFamilyShareable,
19
+ "jsonRepresentation": serializeDebug(p.jsonRepresentation),
20
+ "price": p.price,
21
+ "subscription": serialize(p.subscription),
22
+ "type": serialize(p.type)
23
+ ]
24
+ }
25
+
26
+ func serializeDebug (_ d: Data) -> String? {
27
+ #if DEBUG
28
+ return String( decoding: d, as: UTF8.self)
29
+ #else
30
+ return nil
31
+ #endif
32
+ }
33
+
34
+ func serializeDebug (_ s: String) -> String? {
35
+ #if DEBUG
36
+ return s
37
+ #else
38
+ return nil
39
+ #endif
40
+ }
41
+
42
+ func serialize(_ e: Error?) -> [String: Any?]? {
43
+ guard let e = e else {return nil}
44
+ return ["localizedDescription": e.localizedDescription]
45
+ }
46
+ @available(iOS 15.0, *)
47
+ func serialize(_ si: Product.SubscriptionInfo?) -> [String: Any?]? {
48
+ guard let si = si else {return nil}
49
+ return [
50
+ "introductoryOffer": serialize(si.introductoryOffer),
51
+ "promotionalOffers": si.promotionalOffers.map {(offer: Product.SubscriptionOffer) in serialize(offer)},
52
+ "subscriptionGroupID": si.subscriptionGroupID,
53
+ "subscriptionPeriod": si.subscriptionPeriod
54
+ ]
55
+ }
56
+ @available(iOS 15.0, *)
57
+ func serialize(_ so: Product.SubscriptionOffer?) -> [String: Any?]? {
58
+ guard let so = so else {return nil}
59
+ return [
60
+ "displayPrice": so.displayPrice,
61
+ "id": so.id,
62
+ "paymentMode": so.paymentMode,
63
+ "period": so.period,
64
+ "periodCount": so.periodCount,
65
+ "price": so.price,
66
+ "type": so.type
67
+ ]
68
+ }
69
+
70
+ @available(iOS 15.0, *)
71
+ func serialize(_ t: Transaction) -> [String: Any?] {
72
+ return ["appAccountToken": t.appAccountToken,
73
+ "appBundleID": t.appBundleID,
74
+ "debugDescription": serializeDebug(t.debugDescription),
75
+ "deviceVerification": t.deviceVerification,
76
+ "deviceVerificationNonce": t.deviceVerificationNonce,
77
+ "expirationDate": t.expirationDate,
78
+ "id": t.id,
79
+ "isUpgraded": t.isUpgraded,
80
+ "jsonRepresentation": serializeDebug(t.jsonRepresentation),
81
+ "offerID": t.offerID,
82
+ "offerType": serialize(t.offerType),
83
+ "originalID": t.originalID,
84
+ "originalPurchaseDate": t.originalPurchaseDate,
85
+ "ownershipType": serialize(t.ownershipType),
86
+ "productID": t.productID,
87
+ "productType": serialize(t.productType),
88
+ "purchaseDate": t.purchaseDate,
89
+ "purchasedQuantity": t.purchasedQuantity,
90
+ "revocationDate": t.revocationDate,
91
+ "revocationReason": t.revocationReason,
92
+ "signedDate": t.signedDate,
93
+ "subscriptionGroupID": t.subscriptionGroupID,
94
+ "webOrderLineItemID": t.webOrderLineItemID
95
+ ]
96
+ }
97
+ @available(iOS 15.0, *)
98
+ func serialize(_ ot: Transaction.OfferType?) -> String? {
99
+ guard let ot = ot else {return nil}
100
+ switch ot {
101
+ case .promotional: return "promotional"
102
+ case .introductory: return "introductory"
103
+ case .code: return "code"
104
+ default:
105
+ return nil
106
+ }
107
+ }
108
+ @available(iOS 15.0, *)
109
+ func serialize(_ ot: Transaction.OwnershipType?) -> String? {
110
+ guard let ot = ot else {return nil}
111
+ switch ot {
112
+ case .purchased: return "purchased"
113
+ case .familyShared: return "familyShared"
114
+ default:
115
+ return nil
116
+ }
117
+ }
118
+ @available(iOS 15.0, *)
119
+ func serialize(_ pt: Product.ProductType?) -> String? {
120
+ guard let pt = pt else {return nil}
121
+ switch pt {
122
+ case .autoRenewable: return "autoRenewable"
123
+ case .consumable: return "consumable"
124
+ case .nonConsumable: return "nonConsumable"
125
+ case .nonRenewable: return "nonRenewable"
126
+ default:
127
+ return nil
128
+ }
129
+ }
@@ -0,0 +1,40 @@
1
+ //
2
+ // IapTypes.swift
3
+ // RNIap
4
+ //
5
+ // Created by Andres Aguilar on 8/18/22.
6
+ //
7
+
8
+ import Foundation
9
+ import StoreKit
10
+
11
+ typealias RNIapIosPromise = (RCTPromiseResolveBlock, RCTPromiseRejectBlock)
12
+
13
+ @available(iOS 15.0, *)
14
+ struct ProductOrError {
15
+ let product: Product?
16
+ let error: Error?
17
+ }
18
+
19
+ public enum StoreError: Error {
20
+ case failedVerification
21
+ }
22
+
23
+ enum IapErrors: String, CaseIterable {
24
+ case E_UNKNOWN = "E_UNKNOWN"
25
+ case E_SERVICE_ERROR = "E_SERVICE_ERROR"
26
+ case E_USER_CANCELLED = "E_USER_CANCELLED"
27
+ case E_USER_ERROR = "E_USER_ERROR"
28
+ case E_ITEM_UNAVAILABLE = "E_ITEM_UNAVAILABLE"
29
+ case E_REMOTE_ERROR = "E_REMOTE_ERROR"
30
+ case E_NETWORK_ERROR = "E_NETWORK_ERROR"
31
+ case E_RECEIPT_FAILED = "E_RECEIPT_FAILED"
32
+ case E_RECEIPT_FINISHED_FAILED = "E_RECEIPT_FINISHED_FAILED"
33
+ case E_DEVELOPER_ERROR = "E_DEVELOPER_ERROR"
34
+ case E_PURCHASE_ERROR = "E_PURCHASE_ERROR"
35
+ case E_SYNC_ERROR = "E_SYNC_ERROR"
36
+ case E_DEFERRED_PAYMENT = "E_DEFERRED_PAYMENT"
37
+ func asInt() -> Int {
38
+ return IapErrors.allCases.firstIndex(of: self)!
39
+ }
40
+ }
@@ -0,0 +1,30 @@
1
+ //
2
+ // IapUtils.swift
3
+ // RNIap
4
+ //
5
+ // Created by Andres Aguilar on 8/15/22.
6
+ //
7
+
8
+ import Foundation
9
+ import StoreKit
10
+
11
+ public func debugMessage(_ object: Any...) {
12
+ #if DEBUG
13
+ for item in object {
14
+ print("[react-native-iap] \(item)")
15
+ }
16
+ #endif
17
+ }
18
+ @available(iOS 15.0, *)
19
+ func checkVerified<T>(_ result: VerificationResult<T>) throws -> T {
20
+ // Check whether the JWS passes StoreKit verification.
21
+ switch result {
22
+ case .unverified:
23
+ // StoreKit parses the JWS, but it fails verification.
24
+ throw StoreError.failedVerification
25
+
26
+ case .verified(let safe):
27
+ // The result is verified. Return the unwrapped value.
28
+ return safe
29
+ }
30
+ }
@@ -1,16 +1,6 @@
1
1
  import React
2
2
  import StoreKit
3
3
 
4
- typealias RNIapIosPromise = (RCTPromiseResolveBlock, RCTPromiseRejectBlock)
5
-
6
- public func debugMessage(_ object: Any...) {
7
- #if DEBUG
8
- for item in object {
9
- print("[react-native-iap] \(item)")
10
- }
11
- #endif
12
- }
13
-
14
4
  // Based on https://stackoverflow.com/a/40135192/570612
15
5
  extension Date {
16
6
  var millisecondsSince1970: Int64 {
@@ -0,0 +1,66 @@
1
+ #import <StoreKit/StoreKit.h>
2
+
3
+ #import <React/RCTBridgeModule.h>
4
+ #ifdef __IPHONE_15_0
5
+ @interface RCT_EXTERN_MODULE (RNIapIosSk2, NSObject)
6
+
7
+ RCT_EXTERN_METHOD(initConnection:
8
+ (RCTPromiseResolveBlock)resolve
9
+ reject:(RCTPromiseRejectBlock)reject)
10
+
11
+ RCT_EXTERN_METHOD(endConnection:
12
+ (RCTPromiseResolveBlock)resolve
13
+ reject:(RCTPromiseRejectBlock)reject)
14
+
15
+ RCT_EXTERN_METHOD(getItems:
16
+ (NSArray*)skus
17
+ resolve:(RCTPromiseResolveBlock)resolve
18
+ reject:(RCTPromiseRejectBlock)reject)
19
+
20
+ RCT_EXTERN_METHOD(getAvailableItems:
21
+ (RCTPromiseResolveBlock)resolve
22
+ reject:(RCTPromiseRejectBlock)reject)
23
+
24
+ RCT_EXTERN_METHOD(buyProduct:
25
+ (NSString*)sku
26
+ andDangerouslyFinishTransactionAutomatically:(BOOL)andDangerouslyFinishTransactionAutomatically
27
+ appAccountToken:(NSString*)appAccountToken
28
+ quantity:(NSInteger)quantity
29
+ withOffer:(NSDictionary*)withOffer
30
+ resolve:(RCTPromiseResolveBlock)resolve
31
+ reject:(RCTPromiseRejectBlock)reject)
32
+
33
+ RCT_EXTERN_METHOD(isEligibleForIntroOffer:
34
+ (NSString*)groupID
35
+ resolve:(RCTPromiseResolveBlock)resolve
36
+ reject:(RCTPromiseRejectBlock)reject)
37
+
38
+ RCT_EXTERN_METHOD(currentEntitlement:
39
+ (NSString*)sku
40
+ resolve:(RCTPromiseResolveBlock)resolve
41
+ reject:(RCTPromiseRejectBlock)reject)
42
+
43
+ RCT_EXTERN_METHOD(latestTransaction:
44
+ (NSString*)sku
45
+ resolve:(RCTPromiseResolveBlock)resolve
46
+ reject:(RCTPromiseRejectBlock)reject)
47
+
48
+ RCT_EXTERN_METHOD(finishTransaction:
49
+ (NSString*)transactionIdentifier
50
+ resolve:(RCTPromiseResolveBlock)resolve
51
+ reject:(RCTPromiseRejectBlock)reject)
52
+
53
+ RCT_EXTERN_METHOD(pendingTransactions:
54
+ (RCTPromiseResolveBlock)resolve
55
+ reject:(RCTPromiseRejectBlock)reject)
56
+
57
+ RCT_EXTERN_METHOD(sync:
58
+ (RCTPromiseResolveBlock)resolve
59
+ reject:(RCTPromiseRejectBlock)reject)
60
+
61
+ RCT_EXTERN_METHOD(presentCodeRedemptionSheet:
62
+ (RCTPromiseResolveBlock)resolve
63
+ reject:(RCTPromiseRejectBlock)reject)
64
+
65
+ @end
66
+ #endif