diff --git a/Sources/SwiftyStoreKit/PaymentQueueController.swift b/Sources/SwiftyStoreKit/PaymentQueueController.swift index 0d3ddab..98f3c7d 100644 --- a/Sources/SwiftyStoreKit/PaymentQueueController.swift +++ b/Sources/SwiftyStoreKit/PaymentQueueController.swift @@ -38,6 +38,7 @@ protocol TransactionController { public enum TransactionResult { case purchased(purchase: PurchaseDetails) case restored(purchase: Purchase) + case deferred(purchase: PurchaseDetails) case failed(error: SKError) } diff --git a/Sources/SwiftyStoreKit/PaymentsController.swift b/Sources/SwiftyStoreKit/PaymentsController.swift index b57c81d..f7bfe26 100644 --- a/Sources/SwiftyStoreKit/PaymentsController.swift +++ b/Sources/SwiftyStoreKit/PaymentsController.swift @@ -127,6 +127,15 @@ class PaymentsController: TransactionController { return true } + if transactionState == .deferred { + let purchase = PurchaseDetails(productId: transactionProductIdentifier, quantity: transaction.payment.quantity, product: payment.product, transaction: transaction, originalTransaction: transaction.original, needsFinishTransaction: !payment.atomically) + + payment.callback(.deferred(purchase: purchase)) + + payments.remove(at: paymentIndex) + return true + } + return false } diff --git a/Sources/SwiftyStoreKit/SwiftyStoreKit+Types.swift b/Sources/SwiftyStoreKit/SwiftyStoreKit+Types.swift index addf9b7..d49a27f 100644 --- a/Sources/SwiftyStoreKit/SwiftyStoreKit+Types.swift +++ b/Sources/SwiftyStoreKit/SwiftyStoreKit+Types.swift @@ -128,6 +128,7 @@ public struct RetrieveResults { /// Purchase result public enum PurchaseResult { case success(purchase: PurchaseDetails) + case deferred(purchase: PurchaseDetails) case error(error: SKError) } diff --git a/Sources/SwiftyStoreKit/SwiftyStoreKit.swift b/Sources/SwiftyStoreKit/SwiftyStoreKit.swift index f7e2ba6..8ce9093 100644 --- a/Sources/SwiftyStoreKit/SwiftyStoreKit.swift +++ b/Sources/SwiftyStoreKit/SwiftyStoreKit.swift @@ -99,6 +99,8 @@ public class SwiftyStoreKit { switch result { case .purchased(let purchase): return .success(purchase: purchase) + case .deferred(let purchase): + return .deferred(purchase: purchase) case .failed(let error): return .error(error: error) case .restored(let purchase): @@ -114,6 +116,9 @@ public class SwiftyStoreKit { case .purchased(let purchase): let error = storeInternalError(description: "Cannot purchase product \(purchase.productId) from restore purchases path") restoreFailedPurchases.append((error, purchase.productId)) + case .deferred(let purchase): + let error = storeInternalError(description: "Cannot purchase product \(purchase.productId) from restore purchases path") + restoreFailedPurchases.append((error, purchase.productId)) case .failed(let error): restoreFailedPurchases.append((error, nil)) case .restored(let purchase):