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

Buggy ProductsInfoController #212

Closed
4 tasks done
gerchicov-bp opened this issue May 16, 2017 · 6 comments
Closed
4 tasks done

Buggy ProductsInfoController #212

gerchicov-bp opened this issue May 16, 2017 · 6 comments
Labels
area: purchase flows purchase processes, efficiency and failures status: code review need to review the code type: bug

Comments

@gerchicov-bp
Copy link

gerchicov-bp commented May 16, 2017

Platform

  • iOS

In app purchase type

  • Auto-Renewable Subscription

Environment

  • Sandbox
  • Production

Version

0.9.0 (but the same code is not fixed in 0.9.2)

Related issues

Report

Issue summary

1)request purchases
2)minimize app and change app store account to another one with different currency
3)return to app and request purchases again

What did you expect to happen

Products return currency from the second account

What happened instead

Products return currency from the first account. They are cached and the problem is with the whole ProductsInfoController:
`

guard products.count == productIds.count else {

        requestProducts(productIds, completion: completion)
        return
    }

1)products.count == productIds.countdoesn't mean that all the products are the same - you should compare them by id 2)even ifproducts.count == productIds.countthen the currencies could be different as in my case 3)I wrote that the whole class is buggy because onlyretrieveProductsInfo(...)` func in this class is public and other code is private so I can't even properly fix this code for my case.

So the fastest fix I see is to make everything inside ProductsInfoController public. The better fix is to allow force call requestProducts which is not called because of products.count == productIds.count statement

@bizz84 bizz84 added type: bug status: needs analysis community analysis is needed area: purchase flows purchase processes, efficiency and failures labels May 18, 2017
@numen31337
Copy link

The issue also appears if you change the price. There should be the way to refresh this data.

@bizz84
Copy link
Owner

bizz84 commented May 29, 2017

The problem lies in the fact that SwiftyStoreKit caches products internally to that product information for any given product is only retrieved once.

Based on this report, I believe the best solution is to remove the caching altogether, and leave clients to implement it if desired.

This way, each time a new purchase is requested, SwiftyStoreKit will fetch the updated SKProduct that matches the chosen productId.

For convenience, in addition to these methods:

class func retrieveProductsInfo(_ productIds: Set<String>, ...)
class func purchaseProduct(_ productId: String, ...)

a new method could be made available:

class func purchaseProduct(_ product: SKProduct, ...)

This is so that if the client has already pre-fetched a product with retrieveProductsInfo, it can use it to make the purchase, without requesting the product information again.

I should have this implemented and working soon.

@gerchicov-bp
Copy link
Author

@bizz84 wait. What about to store these methods and add something like the following:

class func retrieveProductsInfo(_ productIds: Set<String>, ..., forceUpdate: Bool)
{
  if forceUpdate {
    ...//clear cache
  }
  retrieveProductsInfo(...) //call to existing method
}

Or even a property which enables/disables caching.

@bizz84
Copy link
Owner

bizz84 commented May 29, 2017

I think removing the cache is more in line with the lightweight spirit of SwiftyStoreKit, so I'm more inclined to remove state rather than adding state.

class func purchaseProduct(_ product: SKProduct, ...)

Clients can use this new method if they wish to prevent any un-necessary network calls, or they can use the old API and things will still work.

bizz84 added a commit that referenced this issue May 29, 2017
Add new purchase product method based on SKProduct. (#212)
@bizz84 bizz84 added status: code review need to review the code and removed status: needs analysis community analysis is needed labels May 29, 2017
@bizz84
Copy link
Owner

bizz84 commented May 29, 2017

Resolved in release 0.10.2.

@bizz84 bizz84 closed this as completed May 29, 2017
@bb-git
Copy link

bb-git commented Jul 11, 2017

I liked the caching. It's sad you removed it for this weird use cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: purchase flows purchase processes, efficiency and failures status: code review need to review the code type: bug
Projects
None yet
Development

No branches or pull requests

4 participants