Example #1
0
        public static PaymentRequestResult CreateRequestResult(string webServiceResponse, IHttpContextAccessor httpContextAccessor, MessagesOptions messagesOptions)
        {
            var result = XmlHelper.GetNodeValueFromXml(webServiceResponse, "return");

            var arrayResult = result.Split(',');

            var resCode = arrayResult[0];
            var refId   = arrayResult.Length > 1 ? arrayResult[1] : string.Empty;

            var isSucceed = resCode == OkResult;

            if (!isSucceed)
            {
                var message = resCode == DuplicateOrderNumberResult
                    ? messagesOptions.DuplicateTrackingNumber
                    : MellatGatewayResultTranslator.Translate(resCode, messagesOptions);

                return(PaymentRequestResult.Failed(message));
            }

            var transporter = new GatewayPost(
                httpContextAccessor,
                PaymentPageUrl,
                new Dictionary <string, string>
            {
                { "RefId", refId }
            });

            return(PaymentRequestResult.Succeed(transporter));
        }
Example #2
0
        public static PaymentRefundResult CreateRefundResult(string webServiceResponse, MessagesOptions messagesOptions)
        {
            var result = XmlHelper.GetNodeValueFromXml(webServiceResponse, "return");

            var isSuccess = result == OkResult;

            var message = MellatGatewayResultTranslator.Translate(result, messagesOptions);

            return(new PaymentRefundResult
            {
                IsSucceed = isSuccess,
                Message = message
            });
        }
Example #3
0
        public static PaymentVerifyResult CreateSettleResult(string webServiceResponse, MellatCallbackResult callbackResult, MessagesOptions messagesOptions)
        {
            var result = XmlHelper.GetNodeValueFromXml(webServiceResponse, "return");

            var isSuccess = result == OkResult || result == SettleSuccess;

            var message = isSuccess
                ? messagesOptions.PaymentSucceed
                : MellatGatewayResultTranslator.Translate(result, messagesOptions);

            return(new PaymentVerifyResult
            {
                IsSucceed = isSuccess,
                TransactionCode = callbackResult.SaleReferenceId,
                Message = message,
            });
        }
Example #4
0
        public static MellatVerifyResult CheckVerifyResult(string webServiceResponse, MellatCallbackResult callbackResult, MessagesOptions messagesOptions)
        {
            var serviceResult = XmlHelper.GetNodeValueFromXml(webServiceResponse, "return");

            var isSucceed = serviceResult == OkResult;

            PaymentVerifyResult verifyResult = null;

            if (!isSucceed)
            {
                var message = MellatGatewayResultTranslator.Translate(serviceResult, messagesOptions);

                verifyResult = PaymentVerifyResult.Failed(message);
            }

            return(new MellatVerifyResult
            {
                IsSucceed = isSucceed,
                Result = verifyResult
            });
        }
Example #5
0
        public static MellatCallbackResult CrateCallbackResult(HttpRequest httpRequest, MessagesOptions messagesOptions)
        {
            httpRequest.TryGetParam("ResCode", out var resCode);

            if (resCode.IsNullOrEmpty())
            {
                return(new MellatCallbackResult
                {
                    IsSucceed = false,
                    Result = PaymentVerifyResult.Failed(messagesOptions.InvalidDataReceivedFromGateway)
                });
            }

            //  Reference ID
            httpRequest.TryGetParam("RefId", out var refId);

            //  Transaction Code
            httpRequest.TryGetParam("SaleReferenceId", out var saleReferenceId);

            var isSucceed = resCode == OkResult;

            PaymentVerifyResult result = null;

            if (!isSucceed)
            {
                var message = MellatGatewayResultTranslator.Translate(resCode, messagesOptions);

                result = PaymentVerifyResult.Failed(message);
            }


            return(new MellatCallbackResult
            {
                IsSucceed = isSucceed,
                RefId = refId,
                SaleReferenceId = saleReferenceId,
                Result = result
            });
        }