Exemplo n.º 1
0
        public JsonResult InitiateCheckout(CheckoutRequest request)
        {
            CheckoutResponse response = null;

            var randomKey    = Guid.NewGuid().ToString("N");
            var privateKey   = ConfigurationManager.AppSettings["AppTestSecretKey"];
            var paymenttoken = "";
            var checkouturl  = "";
            var errorMsg     = "";

            //validations
            if (!request.type.Equals("sale"))
            {
                errorMsg = "Bad Request. Invalid Transaction Type.";
                response = DoCheckoutResponse(randomKey, privateKey, paymenttoken, checkouturl, "100", errorMsg);
                return(Json(response));
            }
            if (request.signature != Md5Helper.GetMd5Hash(request.randomkey + privateKey + request.orderid + request.invoice + request.amounttotal))
            {
                errorMsg = "Bad Request. Invalid Signature.";
                response = DoCheckoutResponse(randomKey, privateKey, paymenttoken, checkouturl, "100", errorMsg);
                return(Json(response));
            }

            //authentication
            GatewayToken token = null;

            try
            {
                token = _gatewayAuthenticationService.GetGatewayToken(request.username, request.password);
            }
            catch (Exception ex)
            {
                errorMsg = "Gateway authentication transaction failed. " + ex.Message;
                response = DoCheckoutResponse(randomKey, privateKey, paymenttoken, checkouturl, "101", errorMsg);
                return(Json(response));
            }

            if (token == null)
            {
                errorMsg = "Gateway authentication transaction failed.";
                response = DoCheckoutResponse(randomKey, privateKey, paymenttoken, checkouturl, "101", errorMsg);
                return(Json(response));
            }

            //checkout
            GatewayCheckoutResponse gatewayCheckoutResponse = null;

            try
            {
                gatewayCheckoutResponse = _gatewayChekoutService.InitiateGatewayChechout(request, token);
            }
            catch (Exception ex)
            {
                errorMsg = "Gateway checkout transaction failed. " + ex.Message;
                response = DoCheckoutResponse(randomKey, privateKey, paymenttoken, checkouturl, "102", errorMsg);
                return(Json(response));
            }

            if (gatewayCheckoutResponse == null)
            {
                errorMsg = "Gateway checkout transaction failed.";
                response = DoCheckoutResponse(randomKey, privateKey, paymenttoken, checkouturl, "102", errorMsg);
                return(Json(response));
            }

            checkouturl = gatewayCheckoutResponse.checkout_url;
            response    = DoCheckoutResponse(randomKey, privateKey, paymenttoken, checkouturl, "", "");
            return(Json(response));
        }
Exemplo n.º 2
0
        public JsonResult InitiateRefund(RefundRequest request)
        {
            RefundResponse response = null;

            var privateKey = ConfigurationManager.AppSettings["AppTestSecretKey"];
            var randomKey  = Guid.NewGuid().ToString("N");
            var errorMsg   = "";

            //validations
            if (!request.type.Equals("void"))
            {
                errorMsg = "Bad Request. Invalid Transaction Type.";
                response = doRefundResponse(0, request, privateKey, randomKey, "", errorMsg, "100");
                return(Json(response));
            }
            if (request.signature != Md5Helper.GetMd5Hash(request.randomkey + privateKey + request.orderid + request.invoice + request.transactionid))
            {
                errorMsg = "Bad Request. Invalid Signature.";
                response = doRefundResponse(0, request, privateKey, randomKey, "", errorMsg, "100");
                return(Json(response));
            }

            //auth token
            GatewayToken token = null;

            try
            {
                token = _gatewayAuthenticationService.GetGatewayToken(request.username, request.password);
            }
            catch (Exception ex)
            {
                errorMsg = "Gateway authentication transaction failed. " + ex.Message;
                response = doRefundResponse(0, request, privateKey, randomKey, "", errorMsg, "101");
                return(Json(response));
            }

            if (token == null)
            {
                errorMsg = "Gateway authentication transaction failed.";
                response = doRefundResponse(0, request, privateKey, randomKey, "", errorMsg, "101");
                return(Json(response));
            }

            GatewayRefundResponse gatewayRefundResponse = null;

            //refund
            try
            {
                gatewayRefundResponse = _gatewayRefundService.InitiateGatewayRefund(request, token);
            }
            catch (Exception ex)
            {
                errorMsg = "Gateway refund transaction failed. " + ex.Message;
                response = doRefundResponse(0, request, privateKey, randomKey, "", errorMsg, "103");
                return(Json(response));
            }

            if (gatewayRefundResponse == null)
            {
                errorMsg = "Gateway refund transaction failed.";
                response = doRefundResponse(0, request, privateKey, randomKey, "", errorMsg, "103");
                return(Json(response));
            }

            response = doRefundResponse(1, request, privateKey, randomKey, gatewayRefundResponse.refund_id, "", "");
            return(Json(response));
        }