@@ -32,6 +32,7 @@ protocol TransactionController {
3232 /// - parameter paymentQueue: payment queue for finishing transactions
3333 /// - returns: array of unhandled transactions
3434 func processTransactions( _ transactions: [ SKPaymentTransaction ] , on paymentQueue: PaymentQueue ) -> [ SKPaymentTransaction ]
35+
3536}
3637
3738public enum TransactionResult {
@@ -58,11 +59,13 @@ public protocol PaymentQueue: class {
5859}
5960
6061extension SKPaymentQueue : PaymentQueue {
62+
6163 #if os(watchOS) && swift(<5.3)
6264 public func resume( _ downloads: [ SKDownload ] ) {
6365 resumeDownloads ( downloads)
6466 }
6567 #endif
68+
6669}
6770
6871extension SKPaymentTransaction {
@@ -71,12 +74,12 @@ extension SKPaymentTransaction {
7174 let transactionId = transactionIdentifier ?? " null "
7275 return " productId: \( payment. productIdentifier) , transactionId: \( transactionId) , state: \( transactionState) , date: \( String ( describing: transactionDate) ) "
7376 }
77+
7478}
7579
7680extension SKPaymentTransactionState : CustomDebugStringConvertible {
7781
7882 public var debugDescription : String {
79-
8083 switch self {
8184 case . purchasing: return " purchasing "
8285 case . purchased: return " purchased "
@@ -90,7 +93,7 @@ extension SKPaymentTransactionState: CustomDebugStringConvertible {
9093
9194struct EntitlementRevocation {
9295 let callback : ( [ String ] ) -> Void
93-
96+
9497 init ( callback: @escaping ( [ String ] ) -> Void ) {
9598 self . callback = callback
9699 }
@@ -99,15 +102,11 @@ struct EntitlementRevocation {
99102class PaymentQueueController : NSObject , SKPaymentTransactionObserver {
100103
101104 private let paymentsController : PaymentsController
102-
103105 private let restorePurchasesController : RestorePurchasesController
104-
105106 private let completeTransactionsController : CompleteTransactionsController
106-
107107 unowned let paymentQueue : PaymentQueue
108-
109108 private var entitlementRevocation : EntitlementRevocation ?
110-
109+
111110 deinit {
112111 paymentQueue. remove ( self )
113112 }
@@ -160,10 +159,10 @@ class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
160159 print ( " SwiftyStoreKit.onEntitlementRevocation() should only be called once when the app launches. Ignoring this call " )
161160 return
162161 }
163-
162+
164163 self . entitlementRevocation = revocation
165164 }
166-
165+
167166 func restorePurchases( _ restorePurchases: RestorePurchases ) {
168167 assertCompleteTransactionsWasCalled ( )
169168
@@ -177,7 +176,6 @@ class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
177176 }
178177
179178 func completeTransactions( _ completeTransactions: CompleteTransactions ) {
180-
181179 guard completeTransactionsController. completeTransactions == nil else {
182180 print ( " SwiftyStoreKit.completeTransactions() should only be called once when the app launches. Ignoring this call " )
183181 return
@@ -197,23 +195,26 @@ class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
197195 func start( _ downloads: [ SKDownload ] ) {
198196 paymentQueue. start ( downloads)
199197 }
198+
200199 func pause( _ downloads: [ SKDownload ] ) {
201200 paymentQueue. pause ( downloads)
202201 }
203202
204203 func resume( _ downloads: [ SKDownload ] ) {
205204 paymentQueue. resume ( downloads)
206205 }
206+
207207 func cancel( _ downloads: [ SKDownload ] ) {
208208 paymentQueue. cancel ( downloads)
209209 }
210210
211211 var shouldAddStorePaymentHandler : ShouldAddStorePaymentHandler ?
212212 var updatedDownloadsHandler : UpdatedDownloadsHandler ?
213213
214- // MARK: SKPaymentTransactionObserver
214+
215+ // MARK: - SKPaymentTransactionObserver
216+
215217 func paymentQueue( _ queue: SKPaymentQueue , updatedTransactions transactions: [ SKPaymentTransaction ] ) {
216-
217218 /*
218219 * Some notes about how requests are processed by SKPaymentQueue:
219220 *
@@ -253,7 +254,6 @@ class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
253254 }
254255
255256 func paymentQueue( _ queue: SKPaymentQueue , didRevokeEntitlementsForProductIdentifiers productIdentifiers: [ String ] ) {
256-
257257 self . entitlementRevocation? . callback ( productIdentifiers)
258258 }
259259
@@ -262,24 +262,20 @@ class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
262262 }
263263
264264 func paymentQueue( _ queue: SKPaymentQueue , restoreCompletedTransactionsFailedWithError error: Error ) {
265-
266265 restorePurchasesController. restoreCompletedTransactionsFailed ( withError: error)
267266 }
268267
269268 func paymentQueueRestoreCompletedTransactionsFinished( _ queue: SKPaymentQueue ) {
270-
271269 restorePurchasesController. restoreCompletedTransactionsFinished ( )
272270 }
273271
274272 func paymentQueue( _ queue: SKPaymentQueue , updatedDownloads downloads: [ SKDownload ] ) {
275-
276273 updatedDownloadsHandler ? ( downloads)
277274 }
278275
279- #if os(iOS) && !targetEnvironment(macCatalyst)
276+ // #if os(iOS) && !targetEnvironment(macCatalyst)
280277 func paymentQueue( _ queue: SKPaymentQueue , shouldAddStorePayment payment: SKPayment , for product: SKProduct ) -> Bool {
281-
282278 return shouldAddStorePaymentHandler ? ( payment, product) ?? false
283279 }
284- #endif
280+ // #endif
285281}
0 commit comments