react-native-iap 10.0.1 → 11.0.0-alpha.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/RNIap.podspec CHANGED
@@ -12,7 +12,7 @@ Pod::Spec.new do |s|
12
12
  s.license = package["license"]
13
13
  s.authors = package["author"]
14
14
 
15
- s.platforms = { :ios => "10.0" , :tvos => "10.0"}
15
+ s.platforms = { :ios => "15.0" , :tvos => "15.0"}
16
16
  s.source = { :git => "https://github.com/dooboolab/react-native-iap.git", :tag => "#{s.version}" }
17
17
 
18
18
  s.source_files = "ios/*.{h,m,mm,swift}"
@@ -0,0 +1,127 @@
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
+
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
+
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
+
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
+ // Transaction
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
+
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
+ func serialize(_ ot: Transaction.OwnershipType?) -> String? {
109
+ guard let ot = ot else {return nil}
110
+ switch ot {
111
+ case .purchased: return "purchased"
112
+ case .familyShared: return "familyShared"
113
+ default:
114
+ return nil
115
+ }
116
+ }
117
+ func serialize(_ pt: Product.ProductType?) -> String? {
118
+ guard let pt = pt else {return nil}
119
+ switch pt {
120
+ case .autoRenewable: return "autoRenewable"
121
+ case .consumable: return "consumable"
122
+ case .nonConsumable: return "nonConsumable"
123
+ case .nonRenewable: return "nonRenewable"
124
+ default:
125
+ return nil
126
+ }
127
+ }
@@ -0,0 +1,39 @@
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
+ struct ProductOrError {
14
+ let product: Product?
15
+ let error: Error?
16
+ }
17
+
18
+ public enum StoreError: Error {
19
+ case failedVerification
20
+ }
21
+
22
+ enum IapErrors: String, CaseIterable {
23
+ case E_UNKNOWN = "E_UNKNOWN"
24
+ case E_SERVICE_ERROR = "E_SERVICE_ERROR"
25
+ case E_USER_CANCELLED = "E_USER_CANCELLED"
26
+ case E_USER_ERROR = "E_USER_ERROR"
27
+ case E_ITEM_UNAVAILABLE = "E_ITEM_UNAVAILABLE"
28
+ case E_REMOTE_ERROR = "E_REMOTE_ERROR"
29
+ case E_NETWORK_ERROR = "E_NETWORK_ERROR"
30
+ case E_RECEIPT_FAILED = "E_RECEIPT_FAILED"
31
+ case E_RECEIPT_FINISHED_FAILED = "E_RECEIPT_FINISHED_FAILED"
32
+ case E_DEVELOPER_ERROR = "E_DEVELOPER_ERROR"
33
+ case E_PURCHASE_ERROR = "E_PURCHASE_ERROR"
34
+ case E_SYNC_ERROR = "E_SYNC_ERROR"
35
+ case E_DEFERRED_PAYMENT = "E_DEFERRED_PAYMENT"
36
+ func asInt() -> Int {
37
+ return IapErrors.allCases.firstIndex(of: self)!
38
+ }
39
+ }
@@ -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
+
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
+ }