bizz84 / bizz84/SwiftyStoreKit

When/How can I trigger the completeTransactions callback within SwiftyStoreKit

Open
#432 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
6.7k
Forks
801
PR merge metrics
No merged PRs in 30d

Description

### Platform

- iOS

### In app purchase type

- Auto-Renewable Subscription

### Environment

- Sandbox

### Version
**0.14.1**

### Issue summary
I'm unable to get the `SwiftyStoreKit.completeTransactions` block to trigger when I make an atomic purchase. So within my view model, I have a wrapper function to purchase an auto-renewable subscription as you can see below in my function.

static func purchase(_ product: SKProduct) -> Promise {

let loftyLoadingViewContentModel = LoftyLoadingViewContentModel(title: "Purchasing".uppercased(), message: "We’re currently processing your\nrequest, for your subscription.")
UIApplication.topViewController()?.showLoadingView(.popOverScreen, loftyLoadingViewContentModel)

return Promise { seal in

SwiftyStoreKit.purchaseProduct(product) { purchaseResult in

switch purchaseResult {
case .success(let product):
if product.needsFinishTransaction {
SwiftyStoreKit.finishTransaction(product.transaction)
}
seal.fulfill()
log.info("Purchase Success: \(product.productId)")
case .error(let error):
UIApplication.topViewController()?.removeLoadingView()
seal.reject(error)
}
}
}
}

But this doesn't trigger the block within my appdelegate.

### What did you expect to happen

I expected the complete transactions block to execute.

SwiftyStoreKit.completeTransactions(atomically: true) { purchases in
for purchase in purchases {
switch purchase.transaction.transactionState {
case .purchased, .restored:
if purchase.needsFinishTransaction {
// TODO: Set flags here that the user has now purchased the product
SwiftyStoreKit.finishTransaction(purchase.transaction)
}
// Unlock content
case .failed, .purchasing, .deferred:
break // do nothing
}
}
}

### What happened instead

Nothing happened.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.