|
@@ -32,6 +32,7 @@ protocol TransactionController {
|
|
/// - parameter paymentQueue: payment queue for finishing transactions
|
|
/// - parameter paymentQueue: payment queue for finishing transactions
|
|
/// - returns: array of unhandled transactions
|
|
/// - returns: array of unhandled transactions
|
|
func processTransactions(_ transactions: [SKPaymentTransaction], on paymentQueue: PaymentQueue) -> [SKPaymentTransaction]
|
|
func processTransactions(_ transactions: [SKPaymentTransaction], on paymentQueue: PaymentQueue) -> [SKPaymentTransaction]
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
public enum TransactionResult {
|
|
public enum TransactionResult {
|
|
@@ -58,11 +59,13 @@ public protocol PaymentQueue: class {
|
|
}
|
|
}
|
|
|
|
|
|
extension SKPaymentQueue: PaymentQueue {
|
|
extension SKPaymentQueue: PaymentQueue {
|
|
|
|
+
|
|
#if os(watchOS) && swift(<5.3)
|
|
#if os(watchOS) && swift(<5.3)
|
|
public func resume(_ downloads: [SKDownload]) {
|
|
public func resume(_ downloads: [SKDownload]) {
|
|
resumeDownloads(downloads)
|
|
resumeDownloads(downloads)
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
extension SKPaymentTransaction {
|
|
extension SKPaymentTransaction {
|
|
@@ -71,12 +74,12 @@ extension SKPaymentTransaction {
|
|
let transactionId = transactionIdentifier ?? "null"
|
|
let transactionId = transactionIdentifier ?? "null"
|
|
return "productId: \(payment.productIdentifier), transactionId: \(transactionId), state: \(transactionState), date: \(String(describing: transactionDate))"
|
|
return "productId: \(payment.productIdentifier), transactionId: \(transactionId), state: \(transactionState), date: \(String(describing: transactionDate))"
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
extension SKPaymentTransactionState: CustomDebugStringConvertible {
|
|
extension SKPaymentTransactionState: CustomDebugStringConvertible {
|
|
|
|
|
|
public var debugDescription: String {
|
|
public var debugDescription: String {
|
|
-
|
|
|
|
switch self {
|
|
switch self {
|
|
case .purchasing: return "purchasing"
|
|
case .purchasing: return "purchasing"
|
|
case .purchased: return "purchased"
|
|
case .purchased: return "purchased"
|
|
@@ -90,7 +93,7 @@ extension SKPaymentTransactionState: CustomDebugStringConvertible {
|
|
|
|
|
|
struct EntitlementRevocation {
|
|
struct EntitlementRevocation {
|
|
let callback: ([String]) -> Void
|
|
let callback: ([String]) -> Void
|
|
-
|
|
|
|
|
|
+
|
|
init(callback: @escaping ([String]) -> Void) {
|
|
init(callback: @escaping ([String]) -> Void) {
|
|
self.callback = callback
|
|
self.callback = callback
|
|
}
|
|
}
|
|
@@ -99,15 +102,11 @@ struct EntitlementRevocation {
|
|
class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
|
|
class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
|
|
|
|
|
|
private let paymentsController: PaymentsController
|
|
private let paymentsController: PaymentsController
|
|
-
|
|
|
|
private let restorePurchasesController: RestorePurchasesController
|
|
private let restorePurchasesController: RestorePurchasesController
|
|
-
|
|
|
|
private let completeTransactionsController: CompleteTransactionsController
|
|
private let completeTransactionsController: CompleteTransactionsController
|
|
-
|
|
|
|
unowned let paymentQueue: PaymentQueue
|
|
unowned let paymentQueue: PaymentQueue
|
|
-
|
|
|
|
private var entitlementRevocation: EntitlementRevocation?
|
|
private var entitlementRevocation: EntitlementRevocation?
|
|
-
|
|
|
|
|
|
+
|
|
deinit {
|
|
deinit {
|
|
paymentQueue.remove(self)
|
|
paymentQueue.remove(self)
|
|
}
|
|
}
|
|
@@ -160,10 +159,10 @@ class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
|
|
print("SwiftyStoreKit.onEntitlementRevocation() should only be called once when the app launches. Ignoring this call")
|
|
print("SwiftyStoreKit.onEntitlementRevocation() should only be called once when the app launches. Ignoring this call")
|
|
return
|
|
return
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
self.entitlementRevocation = revocation
|
|
self.entitlementRevocation = revocation
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
func restorePurchases(_ restorePurchases: RestorePurchases) {
|
|
func restorePurchases(_ restorePurchases: RestorePurchases) {
|
|
assertCompleteTransactionsWasCalled()
|
|
assertCompleteTransactionsWasCalled()
|
|
|
|
|
|
@@ -177,7 +176,6 @@ class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
|
|
}
|
|
}
|
|
|
|
|
|
func completeTransactions(_ completeTransactions: CompleteTransactions) {
|
|
func completeTransactions(_ completeTransactions: CompleteTransactions) {
|
|
-
|
|
|
|
guard completeTransactionsController.completeTransactions == nil else {
|
|
guard completeTransactionsController.completeTransactions == nil else {
|
|
print("SwiftyStoreKit.completeTransactions() should only be called once when the app launches. Ignoring this call")
|
|
print("SwiftyStoreKit.completeTransactions() should only be called once when the app launches. Ignoring this call")
|
|
return
|
|
return
|
|
@@ -197,6 +195,7 @@ class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
|
|
func start(_ downloads: [SKDownload]) {
|
|
func start(_ downloads: [SKDownload]) {
|
|
paymentQueue.start(downloads)
|
|
paymentQueue.start(downloads)
|
|
}
|
|
}
|
|
|
|
+
|
|
func pause(_ downloads: [SKDownload]) {
|
|
func pause(_ downloads: [SKDownload]) {
|
|
paymentQueue.pause(downloads)
|
|
paymentQueue.pause(downloads)
|
|
}
|
|
}
|
|
@@ -204,6 +203,7 @@ class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
|
|
func resume(_ downloads: [SKDownload]) {
|
|
func resume(_ downloads: [SKDownload]) {
|
|
paymentQueue.resume(downloads)
|
|
paymentQueue.resume(downloads)
|
|
}
|
|
}
|
|
|
|
+
|
|
func cancel(_ downloads: [SKDownload]) {
|
|
func cancel(_ downloads: [SKDownload]) {
|
|
paymentQueue.cancel(downloads)
|
|
paymentQueue.cancel(downloads)
|
|
}
|
|
}
|
|
@@ -211,9 +211,10 @@ class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
|
|
var shouldAddStorePaymentHandler: ShouldAddStorePaymentHandler?
|
|
var shouldAddStorePaymentHandler: ShouldAddStorePaymentHandler?
|
|
var updatedDownloadsHandler: UpdatedDownloadsHandler?
|
|
var updatedDownloadsHandler: UpdatedDownloadsHandler?
|
|
|
|
|
|
- // MARK: SKPaymentTransactionObserver
|
|
|
|
|
|
+
|
|
|
|
+ // MARK: - SKPaymentTransactionObserver
|
|
|
|
+
|
|
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
|
|
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
|
|
-
|
|
|
|
/*
|
|
/*
|
|
* Some notes about how requests are processed by SKPaymentQueue:
|
|
* Some notes about how requests are processed by SKPaymentQueue:
|
|
*
|
|
*
|
|
@@ -253,7 +254,6 @@ class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
|
|
}
|
|
}
|
|
|
|
|
|
func paymentQueue(_ queue: SKPaymentQueue, didRevokeEntitlementsForProductIdentifiers productIdentifiers: [String]) {
|
|
func paymentQueue(_ queue: SKPaymentQueue, didRevokeEntitlementsForProductIdentifiers productIdentifiers: [String]) {
|
|
-
|
|
|
|
self.entitlementRevocation?.callback(productIdentifiers)
|
|
self.entitlementRevocation?.callback(productIdentifiers)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -262,24 +262,20 @@ class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
|
|
}
|
|
}
|
|
|
|
|
|
func paymentQueue(_ queue: SKPaymentQueue, restoreCompletedTransactionsFailedWithError error: Error) {
|
|
func paymentQueue(_ queue: SKPaymentQueue, restoreCompletedTransactionsFailedWithError error: Error) {
|
|
-
|
|
|
|
restorePurchasesController.restoreCompletedTransactionsFailed(withError: error)
|
|
restorePurchasesController.restoreCompletedTransactionsFailed(withError: error)
|
|
}
|
|
}
|
|
|
|
|
|
func paymentQueueRestoreCompletedTransactionsFinished(_ queue: SKPaymentQueue) {
|
|
func paymentQueueRestoreCompletedTransactionsFinished(_ queue: SKPaymentQueue) {
|
|
-
|
|
|
|
restorePurchasesController.restoreCompletedTransactionsFinished()
|
|
restorePurchasesController.restoreCompletedTransactionsFinished()
|
|
}
|
|
}
|
|
|
|
|
|
func paymentQueue(_ queue: SKPaymentQueue, updatedDownloads downloads: [SKDownload]) {
|
|
func paymentQueue(_ queue: SKPaymentQueue, updatedDownloads downloads: [SKDownload]) {
|
|
-
|
|
|
|
updatedDownloadsHandler?(downloads)
|
|
updatedDownloadsHandler?(downloads)
|
|
}
|
|
}
|
|
|
|
|
|
- #if os(iOS) && !targetEnvironment(macCatalyst)
|
|
|
|
|
|
+ // #if os(iOS) && !targetEnvironment(macCatalyst)
|
|
func paymentQueue(_ queue: SKPaymentQueue, shouldAddStorePayment payment: SKPayment, for product: SKProduct) -> Bool {
|
|
func paymentQueue(_ queue: SKPaymentQueue, shouldAddStorePayment payment: SKPayment, for product: SKProduct) -> Bool {
|
|
-
|
|
|
|
return shouldAddStorePaymentHandler?(payment, product) ?? false
|
|
return shouldAddStorePaymentHandler?(payment, product) ?? false
|
|
}
|
|
}
|
|
- #endif
|
|
|
|
|
|
+ // #endif
|
|
}
|
|
}
|