Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Communicate deferred transactions to the app #652

Merged
merged 1 commit into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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