react-native-in-app-utils icon indicating copy to clipboard operation
react-native-in-app-utils copied to clipboard

Listen for purchase events + optional promise support + other updates

Open superandrew213 opened this issue 8 years ago • 51 comments
trafficstars

Updates:

  • [x] Listen for purchase events initiated from App Store and subscription renewals
  • [x] Support promises
  • [x] canMakePurchase returns error arg too now *
  • [x] Always return error object for errors *
  • [x] Added helpers shouldFinishTransactions, finishCurrentTransaction and clearCompletedTransactions. See readme for more info.
  • [ ] Call addTransactionObserver after 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 avatar Oct 10 '17 09:10 superandrew213

@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.

jeremyhicks avatar Oct 12 '17 04:10 jeremyhicks

awesome! i will find some time over the weekend for this.

chirag04 avatar Oct 12 '17 13:10 chirag04

@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 avatar Oct 16 '17 18:10 jeremyhicks

@jeremyhicks what is the error output?

superandrew213 avatar Oct 16 '17 23:10 superandrew213

@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.

jeremyhicks avatar Oct 17 '17 18:10 jeremyhicks

@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.

jeremyhicks avatar Nov 04 '17 22:11 jeremyhicks

@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 avatar Nov 05 '17 00:11 superandrew213

@superandrew213 sorry i haven't had a chance to look at it yet. i'm still planning to review and merge this soon.

chirag04 avatar Nov 05 '17 16:11 chirag04

@chirag04 sure no problem!

superandrew213 avatar Nov 06 '17 00:11 superandrew213

Hi! Any changes here?

merryejik avatar Nov 27 '17 15:11 merryejik

@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 avatar Nov 30 '17 16:11 merryejik

@merryejik what happens when you press the link? Does it open your app?

superandrew213 avatar Nov 30 '17 21:11 superandrew213

No...

merryejik avatar Dec 01 '17 05:12 merryejik

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

superandrew213 avatar Dec 01 '17 06:12 superandrew213

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?

merryejik avatar Dec 01 '17 09:12 merryejik

would love to see this merged

raduflp avatar Dec 29 '17 11:12 raduflp

Excited for this. Any new updates?

NipperInShorts avatar Jan 16 '18 18:01 NipperInShorts

@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 avatar Jan 19 '18 14:01 christophby

@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.
   }
});

superandrew213 avatar Jan 20 '18 23:01 superandrew213

@chirag04 any news on this?

superandrew213 avatar Jan 22 '18 01:01 superandrew213

hey @superandrew213, haven't had a chance to look at it. It would be nice if somebody here can review and test it.

chirag04 avatar Jan 22 '18 14:01 chirag04

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).

rodrigopk avatar Feb 13 '18 12:02 rodrigopk

@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.

rodrigopk avatar Feb 13 '18 15:02 rodrigopk

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.

Eyesonly88 avatar Feb 25 '18 22:02 Eyesonly88

I agree this PR should be split up if possible, so we can have the purchase events feature merged in.

adamski avatar Mar 08 '18 15:03 adamski

@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.

idris avatar Apr 18 '18 23:04 idris

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.

idris avatar Apr 23 '18 15:04 idris

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 avatar Sep 28 '18 13:09 clementinoux

@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.

superandrew213 avatar Sep 28 '18 14:09 superandrew213

How's this coming along? Do you need more test coverage or any other contributions?

jeremyhicks avatar Oct 26 '18 14:10 jeremyhicks