public static Dictionary <string, string> CaptureApiCall() { string captureId = ""; string uniqueReferenceId = GenerateRandomUniqueString(); // If the captureNow was not true then capture the amount for the Authorization ID if (!captureNow) { CaptureRequest captureRequestParameters = new CaptureRequest(); captureRequestParameters.WithAmazonAuthorizationId(amazonAuthorizationId) // The below code can be used to get the amount from the session. the amount was added into session in the SetPaymentDetails.aspx //.WithAmount(decimal.Parse(Session["amount"].ToString())) //For example we will be authorizing amount value of 1.99 .WithAmount((decimal)1.99) .WithCurrencyCode(Regions.currencyCode.USD) .WithCaptureReferenceId(uniqueReferenceId) .WithSellerCaptureNote("customNote"); CaptureResponse captureResponse = client.Capture(captureRequestParameters); apiResponse["captureResponse"] = captureResponse.GetJson(); if (!captureResponse.GetSuccess()) { // API CALL FAILED, get the Error code and Error Message string errorCode = captureResponse.GetErrorCode(); string errorMessage = captureResponse.GetErrorMessage(); } else { return(apiResponse); } } else { // The captureNow was true therefore just disply the Captured response details GetCaptureDetailsRequest getCaptureRequestParameters = new GetCaptureDetailsRequest(); foreach (string id in amazonCaptureIdList) { // Here there can be multiple Capture ID's. For example purposes we are considering a single Capture ID. captureId = id; } getCaptureRequestParameters.WithAmazonCaptureId(captureId); CaptureResponse getCaptureDetailsResponse = client.GetCaptureDetails(getCaptureRequestParameters); apiResponse["captureResponse"] = getCaptureDetailsResponse.GetJson(); if (getCaptureDetailsResponse.GetSuccess()) { return(apiResponse); } } return(apiResponse); }
public void CaptureApiCall() { string captureId = ""; string uniqueReferenceId = GenerateRandomUniqueString(); // If the capture has not happened on the previous Authorize API call then capture the amount. if (!captureNow) { CaptureRequest captureRequestParameters = new CaptureRequest(); captureRequestParameters.WithAmazonAuthorizationId(amazonAuthorizationId) .WithAmount(decimal.Parse(Session["amount"].ToString())) .WithCurrencyCode(Regions.currencyCode.USD) .WithCaptureReferenceId(uniqueReferenceId) .WithSellerCaptureNote("customNote"); CaptureResponse captureResponse = client.Capture(captureRequestParameters); // Capture was not a success Get the Error code and the Error message if (!captureResponse.GetSuccess()) { string errorCode = captureResponse.GetErrorCode(); string errorMessage = captureResponse.GetErrorMessage(); capture.InnerHtml = "Capture API call Failed" + Environment.NewLine + captureResponse.GetJson(); } else { // In this example the below is to simply display the output capture.InnerHtml = captureResponse.GetJson(); } } else { // In this case the capture had already happened . running the GetCaptureDetails API call to get the output of the capture. GetCaptureDetailsRequest getCaptureRequestParameters = new GetCaptureDetailsRequest(); foreach (string id in amazonCaptureIdList) { captureId = id; } getCaptureRequestParameters.WithAmazonCaptureId(captureId); CaptureResponse getCaptureDetailsResponse = client.GetCaptureDetails(getCaptureRequestParameters); if (getCaptureDetailsResponse.GetSuccess()) { capture.InnerHtml = getCaptureDetailsResponse.GetJson(); } } }