Beispiel #1
0
        public static PaymentRequestResult CreateRequestResult(
            string webServiceResponse,
            IHttpContextAccessor httpContextAccessor,
            MessagesOptions messagesOptions,
            GatewayAccount account)
        {
            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, account.Name));
            }

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

            return(PaymentRequestResult.Succeed(transporter, account.Name));
        }
Beispiel #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
            {
                Status = isSuccess ? PaymentRefundResultStatus.Succeed : PaymentRefundResultStatus.Failed,
                Message = message
            });
        }
Beispiel #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
            {
                Status = isSuccess ? PaymentVerifyResultStatus.Succeed : PaymentVerifyResultStatus.Failed,
                TransactionCode = callbackResult.SaleReferenceId,
                Message = message,
            });
        }
Beispiel #4
0
        public static PaymentRequestResult CreateRequestResult(
            string webServiceResponse,
            Invoice invoice,
            HttpContext httpContext,
            MellatGatewayOptions gatewayOptions,
            MessagesOptions messagesOptions,
            GatewayAccount account)
        {
            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, account.Name));
            }

            var form = new Dictionary <string, string>
            {
                { "RefId", refId }
            };

            var additionalData = invoice.GetMellatAdditionalData();

            if (!string.IsNullOrWhiteSpace(additionalData?.MobileNumber))
            {
                form.Add("MobileNo", additionalData.MobileNumber);
            }

            return(PaymentRequestResult.SucceedWithPost(
                       account.Name,
                       httpContext,
                       gatewayOptions.PaymentPageUrl,
                       form));
        }
Beispiel #5
0
        public static async Task <MellatCallbackResult> CrateCallbackResultAsync(HttpRequest httpRequest,
                                                                                 MessagesOptions messagesOptions,
                                                                                 CancellationToken cancellationToken)
        {
            var resCode = await httpRequest.TryGetParamAsync("ResCode", cancellationToken).ConfigureAwaitFalse();

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

            //  Reference ID
            var refId = await httpRequest.TryGetParamAsync("RefId", cancellationToken).ConfigureAwaitFalse();

            //  Transaction Code
            var saleReferenceId = await httpRequest.TryGetParamAsync("SaleReferenceId", cancellationToken).ConfigureAwaitFalse();

            var isSucceed = resCode.Value == OkResult;

            PaymentVerifyResult result = null;

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

                result = PaymentVerifyResult.Failed(message);
            }


            return(new MellatCallbackResult
            {
                IsSucceed = isSucceed,
                RefId = refId.Value,
                SaleReferenceId = saleReferenceId.Value,
                Result = result
            });
        }
Beispiel #6
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
            });
        }
Beispiel #7
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
            });
        }