react-native-in-app-utils
react-native-in-app-utils copied to clipboard
Listen for purchase events + optional promise support + other updates
Updates:
- [x] Listen for purchase events initiated from App Store and subscription renewals
- [x] Support promises
- [x]
canMakePurchasereturns error arg too now * - [x] Always return error object for errors *
- [x] Added helpers
shouldFinishTransactions,finishCurrentTransactionandclearCompletedTransactions. See readme for more info. - [ ] Call
addTransactionObserverafter js code initialises *
* breaking change
To install and test:
npm i --save https://github.com/superandrew213/react-native-in-app-utils#listen-for-purchase-event
To trigger purchase initiated from App Store, open this link in safari. Replace bundleId and productIdentifier with your own.
itms-services://?action=purchaseIntent&bundleId=com.example.app&productIdentifier=product_name
@superandrew213 I tested on the device for In-App purchases using the itms link and it works great. Thanks for also setting up index.js that makes it easier to use. I'm actually submitting to the App Store tonight.
awesome! i will find some time over the weekend for this.
@superandrew213 and @chirag04 I discovered an issue. My app has a Keyboard Extension target that bundles and runs the RN app. The extension crashes with this updated code in place. I have more discovery to do but wanted to let you know. I do not use this package in the code running inside of the extension, that is not allowed anyway, but having it linked and available is causing it to crash.
@jeremyhicks what is the error output?
@superandrew213 I wasn't getting any in the console. I need to explore further. When opening the Keyboard Extension it would crash. Debugging that is not easy.
@superandrew213 @chirag04 I have found the source of the issue when this library is included in a project that gets bundled in an iOS extension. The libInAppUtils.a library still needs to be included even though the extension itself doesn't support IAP. I've updated my apps to use this branch and it is working good, no crashes.
@chirag04 will you have some time soon to take this in soon? I've had it in a production app for over 3 weeks now and have had no issues.
@superandrew213 sorry i haven't had a chance to look at it yet. i'm still planning to review and merge this soon.
@chirag04 sure no problem!
Hi! Any changes here?
@superandrew213 I started test your solution, but this link don't work for me itms-services://?action=purchaseIntent&bundleId=com.example.app&productIdentifier=product_name (with my bundleId and productIdentifier, for purchase testing).
I use your branch and subscribe on events as written in your readme.
@merryejik what happens when you press the link? Does it open your app?
No...
Hmm there must be something wrong with your bundleId.
Paste this in your safari browser on your phone and make sure you have the right bundleId. Just to trigger app to open productIdentifier doesn't matter as long as you have a value.
itms-services://?action=purchaseIntent&bundleId=com.example.app&productIdentifier=product_name
Safari wants to open this link in iTunes and opens nothing after that. I will investigate SKPaymentTransactionObserver more carefully. Maybe there is need to be some changes in Info.plist or in AppDelegate?
would love to see this merged
Excited for this. Any new updates?
@superandrew213 I always get the following error when I call addEventListener :
InAppUtils.addListener was called with 2 arguments but expects 1 arguments. If you haven't changed this method yourself, this usually means that your versions of the native code and JavaScript code are out of sync. Updating both should make this error go away.
I call it as mentioned in your README:
InAppUtils.addListener('PurchaseCompleted',` purchase => { console.log('PurchaseCompleted'); if (purchase && purchase.productIdentifier) { alert('Purchase Successful', 'Your Transaction ID is ' + purchase.transactionIdentifier); //unlock store here. } });
@christophby copy and paste this and try again:
InAppUtils.addListener('PurchaseCompleted', purchase => {
if(purchase && purchase.productIdentifier) {
Alert.alert('Purchase Successful', 'Your Transaction ID is ' + purchase.transactionIdentifier);
//unlock store here.
}
});
@chirag04 any news on this?
hey @superandrew213, haven't had a chance to look at it. It would be nice if somebody here can review and test it.
Looking forward to see this merged. @merryejik Had a similar problem as you, which was caused by trying to open the url using an old device (iPhone 5c, which cannot update the OS past version 10.3.3).
@superandrew213 @chirag04 I was trying to use those changes but ran into a problem when trying to add a listener with the following code:
InAppUtils.addListener('purchaseCompleted', purchase => {
if (purchase && purchase.productIdentifier) {
console.log(
`Purchase Successful, Your Transaction ID is ${purchase.transactionIdentifier}`,
);
}
});
The problem seems to be related to InAppUtilsEmitter. When it calls the calls the addListener method:
addListener(eventType: string, listener: Function, context: ?Object): EmitterSubscription {
if (Platform.OS === 'ios') {
invariant(nativeModule, 'Native module cannot be null.');
this._nativeModule = nativeModule;
}
return super.addListener(eventType, listener, context);
}
this._nativeModule is not defined and this throws an error.
I'm using react-native v0.47.2. The implementation of this method in NativeEventEmitter in a later version (v0.54.0-rc.2), but I could not test it on newer versions, so I cannot guarantee it can not be reproduced after this one.
Hey @chirag04 and @superandrew213 great work on this. I'm just wondering is it possible to just have the "Listen for purchase events" feature merged and split the remaining work into another PR? Thanks.
I agree this PR should be split up if possible, so we can have the purchase events feature merged in.
@superandrew213 this needs to piggy-back off of #135 and force the user to call finishTransaction.
Use case:
If the user purchases something from the appstore, we need to notify our back-end, and verify that it worked before calling finishTransaction.
I added a comment on #135 with how I think the API should work: https://github.com/chirag04/react-native-in-app-utils/pull/135#issuecomment-383614510
Happy to help implement if we think this is the right direction.
Hi everyone,
I read all the stuff. I'm not sure... Finally, is there a working way to listen in-app coming from the store ? If so, how to ? Does the branch will be merge soon?
Thanks a lot,
@clementinoux yes, but you have to use my fork.
npm i --save https://github.com/superandrew213/react-native-in-app-utils#listen-for-purchase-event
You can see how here: https://github.com/superandrew213/react-native-in-app-utils/tree/listen-for-purchase-event#listen-for-purchase-events
I use my fork in production and haven't had any issues.
How's this coming along? Do you need more test coverage or any other contributions?