Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Platform, NativeModules } from 'react-native';
- import InAppBilling from 'react-native-billing'; // Android
- import iapReceiptValidator from 'iap-receipt-validator';
- const { InAppUtils } = NativeModules; // iOS
- const PRODUCT_ID = Platform.select({
- ios: '',
- android: ''
- });
- export const isSubscribed = async () => {
- let subscriber = false;
- if (Platform.OS === 'android') {
- await InAppBilling.close();
- try {
- await InAppBilling.open();
- await InAppBilling.loadOwnedPurchasesFromGoogle();
- subscriber = await InAppBilling.isSubscribed(PRODUCT_ID);
- } catch (err) {
- throw err;
- } finally {
- await InAppBilling.close();
- }
- } else if (Platform.OS === 'ios') {
- const password = '...'; // Shared Secret from iTunes connect
- const production = false; // use sandbox or production url for validation
- const validateReceipt = iapReceiptValidator(password, production);
- try {
- const receiptData = '...'; // transactionReceipt da compra do usuário
- const validationData = await validateReceipt(receiptData);
- if (validationData['latest_receipt_info'][0].expires_date > 'data de hoje') {
- subscriber = true;
- }
- } catch (err) {
- throw err;
- }
- }
- return subscriber;
- };
Add Comment
Please, Sign In to add comment