UNPKG

react-native-billing-sdk

Version:
41 lines 2.05 kB
import { NativeEventEmitter, NativeModules, Platform } from 'react-native'; import { BillingSdkAndroidConstants } from './constants'; const { BillingSdkEvent } = BillingSdkAndroidConstants; const BillingSdk = NativeModules.BillingSdk; const eventEmitter = new NativeEventEmitter(NativeModules.BillingSdk); const isAndroid = Platform.OS === 'android'; class BillingSdkAndroid { ensurePlatform = () => { if (isAndroid) { return; } return () => Promise.reject('Unsupported platform.'); }; startConnection = this.ensurePlatform() ?? BillingSdk.startConnection; endConnection = this.ensurePlatform() ?? BillingSdk.endConnection; getConnectionState = this.ensurePlatform() ?? BillingSdk.getConnectionState; queryProductDetails = this.ensurePlatform() ?? BillingSdk.queryProductDetails; acknowledgePurchase = this.ensurePlatform() ?? BillingSdk.acknowledgePurchase; queryPurchaseHistory = this.ensurePlatform() ?? BillingSdk.queryPurchaseHistory; queryPurchases = this.ensurePlatform() ?? BillingSdk.queryPurchases; consume = this.ensurePlatform() ?? BillingSdk.consume; setPurchaseUpdatedListener = listener => { const eventListener = eventEmitter.addListener(BillingSdkEvent.PURCHASE_UPDATED, listener); return eventListener.remove; }; setBillingServiceDisconnectedListener = listener => { const eventListener = eventEmitter.addListener(BillingSdkEvent.BILLING_SERVICE_DISCONNECTED, listener); return eventListener.remove; }; launchBillingFlow = (() => async function (productId, offerToken, oldPurchaseToken) { let subscriptionReplacementMode = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : BillingSdkAndroidConstants.SubscriptionReplacementMode.UNKNOWN_REPLACEMENT_MODE; if (!isAndroid) { return Promise.reject('Unsupported platform.'); } return BillingSdk.launchBillingFlow(productId, offerToken, oldPurchaseToken, subscriptionReplacementMode); })(); } export default new BillingSdkAndroid(); //# sourceMappingURL=BillingSdkAndroid.js.map