chirag04 / react-native-in-app-utils

A react-native wrapper for handling in-app payments
MIT License
891 stars 185 forks source link

Any plan on supporting in-app purchase initiated from the App Store #102

Open rohitgoyal opened 7 years ago

rohitgoyal commented 7 years ago

As Apple released the new beta SDK with support of IAP from the App Store page itself. It would be really helpful to have that functionality with this library.

https://developer.apple.com/documentation/storekit/skpaymenttransactionobserver/2877502-paymentqueue

djw27 commented 7 years ago

+1

chirag04 commented 7 years ago

happy to accept a PR that has an event based api for this.

jeremyhicks commented 7 years ago

I dropped the method in to handle it. It does kick off the purchase process but obviously there is no callback to tell the RN app that the purchase was a success. I'm willing to work on it but I've never done anything with events and was looking into Bubble and Direct events but they need to be attached to an element.

- (BOOL)paymentQueue:(SKPaymentQueue *)queue
  shouldAddStorePayment:(SKPayment *)payment
  forProduct:(SKProduct *)product
{
  return YES;
}
superandrew213 commented 7 years ago

@chirag04 can you give an example of how you want the API to look like?

superandrew213 commented 7 years ago

@chirag04 @jeremyhicks @rohitgoyal please see PR https://github.com/chirag04/react-native-in-app-utils/pull/128.

Added PurchaseCompleted event that is triggered for in-app purchases initiated from the App Store and subscription renewals. It can be used like this:

import {
  NativeEventEmitter,
  NativeModules,
} from 'react-native';

const { InAppUtils } = NativeModules;

const InAppUtilsEmitter = new NativeEventEmitter(InAppUtils);

const listener = InAppUtilsEmitter.addListener('PurchaseCompleted', purchase => {
  if(purchase && purchase.productIdentifier) {
      Alert.alert('Purchase Successful', 'Your Transaction ID is ' + purchase.transactionIdentifier);
      //unlock store here.
   }
});

listener.remove();

I also added promise support and an index.js so that we can import InAppUtils directly:

import InAppUtils from 'react-native-in-app-utils'

instead of:

import {
  NativeModules,
} from 'react-native';

const { InAppUtils } = NativeModules;

You can then also easily add the listener like this:

InAppUtils.addListener('PurchaseCompleted', this._onPurchaseCompleted);

These should be all non-breaking changes.

It would be great if someone else could also test in-app purchases initiated from the App Store and subscription renewals.

To trigger an in-app purchase initiated from the App Store, open this on your device:

itms-services://?action=purchaseIntent&bundleId=com.example.app&productIdentifier=product_name

Replace bundleId and productIdentifier with your own.

jeremyhicks commented 7 years ago

@superandrew213 awesome, I will test this out tonight and report back

oguchy commented 6 years ago

Any update on this?

andreiciceu commented 6 years ago

can they be retrieved using restorePurchases?

ohtangza commented 4 years ago

This is very critical to get organic traffic. Any updates on it?