Open rohitgoyal opened 7 years ago
+1
happy to accept a PR that has an event based api for this.
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;
}
@chirag04 can you give an example of how you want the API to look like?
@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.
@superandrew213 awesome, I will test this out tonight and report back
Any update on this?
can they be retrieved using restorePurchases
?
This is very critical to get organic traffic. Any updates on it?
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