Skip to content

When/How can I trigger the completeTransactions callback within SwiftyStoreKit #432

@tunds

Description

@tunds

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<Void> {
    
    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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions