Guest User

Untitled

a guest
Jun 20th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. import { Platform, NativeModules } from 'react-native';
  2. import InAppBilling from 'react-native-billing'; // Android
  3. import iapReceiptValidator from 'iap-receipt-validator';
  4.  
  5. const { InAppUtils } = NativeModules; // iOS
  6.  
  7. const PRODUCT_ID = Platform.select({
  8. ios: '',
  9. android: ''
  10. });
  11.  
  12. export const isSubscribed = async () => {
  13. let subscriber = false;
  14.  
  15. if (Platform.OS === 'android') {
  16. await InAppBilling.close();
  17. try {
  18. await InAppBilling.open();
  19. await InAppBilling.loadOwnedPurchasesFromGoogle();
  20. subscriber = await InAppBilling.isSubscribed(PRODUCT_ID);
  21. } catch (err) {
  22. throw err;
  23. } finally {
  24. await InAppBilling.close();
  25. }
  26. } else if (Platform.OS === 'ios') {
  27. const password = '...'; // Shared Secret from iTunes connect
  28. const production = false; // use sandbox or production url for validation
  29. const validateReceipt = iapReceiptValidator(password, production);
  30.  
  31. try {
  32. const receiptData = '...'; // transactionReceipt da compra do usuário
  33. const validationData = await validateReceipt(receiptData);
  34.  
  35. if (validationData['latest_receipt_info'][0].expires_date > 'data de hoje') {
  36. subscriber = true;
  37. }
  38. } catch (err) {
  39. throw err;
  40. }
  41. }
  42.  
  43. return subscriber;
  44. };
Add Comment
Please, Sign In to add comment