Skip to content

Commit

Permalink
validate_purchase fix for SANDBOX requests (#2253)
Browse files Browse the repository at this point in the history
* Fixed routing for validate_purchase method

* Fixed validate_purchase endpoint
  • Loading branch information
ValeryVa authored and flovilmart committed Jul 11, 2016
1 parent 9658d21 commit 7a2e906
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/Routers/IAPValidationRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Expand Down Expand Up @@ -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);
});
}

Expand Down

0 comments on commit 7a2e906

Please sign in to comment.