Last active
June 18, 2018 20:04
-
-
Save tiagoportaluppi/f78450af93f8f2e2d13a7e66c879f571 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment