Ejemplo n.º 1
0
        public ActionResult ShowHostedCheckout()
        {
            //  Logger.LogInformation("Payment controller HostedCheckout action");

            GatewayApiRequest gatewayApiRequest = new GatewayApiRequest(GatewayApiConfig);

            gatewayApiRequest.ApiOperation  = "CREATE_CHECKOUT_SESSION";
            gatewayApiRequest.OrderId       = IdUtils.generateSampleId();
            gatewayApiRequest.OrderCurrency = GatewayApiConfig.Currency;

            gatewayApiRequest.buildSessionRequestUrl();
            gatewayApiRequest.buildPayload();

            gatewayApiRequest.ApiMethod = GatewayApiClient.POST;

            try
            {
                String response = GatewayApiClient.SendTransaction(gatewayApiRequest);

                //   Logger.LogInformation("HostedCheckout response -- " + response);

                CheckoutSessionModel checkoutSessionModel = CheckoutSessionModel.toCheckoutSessionModel(response);

                ViewBag.CheckoutJsUrl   = $@"{GatewayApiConfig.GatewayUrl}/checkout/version/{GatewayApiConfig.Version}/checkout.js";
                ViewBag.MerchantId      = GatewayApiConfig.MerchantId;
                ViewBag.OrderId         = gatewayApiRequest.OrderId;
                ViewBag.CheckoutSession = checkoutSessionModel;
                ViewBag.Currency        = GatewayApiConfig.Currency;
            }
            catch (Exception e)
            {
                //  Logger.LogError($"Hosted Checkout error : {JsonConvert.SerializeObject(e)}");

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

            return(View("HostedCheckout"));
        }
Ejemplo n.º 2
0
        public ActionResult tokenize(GatewayApiRequest gatewayApiRequest)
        {
//            Logger.LogInformation($"PaymentApiController ProcessHostedSession action gatewayApiRequest {JsonConvert.SerializeObject(gatewayApiRequest)}");

            //update session with order details
            GatewayApiRequest gatewayUpdateSessionRequest = new GatewayApiRequest(GatewayApiConfig);

            gatewayUpdateSessionRequest.ApiMethod = GatewayApiClient.PUT;

            //update the url appending session id
            gatewayUpdateSessionRequest.buildSessionRequestUrl(gatewayApiRequest.SessionId);

            gatewayUpdateSessionRequest.OrderId       = gatewayApiRequest.OrderId;
            gatewayUpdateSessionRequest.OrderCurrency = gatewayApiRequest.OrderCurrency;
            gatewayUpdateSessionRequest.OrderAmount   = gatewayApiRequest.OrderAmount;

            //build payload with order info
            gatewayUpdateSessionRequest.buildPayload();

            String response = GatewayApiClient.SendTransaction(gatewayUpdateSessionRequest);

            //   Logger.LogInformation($"Tokenize updated session {response}");

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

            //generate token
            GatewayApiRequest gatewayGenerateTokenRequest = new GatewayApiRequest(GatewayApiConfig);

            gatewayGenerateTokenRequest.SessionId = gatewayApiRequest.SessionId;
            gatewayGenerateTokenRequest.ApiMethod = GatewayApiClient.POST;
            gatewayGenerateTokenRequest.buildPayload();
            gatewayGenerateTokenRequest.buildTokenUrl();

            response = GatewayApiClient.SendTransaction(gatewayGenerateTokenRequest);

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

            //convert json to model
            TokenResponse tokenResponse = TokenResponse.ToTokenResponse(response);

            //payment with token
            GatewayApiRequest gatewayGeneratePaymentRequest = new GatewayApiRequest(GatewayApiConfig);

            gatewayGeneratePaymentRequest.ApiOperation = "PAY";
            gatewayGeneratePaymentRequest.ApiMethod    = GatewayApiClient.PUT;

            gatewayGeneratePaymentRequest.Token         = tokenResponse.Token;
            gatewayGeneratePaymentRequest.SessionId     = gatewayApiRequest.SessionId;
            gatewayGeneratePaymentRequest.OrderId       = gatewayApiRequest.OrderId;
            gatewayGeneratePaymentRequest.TransactionId = gatewayApiRequest.TransactionId;

            gatewayGeneratePaymentRequest.buildPayload();
            gatewayGeneratePaymentRequest.buildRequestUrl();

            response = GatewayApiClient.SendTransaction(gatewayGeneratePaymentRequest);

            buildViewData(gatewayGeneratePaymentRequest, response, 0);

            return(View(ViewList["ApiResponse"]));
        }
Ejemplo n.º 3
0
        public ActionResult masterpassResponse(String oauth_token, String oauth_verifier, String checkoutId,
                                               String checkout_resource_url, String mpstatus)
        {
            String UPDATE_SESSION_FROM_WALLET = "UPDATE_SESSION_FROM_WALLET";
            String WALLET_PROVIDER            = "MASTERPASS_ONLINE";

            //get session values
            String sessionId = getSessionValueAsString("sessionId");
            String amount    = getSessionValueAsString("amount");
            String currency  = getSessionValueAsString("currency");
            String orderId   = getSessionValueAsString("orderId");

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

            // UPDATE_SESSION_FROM_WALLET - Retrieve payment details from wallet using session ID
            GatewayApiRequest gatewayApiRequest = new GatewayApiRequest(GatewayApiConfig);

            gatewayApiRequest.ApiMethod        = GatewayApiClient.POST;
            gatewayApiRequest.ApiOperation     = UPDATE_SESSION_FROM_WALLET;
            gatewayApiRequest.MasterpassOnline = WALLET_PROVIDER;

            gatewayApiRequest.MasterpassOauthToken    = oauth_token;
            gatewayApiRequest.MasterpassOauthVerifier = oauth_verifier;
            gatewayApiRequest.MasterpassCheckoutUrl   = checkout_resource_url;

            gatewayApiRequest.buildSessionRequestUrl(sessionId);

            //build json
            gatewayApiRequest.buildPayload();

            string response = GatewayApiClient.SendTransaction(gatewayApiRequest);

            // Logger.LogInformation($"Masterpass update session : {response}");

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


            // Make a payment using the session
            // Construct API request
            GatewayApiRequest gatewayPayApiRequest = new GatewayApiRequest(GatewayApiConfig);

            gatewayPayApiRequest.ApiMethod    = GatewayApiClient.PUT;
            gatewayPayApiRequest.ApiOperation = "PAY";
            gatewayPayApiRequest.SessionId    = sessionId;

            //order info
            gatewayPayApiRequest.OrderAmount   = amount;
            gatewayPayApiRequest.OrderId       = orderId;
            gatewayPayApiRequest.OrderCurrency = currency;
            gatewayPayApiRequest.TransactionId = IdUtils.generateSampleId();

            //build payload
            gatewayPayApiRequest.buildPayload();

            gatewayPayApiRequest.buildRequestUrl();

            response = GatewayApiClient.SendTransaction(gatewayPayApiRequest);

            // Logger.LogInformation($"Masterpass PAY operation : {response}");

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


            //parse response to default transaction response model
            TransactionResponseModel model = null;

            try
            {
                model = TransactionResponseModel.fromMasterpassResponseToTransactionResponseModel(response);
            }
            catch (Exception e)
            {
                //  Logger.LogError($"MasterpassResponse error : {JsonConvert.SerializeObject(e)}");

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

            return(View(ViewList["Receipt"], model));
        }
Ejemplo n.º 4
0
        public ActionResult ProcessMasterpass(GatewayApiRequest gatewayApiRequest)
        {
            //   Logger.LogInformation($"PaymentApiController Process Master Pass action gatewayApiRequest {JsonConvert.SerializeObject(gatewayApiRequest)}");
            String response = null;

            // Create session to use with OPEN_WALLET operation
            GatewayApiRequest gatewaySessionRequest = new GatewayApiRequest(GatewayApiConfig);

            gatewaySessionRequest.buildSessionRequestUrl();
            gatewaySessionRequest.ApiMethod = GatewayApiClient.POST;
            response = GatewayApiClient.SendTransaction(gatewaySessionRequest);

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

            //convert json to model
            CheckoutSessionModel checkoutSessionModel = CheckoutSessionModel.toCheckoutSessionModel(response);

            //  Logger.LogInformation($"Masterpass hostedSession created {response}");

            // Call UPDATE_SESSION to add order information to session
            //update http verb
            GatewayApiRequest gatewayUpdateSessionRequest = new GatewayApiRequest(GatewayApiConfig);

            gatewayUpdateSessionRequest.ApiMethod = GatewayApiClient.PUT;

            //update the url appending session id
            gatewayUpdateSessionRequest.buildSessionRequestUrl(checkoutSessionModel.Id);

            gatewayUpdateSessionRequest.OrderId       = gatewayApiRequest.OrderId;
            gatewayUpdateSessionRequest.OrderCurrency = gatewayApiRequest.OrderCurrency;
            gatewayUpdateSessionRequest.OrderAmount   = gatewayApiRequest.OrderAmount;

            //build payload with order info
            gatewayUpdateSessionRequest.buildPayload();

            response = GatewayApiClient.SendTransaction(gatewayUpdateSessionRequest);

            //  Logger.LogInformation($"Masterpass updated session {response}");

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


            // Call OPEN_WALLET to retrieve Masterpass configuration
            //It will use session URL
            GatewayApiRequest gatewayOpenWalletRequest = new GatewayApiRequest(GatewayApiConfig);

            gatewayOpenWalletRequest.buildSessionRequestUrl(checkoutSessionModel.Id);
            gatewayOpenWalletRequest.ApiMethod = GatewayApiClient.POST;

            gatewayOpenWalletRequest.MasterpassOnline    = gatewayApiRequest.MasterpassOnline;
            gatewayOpenWalletRequest.MasterpassOriginUrl = gatewayApiRequest.MasterpassOriginUrl;

            gatewayOpenWalletRequest.OrderCurrency = gatewayApiRequest.OrderCurrency;
            gatewayOpenWalletRequest.OrderAmount   = gatewayApiRequest.OrderAmount;

            gatewayOpenWalletRequest.buildPayload();

            response = GatewayApiClient.SendTransaction(gatewayOpenWalletRequest);

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


            //parse response to model
            MasterpassWalletResponse masterpassWalletResponse = null;

            try
            {
                masterpassWalletResponse = MasterpassWalletResponse.toMasterpassWalletResponse(response);
            }
            catch (Exception e)
            {
                // Logger.LogError($"ProcessMasterpass error : {JsonConvert.SerializeObject(e)}");

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

            // Logger.LogInformation($"Masterpass wallet configuration {response}");

            // Save this value in HttpSession to retrieve after returning from issuer authentication form
            setSessionValue("sessionId", checkoutSessionModel.Id);
            setSessionValue("amount", gatewayApiRequest.OrderAmount);
            setSessionValue("currency", gatewayApiRequest.OrderCurrency);
            setSessionValue("orderId", gatewayApiRequest.OrderId);

            //set values for view usage
            ViewBag.requestToken       = masterpassWalletResponse.RequestToken;
            ViewBag.merchantCheckoutId = masterpassWalletResponse.MerchantCheckoutId;
            ViewBag.allowedCardTypes   = masterpassWalletResponse.AllowedCardTypes;

            return(View(ViewList["MasterpassButton"]));
        }
Ejemplo n.º 5
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));
        }