Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Restore Product Option #36

Open
Jerland2 opened this issue Mar 31, 2019 · 3 comments
Open

Restore Product Option #36

Jerland2 opened this issue Mar 31, 2019 · 3 comments

Comments

@Jerland2
Copy link

Describe the bug
Whenever I use the current restore Product option it succeeds even when a user has not purchased the in app purchase

To Reproduce
Steps to reproduce the behavior:

  1. Implement IAPS in App Store Connect
  2. Call In App Purchase.Restore
  3. Call succeeds even if user has not purchased the product

Expected behavior
A user should be prompted to sign in to their iCloud account and it should fail if they have not purchased the product before

@Jerland2
Copy link
Author

Jerland2 commented Mar 31, 2019

The solution is to modify this block of code

public func restore(handler: ((_ result: InAppPurchase.Result<Void>) -> Void)?) {
        paymentProvider.restoreCompletedTransactions { (_, error) in
            if let error = error {
                handler?(.failure(error))
                return
            }
            handler?(.success(()))
        }
    }

and change it to:

    public func restore(handler: ((_ result: InAppPurchase.Result<Void>) -> Void)?) {
        paymentProvider.restoreCompletedTransactions { (queue, error) in
            if let error = error {
                handler?(.failure(error))
                return
            }
            
            if queue.transactions.isEmpty {
                let emptyProductsError = Error(error: Error.emptyProducts)
                handler?(.failure(emptyProductsError))
                return
            } else {
                handler?(.success(()))
            }
        }
    }

@Jerland2
Copy link
Author

@jinSasaki please let me know if you see any issues with this fix as you are no doubt more familiar with the library. If not this should be updated in the repo

@jinSasaki
Copy link
Owner

It is not a bug.

I think that the restore feature should be always succeeded except StoreKit returned error, so this library returns success even if queue.transactions is empty.

However, I think that the developers should be able to handle the restored result.
InAppPurchase plans to add the product ids to result after the restore method called.

Please see also #26.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants