React-native-iap: Add support for Amazon Appstore IAP

Created on 26 Feb 2020  ·  35Comments  ·  Source: dooboolab/react-native-iap

I think it would be nice to have support for Amazon Appstore IAP API.

🎯 feature 📢 announcement 🚶🏻 stale

Most helpful comment

I saw there was a work in the past to support it, but it appears to be outdated and can't be used with the current react-native-iap library:
https://github.com/dooboolab/react-native-iap/issues/370
So I started my own fork at https://github.com/nochkin/react-native-iap/tree/amazon-iap

It seems to be working in my own dev environment. But before I create a PR for it, it would be nice to get some real alpha/beta testers to review certain edge cases and get those polished properly as it's very possible I don't use all functionality in my own app.

I tried to stay within the original react-native-iap API as possible. There are couple methods I don't do yet (I can add it if someone has a way to test properly).

One of the breaking design decision in my fork is how to detect Google vs Amazon. I think detecting a device model/make is not a good approach because a user can install Google Play on a Kindle and get the app through Google (and vice versa when you can install Amazon Appstore on a Play-based device). We should get the IAP done through the correspondent API in this case.
My forks checks for installation source and acts accordingly. In dev environment, the installation source does not exist, so you can set a fallback to be able to test it properly.
I will document this if there is any interest in my fork to be merged into the upstream repo.

All 35 comments

I saw there was a work in the past to support it, but it appears to be outdated and can't be used with the current react-native-iap library:
https://github.com/dooboolab/react-native-iap/issues/370
So I started my own fork at https://github.com/nochkin/react-native-iap/tree/amazon-iap

It seems to be working in my own dev environment. But before I create a PR for it, it would be nice to get some real alpha/beta testers to review certain edge cases and get those polished properly as it's very possible I don't use all functionality in my own app.

I tried to stay within the original react-native-iap API as possible. There are couple methods I don't do yet (I can add it if someone has a way to test properly).

One of the breaking design decision in my fork is how to detect Google vs Amazon. I think detecting a device model/make is not a good approach because a user can install Google Play on a Kindle and get the app through Google (and vice versa when you can install Amazon Appstore on a Play-based device). We should get the IAP done through the correspondent API in this case.
My forks checks for installation source and acts accordingly. In dev environment, the installation source does not exist, so you can set a fallback to be able to test it properly.
I will document this if there is any interest in my fork to be merged into the upstream repo.

@nochkin Sounds really nice. I'd like to know the step to test out this. I don't have any amazon device. Can I still test it out? Hope you can bring up some document for those who have an interest in following up this integration.

I use a real Amazon device for testing purposes. I guess if you install Amazon Appstore on a non-Amazon device, that should do it.
I'll create some documentation later today to get started. I'm glad there is an interest for that.

Here is the guide on how to add Amazon IAP support to the existing app:
https://github.com/nochkin/react-native-iap/blob/amazon-iap/README_AMAZON.md
Let me know if something needs additional clarification.

FYI,
I pushed a few more changes to my fork last night, and also released my app to production using it.
Looks good so far.
I would be interested to get a feedback from others in case if there is any need for any additional functionality or use cases which are not covered in my own app.

@hyochan Is there any plan to add this to a release?

@curiousdustin,
You can use my fork to test and a feedback:
https://github.com/nochkin/react-native-iap/tree/amazon-iap
I'm sure your use-cases are different from mine, so you may provide additional feedback to get more changes to it.

@nochkin does your fork include support for amazon subscription IAPs?

@curiousdustin,
Even though it's been long time since implementation, but I believe so. I just haven't tested it with subscriptions.
You will still need to implement verification on the server side as I never validate anything on a client.

Amazon does not bring that much traffic, so my testing in real life is kinda slow. If you could contribute in this aspect, that would be nice.

Ok, I will likely be testing this out. I am currently using my own fork in production, but this was from before the major lifecycle related changes. I would really like to take advantage of all the great updates since then.

Nice. I'm still in the process of implementing subscriptions for my own app (internal app-related logic, not the rn-iap), so let me know if anything.

Amazon subscriptions API is kinda weird when being queried. For example, I have monthly and yearly subscription of the same service, but Amazon reports them identically. The only difference is the price, so I was thinking I'll figure out which one is which based on the price only.

Do you have a lot of subscribed and new subscription users?

Yes, the app I am using this for has hundreds of new subscriptions each month. Also any update that uses this will be thoroughly QA'd before release.

We also have monthly and yearly options. As you described, they are both under a single ID for Amazon. In our case we are confirming the subscription via the Amazon API, which gives us information about the period.

This sounds great. I'm glad my fork will have a proper testing in a different scenario.

I need to show the period of subscription in the UI for the user to select.
It's weird that Amazon Developer Console has those fields as required, but API does not have access to them.

This may have changed, but we found that even if you present 2 options to the used, once they initiate the purchase flow, Amazon will display the period options with the first one preselected. So, we had to implement a new UI for amazon, where the user does not actually select the period, until they are in the Amazon purchase flow UI.

Interesting idea actually. My UI won't fit this model, but I may consider this option if I decide to change it. I may still get to use it anyway. Thanks.

@curiousdustin @nochkin
Hi, as i understood you did a lot for this issue, wow! I'm in the process of implementing subscriptions too. How do you know that the subscription has been updated? And do you need to update it on the server? How does it work with RVS, I mean amazon receipt doesn't have endDate of subscription, so, how to update specific subscription for user on the server. Would be nice to hear from you if you know something about all this things)

I have not actually started implementing this fork yet in my project. Will likely be doing that next month.

Sorry, I don't have much info on how the server side Amazon stuff works. A different person on my team handled the backend. I do know that currently we just hand off the product ID and the receipt ID to our server and it handles everything else as far as verifying and updating the subscription validity as needed.

@kostiantyn-solianyk
My own app currently implemented Google Play and App Store only, I did not do Amazon RVS for subscriptions yet.
I do regular in-app purchases verification for Amazon and that was easy enough to implement so I would assume subscriptions should be someway similar.

yea in test mode everything is ok with it, and with you fork actually too, working as needed(in the cases that I checked).

We are stuck on the issue updating the subscription because amazon receipt doesn't have endDate of subscription, and it's actually weird.

I'll see if I can re-prioritize my tasks so I can play with Amazon verifications on their subscriptions.
I assume you have the issue using their test server too, right?

@nochkin By the way, I noticed that methods getAvailablePurchases and getPurchaseHistory return errors. I think these 2 haven't implemented yet for amazon IAP in you fork?

You are right. My own app model does not use those.
I'll take a look. Thank you.

Similar to @kostiantyn-solianyk , I found that the following methods need to be implemented for Amazon:

RNIapAmazonModule.endConnection() called by RNIap.endConnection()

I think this just needs to resolve the promise. It also requires changes to index.ts, or it is never used.

RNIapAmazonModule.refreshItems() called by RNIap.consumeAllItemsAndroid()

My app does not use consumeAllItemsAndroid, so I have not looked into what needs to be done.

RNIapAmazonModule.getPurchaseHistoryByType() called by RNIap.getPurchaseHistory()

My app does not use getPurchaseHistory, so I have not looked into what needs to be done.

RNIapAmazonModule.getAvailableItemsByType() called by RNIap.getAvailablePurchases()

This is necessary for providing a _Restore Purchases_ flow in your app. I got this working, but what I nave feels a bit hacky. I will post the solution here if I get it cleaned up a bit.

Other than these, testing so far is going well. Thanks for this @nochkin !

@nochkin, Would you be able to describe how you are installing this fork in your app project?

When I do something like this:

"react-native-iap": "github:nochkin/react-native-iap.git#amazon-iap"

The module does not resolve because it is expecting the js built from typescript to be there, but the built version of the project does not exist on github. It only gets created for the module release package. In fact installing with npm and the line above, it doesn't even download the index.ts, because of the .npmignore file, I think.

Does this make sense?

Thanks a lot for the summary on the missing method implementations. I did not implement the "endConnection" because it was not needed, but I agree it needs to have the method for compatibility purposes.
I'll look into others. Sorry, it took some time, but things are getting cleared up now and I expect to check/implement it soon.

I installed locally, something like this:
"react-native-iap": "../react-native-iap"
While having the "react-native-iap" directory simply be a clone of my repo.

No worries!

Ok, yeah I figured that local file reference would work, but doesn't make the project very portable.

The workaround I am using right now to reference my own fork/branch is to define the dependency like this:

"react-native-iap": "github:curiousdustin/react-native-iap.git#curious-amazon-iap-ts"

And in my branch I have changed the main property in react-native-iap's package.json to index.ts instead of .js. I also removed the TypeScript related entries in .npmignore.

This works for now, I guess because my RN setup is automatically building TS based modules...

Another important piece that appears to be missing is error handling.

The Amazon implementation never runs any code to emit error events, such as this from the Google version:

sendEvent(reactContext, "purchase-error", error);

This means that the purchaseErrorListener will never be called.

Noted. Good point. Thanks.

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as "For Discussion" or "Good first issue" and I will leave it open. Thank you for your contributions.

Bump!

It would be great to have the amazon support in this plugin as well. I've been using the amazon's implementation made by @nochkin for auto-renewal subscriptions and the thing is quite reliable. It would be awesome to integrate this fork in the repo and have a larger base of contributors maintaining the implementation!

Is there going to be any news on this later on or is the idea going to be dropped?

I don't think it will be dropped. I believe the main stalling point is a few missing features (minor for my use-cases, but maybe major for someone's else). My own app is happy with the current state too.
Those remaining pieces of the puzzle are still on my radar and I started working on those. Unfortunately, the completion/testing takes longer than expected due to other priorities.

Yeah, I understand the situation, I'll be keeping an eye on this then!

Thanks for the reply and I hope you get a little extra time for it 🤣

I pushed a PR (#1134 ) based on your great work @nochkin @curiousdustin ! 👏
Tests done, working great on our side! We'll add the support of Amazon on react-native-iaphub when the PR will be merged.
It's functional but like @nochkin said there is still some improvements we can do in the future.

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as "For Discussion" or "Good first issue" and I will leave it open. Thank you for your contributions.

Resolved and now part of the 5.0.0 release:
https://github.com/dooboolab/react-native-iap/releases/tag/5.0.0

Was this page helpful?
0 / 5 - 0 ratings