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 Purchase - iOS #3

Closed
mad-anoop opened this issue Dec 6, 2017 · 14 comments
Closed

Restore Purchase - iOS #3

mad-anoop opened this issue Dec 6, 2017 · 14 comments

Comments

@mad-anoop
Copy link

Any updates on iOS restore purchase feature?

@JJMoon
Copy link
Contributor

JJMoon commented Dec 7, 2017

We wil update soon. Maybe before 2018.

@KjellConnelly
Copy link
Contributor

@JJMoon @dooboolab
Btw how do we restore purchases on Android? I know Google Play allows you to query for non consumable purchases, but then that leaves me with a few questions:

  1. Is the idea to query for IAPs when the app loads, and restore functionality on each app load (saving locally of course so the app can work offline as well)?
  2. Which function should I use? I see:
    refreshPurchaseItemsAndroid() getPurchasedItemsAndroid()
    Maybe an example is in order for the readme?
  3. Do these only work for Google Play? How about Amazon/others?

@hyochan
Copy link
Member

hyochan commented Dec 17, 2017

@KjellConnelly
Answering you questions~

  1. You need to query for IAPs at first. When you want to query items offline and you are sure that lists of items won't change~ you can save them in LocalStorage.
  2. Sorry for that. As we told in head of this repo, we are interested in making IAP the same behavior between IOS and ANDOIRD platform. Therefore we missed out that tutorial officially. getPurchasedItemsAndroid() is a method to get a list of items you purchased in your app. refreshPurchaseItemsAndroid() is a method to refresh that item so you can buy the same item again.
  3. We've only tested on Google Play. We've not tested on Amazon/others yet.

Hope my answer helps you.

Thank you.

@KjellConnelly
Copy link
Contributor

@dooboolab Thanks for the reply :) Could you help me understand a bit better how the process works for Android? I am coming from an iOS background, so I will use iOS terms to try to make sense of this.

Imagine the situation where I have two IAPs

  1. Premium Version ($3.99), non-consumable.
  2. 100 Coins ($0.99), consumable.

In iOS, I would first query for the product IDs, then call the buy function. This returns Promise once the buy function has completed (success or failure).

On iOS, I would do something with LocalStorage such as setting a saved object:

if (item.productId == 'com.website.100coins') {
    savedData = {
        coins: savedData.coins + 100,
        premium: savedData.premium
    }
} else if (item.productId == 'com.website.premium') {
    savedData = {
        coins: savedData.coins,
        premium: true
    }
}

And then I would have a Restore button, and when you tap it, the Restore function is called, which returns the non-consumable purchases that the user has made in the past using that iTunes account.


For Android, it looks like I query for the productIds just as on iOS. And when the purchase happens, I also save to LocalStorage. But if I remember correctly, I need to then tell Google Play that the consumable has been consumed (for the coins, and once I save to local storage).

But when it comes to the Restore Button, I'm a bit confused.

By your description, it looks like those two functions do the following:

getPurchasedItemsAndroid(): This will return probably an array of IAPs that this user has purchased using your app. This will include all consumable, and non-consumable purchases. In my case, where I have Coins and a Premium Version, I would just iterate through this array to check to see if the user has bought the Premium Version before when they tap the Restore Button, right? And if its there, then I just set savedData.premium = true?

refreshPurchasedItemsAndroid() I don't really understand what refreshing does in this case. Does it tell Google Play that all of the previously consumed purchases are still purchased, but not consumed anymore? Or does it refresh the app's list of purchased items from Google Play's servers in which case would mean that the user's device is saving some sort of data on its own when a purchase is made?

Finally, it seems like on iOS, you are required to have a Restore Button for non-consumables. But for Google Play, you CAN have a Restore button for non-consumables, but it would be best practice to just check using getPurchasedItemsAndroid every time the app is launched (if the user's local data is saying that they haven't purchased the premium version yet).

Sorry for the long essay. Just having trouble making sense of the IAP process on Android.

@hyochan
Copy link
Member

hyochan commented Dec 18, 2017

@KjellConnelly

Sorry that I've missed this. I've not implemented Sku.Type option to get consumable products in android since this was our above our topic as explained. Before you could only getPurchasedItems lists for non-consumable products only. I just fixed this to support for querying both consumable and non-consumable products.
--------------------------- screenshots below -----------------------------------

  1. In index.js
    screen1
  2. in RNIapModule.java
    screen2

--------------------------- screenshots done -----------------------------------

Also for refreshPurchasedItemsAndroid method, I've updated support for conusmable products. Screenshots are below

--------------------------- screenshots below -----------------------------------

  1. In index.js
    screen1
  2. in RNIapModule.java
    screen2

--------------------------- screenshots done -----------------------------------

I've just commited this update. Hope this helps your question.

Now you can call getPurchasedItemsAndroid(type: string) function to get non-consumable items or consumable items. If you want non-consumable items just put null or any string. If you want consumable items put 'SUBS' in it.

You can use refreshPurchasedItemsAndroid(type: string) function same as described above.

@KjellConnelly
Copy link
Contributor

@dooboolab

I’m a bit confused now - I thought .SUBS was for subscriptions (which is different than consumables and non-consumables)

@hyochan
Copy link
Member

hyochan commented Dec 18, 2017

@KjellConnelly

Yes! It was about items for subscriptions. OMG... I was confused too. Thanks again to point that out. Sorry that I was confused by busy work ..

It seems we've been missing some support for this senario. We didn't actually distinguish between consumable and non-consumable product in our library. Since you need this part, we will support for this near future. Thanks for sharing.

@KjellConnelly
Copy link
Contributor

@dooboolab If you have time, could you add Restore Purchase support for iOS? Will be needing it soon and was hoping this feature to be implemented by 2018. Thanks!

@JJMoon
Copy link
Contributor

JJMoon commented Jan 15, 2018

@KjellConnelly
Sorry for delay. I will implement that method soon. Happy new year.. !!

@JJMoon
Copy link
Contributor

JJMoon commented Jan 22, 2018

Restore function Implemented. NPM module will be updated soon. If you need it right now, just use it from GitHub. Version is 0.1.16. It was merged to master, so you can use it right away.
Closing this issue. Thank you for waiting..

@JJMoon JJMoon closed this as completed Jan 22, 2018
@KjellConnelly
Copy link
Contributor

Thank you!! I really appreciate it :)

@hyochan
Copy link
Member

hyochan commented Jan 23, 2018

@KjellConnelly
Checkout later version of @0.2.2 for update.
Thank you!

@ivan133
Copy link

ivan133 commented Jan 28, 2019

But how to use it?

@ivan133
Copy link

ivan133 commented Jan 29, 2019

I wanted to create a new issue, but since the SUBJ I'll just post it here (Restore Purchase on iOS)
I'm not sure how to restore the subscription on ios?
As far I need to press a button (like restore subscription) but do I need to call any RNIap functions?
Or should I just save the purchase to local storage and restore it?

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

No branches or pull requests

5 participants