react-native-billing-sdk
Version:
Implementation of Android Billing Client v6.0
48 lines (47 loc) • 2.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _reactNative = require("react-native");
var _constants = require("./constants");
const {
BillingSdkEvent
} = _constants.BillingSdkAndroidConstants;
const BillingSdk = _reactNative.NativeModules.BillingSdk;
const eventEmitter = new _reactNative.NativeEventEmitter(_reactNative.NativeModules.BillingSdk);
const isAndroid = _reactNative.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] : _constants.BillingSdkAndroidConstants.SubscriptionReplacementMode.UNKNOWN_REPLACEMENT_MODE;
if (!isAndroid) {
return Promise.reject('Unsupported platform.');
}
return BillingSdk.launchBillingFlow(productId, offerToken, oldPurchaseToken, subscriptionReplacementMode);
})();
}
var _default = new BillingSdkAndroid();
exports.default = _default;
//# sourceMappingURL=BillingSdkAndroid.js.map