public HttpResponseMessage OnAuthorization() { AmexAuthRequest request = ParseRequest(); AmexAuthResponse response = new AmexAuthResponse(); CommerceContext context = CommerceContext.BuildSynchronousContext("Amex payment authorization request", request, response); context.Log.Verbose("Amex payment authorization payload : \r\n\"{0}\".", Request.Content.ReadAsStringAsync().Result); if (IsAuthorized(context)) { Stopwatch callTimer = Stopwatch.StartNew(); HttpStatusCode httpStatusCode = ProcessAmexAuthCall(context, callTimer, () => { AmexAuthorizationExecutor amexAuthorizationExecutor = new AmexAuthorizationExecutor(context); return(amexAuthorizationExecutor.Execute()); }); if (httpStatusCode != HttpStatusCode.OK) { response.ResponseCode = AmexAuthResponseCode.AmexAuthInternalError; context.Log.Warning("Amex payment authorization processing error. Request : {0} ", request.ToString()); } HttpResponseMessage message = new HttpResponseMessage(HttpStatusCode.OK) { Content = new ObjectContent <AmexAuthResponse>(response, new XmlMediaTypeFormatter()) }; return(message); } return(new HttpResponseMessage(HttpStatusCode.Unauthorized)); }
/// <summary> /// Construct response for Amex Auth Calls. /// </summary> public void BuildAuthorizationResponse() { AmexAuthResponse response = (AmexAuthResponse)Context[Key.Response]; ResultCode resultCode = (ResultCode)Context[Key.ResultCode]; switch (resultCode) { case ResultCode.Success: case ResultCode.Created: case ResultCode.DuplicateTransaction: response.ResponseCode = AmexAuthResponseCode.AmexAuthSuccess; break; case ResultCode.DealNotFound: response.ResponseCode = AmexAuthResponseCode.AmexAuthDealNotFound; break; } }