예제 #1
0
        public ActionResult Process3dsAuthenticationResult()
        {
            String responseView = ViewList["ApiResponse"];

            //cons
            String AUTHORIZE          = "AUTHORIZE";
            String PROCESS_ACS_RESULT = "PROCESS_ACS_RESULT";

            //get secure / session information from session
            String secureId      = getSessionValueAsString("secureId");
            String sessionId     = getSessionValueAsString("sessionId");
            String amount        = getSessionValueAsString("amount");
            String currency      = getSessionValueAsString("currency");
            String orderId       = getSessionValueAsString("orderId");
            String transactionId = getSessionValueAsString("transactionId");

            //remove values from session
            removeSessionValue("secureId");
            removeSessionValue("sessionId");
            removeSessionValue("amount");
            removeSessionValue("currency");
            removeSessionValue("orderId");
            removeSessionValue("transactionId");

            // Retrieve Payment Authentication Response (PaRes) from request
            String paRes = this.Request.Form["PaRes"];

            //init aux variables
            String            response          = null;
            GatewayApiRequest gatewayApiRequest = null;


            // Process Access Control Server (ACS) result
            gatewayApiRequest = new GatewayApiRequest();

            gatewayApiRequest.GatewayApiConfig    = GatewayApiConfig;
            gatewayApiRequest.ApiMethod           = GatewayApiClient.POST;
            gatewayApiRequest.PaymentAuthResponse = paRes;
            gatewayApiRequest.SecureId            = secureId;
            gatewayApiRequest.ApiOperation        = PROCESS_ACS_RESULT;
            gatewayApiRequest.buildPayload();
            gatewayApiRequest.buildSecureIdRequestUrl();

            response = GatewayApiClient.SendTransaction(gatewayApiRequest);

            //validate transaction response
            if (JsonHelper.isErrorMessage(response))
            {
                return(View("Error", ErrorViewModel.toErrorViewModel(getRequestId(), response)));
            }

            //parse response to domain
            SecureIdEnrollmentResponseModel model = null;

            try
            {
                model = SecureIdEnrollmentResponseModel.toSecureIdEnrollmentResponseModel(Request, response);
                //  Logger.LogInformation($"SecureIdEnrollmentResponseModel {JsonConvert.SerializeObject(model)}");
            }
            catch (Exception e)
            {
                //  Logger.LogError($"Process3dsAuthenticationResult error : {JsonConvert.SerializeObject(e)}");

                return(View("Error", new ErrorViewModel
                {
                    RequestId = getRequestId(),
                    Cause = e.InnerException != null ? e.InnerException.StackTrace : e.StackTrace,
                    Message = e.Message
                }));
            }


            //create 'authorize' API request in case of SUCCESS response
            if (model.Status != null && "AUTHENTICATION_FAILED" != model.Status)
            {
                //build authorize request
                gatewayApiRequest = new GatewayApiRequest();
                gatewayApiRequest.GatewayApiConfig = GatewayApiConfig;
                gatewayApiRequest.ApiMethod        = GatewayApiClient.PUT;
                gatewayApiRequest.ApiOperation     = AUTHORIZE;

                gatewayApiRequest.SessionId     = sessionId;
                gatewayApiRequest.SecureId3D    = secureId;
                gatewayApiRequest.OrderCurrency = currency;
                gatewayApiRequest.OrderAmount   = amount;
                gatewayApiRequest.TransactionId = transactionId;
                gatewayApiRequest.OrderId       = orderId;

                gatewayApiRequest.buildPayload();
                gatewayApiRequest.buildRequestUrl();

                //call api
                response = GatewayApiClient.SendTransaction(gatewayApiRequest);

                //build response view
                this.buildViewData(gatewayApiRequest, response, 0);
            }
            else
            {
                //return error view
                return(View("Error", new ErrorViewModel
                {
                    RequestId = getRequestId(),
                    Cause = model.Status,
                    Message = "3DS Authentication failed."
                }));
            }

            return(View(responseView));
        }
예제 #2
0
        public ActionResult Check3dsEnrollment(GatewayApiRequest gatewayApiRequest)
        {
            //   Logger.LogInformation($"PaymentApiController Check3dsEnrollment action SessionId {JsonConvert.SerializeObject(gatewayApiRequest)} gatewayApiRequest.SessionId {gatewayApiRequest.SessionId}");

            gatewayApiRequest.GatewayApiConfig = GatewayApiConfig;

            // Retrieve session
            gatewayApiRequest.buildSessionRequestUrl();
            gatewayApiRequest.ApiMethod = GatewayApiClient.GET;

            //  Logger.LogInformation($"gatewayApiRequest {JsonConvert.SerializeObject(gatewayApiRequest)}");

            string response = GatewayApiClient.SendTransaction(gatewayApiRequest);

            //   Logger.LogInformation("Get session response -- " + response);

            //validate transaction response
            if (JsonHelper.isErrorMessage(response))
            {
                return(View("Error", ErrorViewModel.toErrorViewModel(getRequestId(), response)));
            }


            CheckoutSessionModel checkoutSessionModel = CheckoutSessionModel.toCheckoutSessionModel(response);

            //   Logger.LogInformation($@"checkoutSession.Id {checkoutSessionModel.Id} gatewayApiRequest.SessionId {gatewayApiRequest.SessionId}");

            string secureId = IdUtils.generateSampleId();

            gatewayApiRequest.SecureId = secureId;

            gatewayApiRequest.buildSecureIdRequestUrl();
            gatewayApiRequest.buildPayload();
            gatewayApiRequest.ApiMethod = GatewayApiClient.PUT;


            //add values in session to use it after processing response
            setSessionValue("secureId", secureId);
            setSessionValue("sessionId", checkoutSessionModel.Id);
            setSessionValue("amount", gatewayApiRequest.OrderAmount);
            setSessionValue("currency", gatewayApiRequest.OrderCurrency);
            setSessionValue("orderId", gatewayApiRequest.OrderId);
            setSessionValue("transactionId", gatewayApiRequest.TransactionId);

            response = GatewayApiClient.SendTransaction(gatewayApiRequest);

            //  Logger.LogInformation($"SecureId response {response}");

            //validate transaction response
            if (JsonHelper.isErrorMessage(response))
            {
                return(View("Error", ErrorViewModel.toErrorViewModel(getRequestId(), response)));
            }

            //parse response
            SecureIdEnrollmentResponseModel model = null;

            try
            {
                model = SecureIdEnrollmentResponseModel.toSecureIdEnrollmentResponseModel(Request, response);
            }
            catch (Exception e)
            {
                //  Logger.LogError($"Check3dsEnrollment error : {JsonConvert.SerializeObject(e)}");

                return(View("Error", new ErrorViewModel
                {
                    RequestId = getRequestId(),
                    Cause = e.InnerException != null ? e.InnerException.StackTrace : e.StackTrace,
                    Message = e.Message
                }));
            }


            //check process result
            //  Logger.LogInformation($"SecureIdEnrollmentResponseModel {JsonConvert.SerializeObject(model)}");

            if (model.Status != "CARD_ENROLLED")
            {
                //   Logger.LogError($"Check3dsEnrollment was unsuccessful, status {model.Status}");
                return(View("Error", new ErrorViewModel
                {
                    RequestId = getRequestId(),
                    Cause = model.Status,
                    Message = "Card not enrolled in 3DS."
                }));
            }

            return(View(ViewList["SecureIdPayerAuthenticationForm"], model));
        }