public GatewayRefundResponse InitiateGatewayRefund(RefundRequest request, GatewayToken token)
        {
            GatewayRefundResponse gatewayResponse = null;

            var baseUrl = ConfigurationManager.AppSettings["BaseURLWebAPIService"];

            var gatewayRefundRequest = _translatorService.GetGatewayRefundRequest(request);

            var response = _webApiClient.HTTPPostRequest(baseUrl, "orders/" + request.transactionid + "/refund", gatewayRefundRequest, token.token);

            if (response != null)
            {
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    using (var streamReader = new StreamReader(response.GetResponseStream()))
                    {
                        var responseText = streamReader.ReadToEnd();
                        gatewayResponse = JsonConvert.DeserializeObject <GatewayRefundResponse>(responseText);
                    }
                }
            }

            return(gatewayResponse);
        }
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));
        }