From 263537429f9b539b77b0f67d1ebebcc7137649bc Mon Sep 17 00:00:00 2001 From: Aristidis Zoutsos Date: Wed, 22 Sep 2021 20:06:42 +0300 Subject: [PATCH] FIX: MOBAPPS-3342 - Fixed ask to buy --- Sources/SwiftyStoreKit/PaymentQueueController.swift | 1 + Sources/SwiftyStoreKit/PaymentsController.swift | 9 +++++++++ Sources/SwiftyStoreKit/SwiftyStoreKit+Types.swift | 1 + Sources/SwiftyStoreKit/SwiftyStoreKit.swift | 5 +++++ 4 files changed, 16 insertions(+) diff --git a/Sources/SwiftyStoreKit/PaymentQueueController.swift b/Sources/SwiftyStoreKit/PaymentQueueController.swift index 0d3ddab2..98f3c7d3 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 b57c81d7..f7bfe267 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 addf9b78..d49a27fb 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 f7e2ba61..8ce90933 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):