Skip to content

Commit

Permalink
macOS Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam-Spencer committed Jan 7, 2021
1 parent 3126871 commit cf82d21
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
34 changes: 15 additions & 19 deletions Sources/SwiftyStoreKit/PaymentQueueController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ protocol TransactionController {
/// - parameter paymentQueue: payment queue for finishing transactions
/// - returns: array of unhandled transactions
func processTransactions(_ transactions: [SKPaymentTransaction], on paymentQueue: PaymentQueue) -> [SKPaymentTransaction]

}

public enum TransactionResult {
Expand All @@ -58,11 +59,13 @@ public protocol PaymentQueue: class {
}

extension SKPaymentQueue: PaymentQueue {

#if os(watchOS) && swift(<5.3)
public func resume(_ downloads: [SKDownload]) {
resumeDownloads(downloads)
}
#endif

}

extension SKPaymentTransaction {
Expand All @@ -71,12 +74,12 @@ extension SKPaymentTransaction {
let transactionId = transactionIdentifier ?? "null"
return "productId: \(payment.productIdentifier), transactionId: \(transactionId), state: \(transactionState), date: \(String(describing: transactionDate))"
}

}

extension SKPaymentTransactionState: CustomDebugStringConvertible {

public var debugDescription: String {

switch self {
case .purchasing: return "purchasing"
case .purchased: return "purchased"
Expand All @@ -90,7 +93,7 @@ extension SKPaymentTransactionState: CustomDebugStringConvertible {

struct EntitlementRevocation {
let callback: ([String]) -> Void

init(callback: @escaping ([String]) -> Void) {
self.callback = callback
}
Expand All @@ -99,15 +102,11 @@ struct EntitlementRevocation {
class PaymentQueueController: NSObject, SKPaymentTransactionObserver {

private let paymentsController: PaymentsController

private let restorePurchasesController: RestorePurchasesController

private let completeTransactionsController: CompleteTransactionsController

unowned let paymentQueue: PaymentQueue

private var entitlementRevocation: EntitlementRevocation?

deinit {
paymentQueue.remove(self)
}
Expand Down Expand Up @@ -160,10 +159,10 @@ class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
print("SwiftyStoreKit.onEntitlementRevocation() should only be called once when the app launches. Ignoring this call")
return
}

self.entitlementRevocation = revocation
}

func restorePurchases(_ restorePurchases: RestorePurchases) {
assertCompleteTransactionsWasCalled()

Expand All @@ -177,7 +176,6 @@ class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
}

func completeTransactions(_ completeTransactions: CompleteTransactions) {

guard completeTransactionsController.completeTransactions == nil else {
print("SwiftyStoreKit.completeTransactions() should only be called once when the app launches. Ignoring this call")
return
Expand All @@ -197,23 +195,26 @@ class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
func start(_ downloads: [SKDownload]) {
paymentQueue.start(downloads)
}

func pause(_ downloads: [SKDownload]) {
paymentQueue.pause(downloads)
}

func resume(_ downloads: [SKDownload]) {
paymentQueue.resume(downloads)
}

func cancel(_ downloads: [SKDownload]) {
paymentQueue.cancel(downloads)
}

var shouldAddStorePaymentHandler: ShouldAddStorePaymentHandler?
var updatedDownloadsHandler: UpdatedDownloadsHandler?

// MARK: SKPaymentTransactionObserver

// MARK: - SKPaymentTransactionObserver

func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {

/*
* Some notes about how requests are processed by SKPaymentQueue:
*
Expand Down Expand Up @@ -253,7 +254,6 @@ class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
}

func paymentQueue(_ queue: SKPaymentQueue, didRevokeEntitlementsForProductIdentifiers productIdentifiers: [String]) {

self.entitlementRevocation?.callback(productIdentifiers)
}

Expand All @@ -262,24 +262,20 @@ class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
}

func paymentQueue(_ queue: SKPaymentQueue, restoreCompletedTransactionsFailedWithError error: Error) {

restorePurchasesController.restoreCompletedTransactionsFailed(withError: error)
}

func paymentQueueRestoreCompletedTransactionsFinished(_ queue: SKPaymentQueue) {

restorePurchasesController.restoreCompletedTransactionsFinished()
}

func paymentQueue(_ queue: SKPaymentQueue, updatedDownloads downloads: [SKDownload]) {

updatedDownloadsHandler?(downloads)
}

#if os(iOS) && !targetEnvironment(macCatalyst)
// #if os(iOS) && !targetEnvironment(macCatalyst)
func paymentQueue(_ queue: SKPaymentQueue, shouldAddStorePayment payment: SKPayment, for product: SKProduct) -> Bool {

return shouldAddStorePaymentHandler?(payment, product) ?? false
}
#endif
// #endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
// Copyright © 2017 musevisions. All rights reserved.
//

#if os(iOS)

import UIKit

class PaymentTransactionObserverFake: NSObject {

}

#endif

0 comments on commit cf82d21

Please sign in to comment.