Skip to content

Commit

Permalink
Merge pull request #652 from azouts/master
Browse files Browse the repository at this point in the history
Communicate deferred transactions to the app
  • Loading branch information
Sam-Spencer authored Dec 6, 2021
2 parents 9a3dd91 + 2635374 commit b3f2601
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions Sources/SwiftyStoreKit/PaymentQueueController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
9 changes: 9 additions & 0 deletions Sources/SwiftyStoreKit/PaymentsController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions Sources/SwiftyStoreKit/SwiftyStoreKit+Types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public struct RetrieveResults {
/// Purchase result
public enum PurchaseResult {
case success(purchase: PurchaseDetails)
case deferred(purchase: PurchaseDetails)
case error(error: SKError)
}

Expand Down
5 changes: 5 additions & 0 deletions Sources/SwiftyStoreKit/SwiftyStoreKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down

0 comments on commit b3f2601

Please sign in to comment.