public async Task <ActionResult> CheckoutPaymentsApi(decimal amount, string token) { var response = await PaymentsApiClient.ChargeCheckoutTransaction(amount, token); var content = await response.Content.ReadAsStringAsync(); // Return any error to display to the user. if (!response.IsSuccessStatusCode) { var errorMessage = TryGetErrorMessage(content); if (string.IsNullOrWhiteSpace(errorMessage)) { errorMessage = "The attempt to retrieve payment configurations from Payments API did not succeed and has produced an unexpected error."; } HttpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError; return(new JsonResult() { Data = new { Error = errorMessage } }); } return(new HttpStatusCodeResult(HttpStatusCode.NoContent)); }