I am facing 'callout loop not allowed' issue while making a Apex REST webservice call from mobile app (Hybrid remote app developed using salesforce mobile SDK for iOS ) which in turn makes a callout to external webservice.
This use case is about making a call to Authorise.net for payment processing.
User->login->credit card details -> restful apex call - forceTk -> http callout to payment(within restful apex method)->update user with result
Here is the code
Authentication:
var forceTKClient;
cordova.require("salesforce/plugin/oauth").authenticate(functionSuccessCallBack, functionErrorCallBack);
function functionSuccessCallBack (creds) {
var apiVersion = "v28.0";
forceTKClient = new forcetk.Client(creds.clientId, creds.loginUrl, null, cordova.require("salesforce/plugin/oauth").forcetkRefresh);
forceTKClient.setSessionToken(creds.accessToken, apiVersion , creds.instanceUrl);
forceTKClient.setRefreshToken(creds.refreshToken);
forceTKClient.setUserAgentString(creds.userAgent);
}
REST webservice
/*************************************************************************
* HttpPost method
**************************************************************************/
@HttpPost
global static REST_ProcessOrder_V1.ProcessOrderResponse doPost
(REST_ProcessOrder_V1.ProcessOrderRequest OrderRequest) {
//http callout to payment gateway
//post call code to update database with transaction details
}
REST call from client side
forceTKClient.apexrest('/v1/orders/' ,
function(data, textStatus, jqXHR){
//process = data;
console.log("****Response Success : "+JSON.stringify(data));
scope.$apply(defered.resolve(data));
}
Thanks in advance for your help!