From 7a2e9062026efa6233f51a0115860a5eca27317c Mon Sep 17 00:00:00 2001 From: Valery Vaskabovich Date: Tue, 12 Jul 2016 02:38:42 +0300 Subject: [PATCH] validate_purchase fix for SANDBOX requests (#2253) * Fixed routing for validate_purchase method * Fixed validate_purchase endpoint --- src/Routers/IAPValidationRouter.js | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/Routers/IAPValidationRouter.js b/src/Routers/IAPValidationRouter.js index 831915b797..b961853257 100644 --- a/src/Routers/IAPValidationRouter.js +++ b/src/Routers/IAPValidationRouter.js @@ -37,9 +37,6 @@ function validateWithAppStore(url, receipt) { return fulfill(); } // receipt is from test and should go to test - if (status == 21007) { - return validateWithAppStore(IAP_SANDBOX_URL); - } return reject(body); }); }); @@ -82,11 +79,30 @@ export class IAPValidationRouter extends PromiseRouter { if (process.env.NODE_ENV == "test" && req.body.bypassAppStoreValidation) { return getFileForProductIdentifier(productIdentifier, req); } + + function successCallback() { + return getFileForProductIdentifier(productIdentifier, req); + }; + + function errorCallback(error) { + return Promise.resolve({response: appStoreError(error.status) }); + } return validateWithAppStore(IAP_PRODUCTION_URL, receipt).then( () => { - return getFileForProductIdentifier(productIdentifier, req); + + return successCallback(); + }, (error) => { - return Promise.resolve({response: appStoreError(error.status) }); + if (error.status == 21007) { + return validateWithAppStore(IAP_SANDBOX_URL, receipt).then( () => { + return successCallback(); + }, (error) => { + return errorCallback(error); + } + ); + } + + return errorCallback(error); }); }