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

Restore a purchased product, get SwiftyStoreKit.InternalErrorCode.PurchasedWhenRestoringPurchase #26

Closed
atjason opened this issue Apr 23, 2016 · 8 comments

Comments

@atjason
Copy link
Contributor

atjason commented Apr 23, 2016

In fact already purchased the products. Remove the local information and try to restore, but get this error: SwiftyStoreKit.InternalErrorCode.PurchasedWhenRestoringPurchase.

@atjason
Copy link
Contributor Author

atjason commented Apr 23, 2016

In fact I even comment out the related code and treat this case as restore succeed. But I'm not sure this way is safe or not. And it has multi IAPs, but can't return them at a time. Seems each of the IAP calls the handler of restore, which is also not what I want.

    private func processRestoreResults(results: [InAppProductPurchaseRequest.TransactionResult]) -> RestoreResults {
        var restoredProductIds: [String] = []
        var restoreFailedProducts: [(ErrorType, String?)] = []
        for result in results {
            switch result {
            case .Purchased(let productId):
                restoredProductIds.append(productId)
//                restoreFailedProducts.append((storeInternalError(code: InternalErrorCode.PurchasedWhenRestoringPurchase.rawValue, description: "Cannot purchase product \(productId) from restore purchases path"), productId))
            case .Failed(let error):
                restoreFailedProducts.append((error, nil))
            case .Restored(let productId):
                restoredProductIds.append(productId)
            }
        }
        return RestoreResults(restoredProductIds: restoredProductIds, restoreFailedProducts: restoreFailedProducts)
    }

@bizz84
Copy link
Owner

bizz84 commented Apr 23, 2016

This pull request should fix this problem:
#24

See my comments here:
#22

@atjason
Copy link
Contributor Author

atjason commented Apr 24, 2016

I'm afraid this issue was not fixed.

My code didn't change, just replace the SwiftyStoreKit by git clone -b hotfix/transactionQueue-mismatch-fix https://github.com/bizz84/SwiftyStoreKit.

This time when restore an account which ever purchased, when the handler is called, both restoredProductIds and restoreFailedProducts are empty. And the handler only be called once.

(lldb) e result
(iHosts.SwiftyStoreKit.RestoreResults) $R0 = {
  restoredProductIds = 0 values {}
  restoreFailedProducts = 0 values {}
}

@bizz84
Copy link
Owner

bizz84 commented Apr 24, 2016

Sorry I'm not sure I fully understand your answer. This is what is expected:

If the product was never purchased and you call SwiftyStoreKit.restorePurchases(), you should get:

results.restoredProductIds = [] (empty)
results.restoreFailedProducts = [] (empty)

If the product was previously purchased, you should get:

results.restoredProductIds = [ "your.product.IAP.id" ] (1 value)
results.restoreFailedProducts = [] (empty)

The new API will always return with a single callback, and an empty array in results.restoredProductIds if no purchases are found.
Can you confirm if this works with your code?

@atjason
Copy link
Contributor Author

atjason commented Apr 24, 2016

Seems there's some misunderstanding. In my sense, I should get code from git clone -b hotfix/transactionQueue-mismatch-fix https://github.com/bizz84/SwiftyStoreKit. The code in this branch doesn't have the new API you mentioned. So should I use the latest code in master?

In another side, I did read the latest code in master. Seems it changes a lot. To be honest, I'm not confident to use these codes in my app. So I plan to submit with the original version which I test with it for longer time. And then replace with latest one in next update of the app.

@bizz84
Copy link
Owner

bizz84 commented Apr 24, 2016

@atjason I have merged all my changes. Please do any further testing after pulling the latest code in master or use pod version 0.2.7. Also I have added a Changelog section in the README - hopefully this clarifies all the recent changes that I have made.

@atjason
Copy link
Contributor Author

atjason commented Apr 27, 2016

@bizz84 Sorry didn't reply in time. In these days I was really busy to submit my app to Mac App Store and some other things. Now the app review is passed, but I plan to manually release it on May 3rd.

I will merge the latest SwiftStoreKit and adjust my code in these days. But I'm afraid I can't really make sure it works before I really test with the app which is already in Mac App Store. Will update in time.

@atjason
Copy link
Contributor Author

atjason commented Apr 28, 2016

@bizz84 This issue itself could be closed as it's fixed. I test with v0.2.7 and found other issues, which I just create new issues. Please check.

To be honest, I feel lucky I didn't use this version for the app to submitted to Mac App Store, but use previous version. But still feel upset for the potential issue. Hope we can really make SwiftStoreKit better.

In another side, if you can reach the guys who also use SwiftStoreKit, maybe you can tell them the issue of the version before v0.2.7, and invite them to test with latest version of SwiftStoreKit, as you or me couldn't cover all the cases. And my app even hasn't release on Mac App Store, it means I also can't make sure there's issue or not in that production environment.

@atjason atjason closed this as completed Apr 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants