Skip to content

Commit

Permalink
Use build-config to detect amazon, in order to match how we're doing …
Browse files Browse the repository at this point in the history
…it in the main app. This uses a build variant instead of detection.
  • Loading branch information
curiousdustin committed May 1, 2019
1 parent 69b3dec commit a0911a8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
33 changes: 16 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import { NativeModules, Platform, NativeEventEmitter } from 'react-native';
import BuildConfig from 'react-native-build-config';

const { RNIapIos, RNIapCombinedModule, RNIapAndroidModule, RNIapAmazonModule } = NativeModules;

Expand All @@ -23,7 +23,7 @@ export const prepare = () => {
},
android: async() => {
checkNativeAndroidAvailable();
let isAmazonDevice = await checkIsAmazonDevice();
let isAmazonDevice = checkIsAmazonDevice();
if(isAmazonDevice) {
Promise.resolve();
} else {
Expand All @@ -34,7 +34,7 @@ export const prepare = () => {
};

async function checkNativeAndroidAvailable() {
let isAmazonDevice = await checkIsAmazonDevice();
let isAmazonDevice = checkIsAmazonDevice();
if(isAmazonDevice) {
if (!RNIapAmazonModule) {
return Promise.reject(new Error('E_IAP_NOT_AVAILABLE', 'The payment setup is not available in this version of the app. Contact admin.'));
Expand Down Expand Up @@ -63,7 +63,7 @@ export const initConnection = () => Platform.select({
return RNIapIos.canMakePayments();
},
android: async() => {
let isAmazonDevice = await checkIsAmazonDevice();
let isAmazonDevice = checkIsAmazonDevice();
if(isAmazonDevice) {
Promise.resolve();
} else {
Expand All @@ -82,7 +82,7 @@ export const initConnection = () => Platform.select({
export const endConnection = () => Platform.select({
ios: async() => Promise.resolve(),
android: async() => {
let isAmazonDevice = await checkIsAmazonDevice();
let isAmazonDevice = checkIsAmazonDevice();
if(isAmazonDevice) {
Promise.resolve();
} else {
Expand All @@ -102,7 +102,7 @@ export const consumeAllItems = () => Platform.select({
ios: async() => Promise.resolve(),
android: async() => {
checkNativeAndroidAvailable();
let isAmazonDevice = await checkIsAmazonDevice();
let isAmazonDevice = checkIsAmazonDevice();
if(isAmazonDevice) {
Promise.resolve();
} else {
Expand All @@ -125,7 +125,7 @@ export const getProducts = (skus) => Platform.select({
.then((items) => items.filter((item) => item.productId));
},
android: async() => {
let isAmazonDevice = await checkIsAmazonDevice();
let isAmazonDevice = checkIsAmazonDevice();
if(isAmazonDevice) {
return RNIapAmazonModule.getProductData(skus);
} else {
Expand All @@ -150,7 +150,7 @@ export const getSubscriptions = (skus) => Platform.select({
},
android: async() => {
checkNativeAndroidAvailable();
let isAmazonDevice = await checkIsAmazonDevice();
let isAmazonDevice = checkIsAmazonDevice();
if(isAmazonDevice) {
return RNIapAmazonModule.getProductData(skus);
} else {
Expand All @@ -170,7 +170,7 @@ export const getPurchaseHistory = () => Platform.select({
},
android: async() => {
checkNativeAndroidAvailable();
let isAmazonDevice = await checkIsAmazonDevice();
let isAmazonDevice = checkIsAmazonDevice();
if(isAmazonDevice) {
return RNIapAmazonModule.getPurchaseUpdates(true);
} else {
Expand All @@ -192,7 +192,7 @@ export const getAvailablePurchases = () => Platform.select({
},
android: async() => {
checkNativeAndroidAvailable();
let isAmazonDevice = await checkIsAmazonDevice();
let isAmazonDevice = checkIsAmazonDevice();
if(isAmazonDevice) {
return RNIapAmazonModule.getPurchaseUpdates(true);
} else {
Expand All @@ -218,7 +218,7 @@ export const buySubscription = (sku, oldSku, prorationMode) => {
},
android: async() => {
checkNativeAndroidAvailable();
let isAmazonDevice = await checkIsAmazonDevice();
let isAmazonDevice = checkIsAmazonDevice();
if(isAmazonDevice) {
return RNIapAmazonModule.purchase(sku);
} else {
Expand All @@ -241,7 +241,7 @@ export const buyProduct = (sku) => Platform.select({
},
android: async() => {
checkNativeAndroidAvailable();
let isAmazonDevice = await checkIsAmazonDevice();
let isAmazonDevice = checkIsAmazonDevice();
if(isAmazonDevice) {
return RNIapAmazonModule.purchase(sku);
} else {
Expand Down Expand Up @@ -277,7 +277,7 @@ export const buyProductWithoutFinishTransaction = (sku) => Platform.select({
},
android: async() => {
checkNativeAndroidAvailable();
let isAmazonDevice = await checkIsAmazonDevice();
let isAmazonDevice = checkIsAmazonDevice();
if(isAmazonDevice) {
return RNIapAmazonModule.purchase(sku);
} else {
Expand Down Expand Up @@ -335,7 +335,7 @@ export const consumePurchase = (token) => Platform.select({
ios: async() => Promise.resolve(), // Consuming is a no-op on iOS, as soon as the product is purchased it is considered consumed.
android: async() => {
checkNativeAndroidAvailable();
let isAmazonDevice = await checkIsAmazonDevice();
let isAmazonDevice = checkIsAmazonDevice();
if(isAmazonDevice) {
Promise.resolve();
} else {
Expand Down Expand Up @@ -446,9 +446,8 @@ export const notifyFulfillmentAmazon = async(receiptId, fulfillmentResult) => {
}

// Function used to differentiate amazon / android devices
export const checkIsAmazonDevice = async() => {
let isAmazonDevice = await RNIapCombinedModule.isAmazonDevice();
return isAmazonDevice;
export const checkIsAmazonDevice = () => {
return BuildConfig.FLAVOR === 'amazon';
}

export const getUserData = async() => {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"react-native": ">=0.54"
},
"dependencies": {
"react-native-build-config": "github:ismaeldcom/react-native-build-config",
"dooboolab-welcome": "^1.1.0"
},
"devDependencies": {
Expand Down

0 comments on commit a0911a8

Please sign in to comment.