Example #1
0
        public static PaymentRequestResult CreateRequestResult(
            string response,
            Invoice invoice,
            AsanPardakhtGatewayAccount account,
            IHttpContextAccessor httpContextAccessor,
            MessagesOptions messagesOptions)
        {
            var result = XmlHelper.GetNodeValueFromXml(response, "RequestOperationResult", "http://tempuri.org/");

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

            var    isSucceed = splitedResult.Length == 2 && splitedResult[0] == "0";
            string message   = null;

            if (!isSucceed)
            {
                message = AsanPardakhtResultTranslator.TranslateRequest(splitedResult[0], messagesOptions);

                return(PaymentRequestResult.Failed(message));
            }

            var transporter = new GatewayPost(
                httpContextAccessor,
                PaymentPageUrl,
                new Dictionary <string, string>
            {
                { "RefId", splitedResult[1] }
            });

            return(PaymentRequestResult.Succeed(transporter, account.Name));
        }
Example #2
0
        public static AsanPardakhtCallbackResult CreateCallbackResult(
            InvoiceContext context,
            AsanPardakhtGatewayAccount account,
            HttpRequest httpRequest,
            MessagesOptions messagesOptions)
        {
            httpRequest.Form.TryGetValue("ReturningParams", out var returningParams);

            var isSucceed = false;
            PaymentVerifyResult verifyResult = null;
            string payGateTranId             = null;
            string rrn = null;
            string lastFourDigitOfPAN = null;

            if (returningParams.IsNullOrEmpty())
            {
                verifyResult = new PaymentVerifyResult
                {
                    TrackingNumber = context.Payment.TrackingNumber,
                    IsSucceed      = false,
                    Message        = messagesOptions.InvalidDataReceivedFromGateway
                };
            }
            else
            {
                var decryptedResult = Decrypt(returningParams, account.Key, account.IV);

                var splitedResult = decryptedResult.Split(',');

                var amount       = splitedResult[0];
                var preInvoiceID = splitedResult[1];
                var token        = splitedResult[2];
                var resCode      = splitedResult[3];
                var messageText  = splitedResult[4];
                payGateTranId      = splitedResult[5];
                rrn                = splitedResult[6];
                lastFourDigitOfPAN = splitedResult[7];

                isSucceed = resCode == "0" || resCode == "00";
                string message = null;

                if (!isSucceed)
                {
                    message = messageText.IsNullOrEmpty()
                        ? AsanPardakhtResultTranslator.TranslateRequest(resCode, messagesOptions)
                        : messageText;
                }
                else
                {
                    if (long.TryParse(amount, out var longAmount))
                    {
                        if (longAmount != (long)context.Payment.Amount)
                        {
                            isSucceed = false;
                            message   = "مبلغ پرداخت شده با مبلغ درخواست شده مطابقت ندارد.";
                        }
                    }
                    else
                    {
                        isSucceed = false;
                        message   = "مبلغ پرداخت شده نامشخص است.";
                    }
                }

                if (!isSucceed)
                {
                    verifyResult = new PaymentVerifyResult
                    {
                        IsSucceed       = false,
                        TrackingNumber  = context.Payment.TrackingNumber,
                        TransactionCode = rrn,
                        Message         = message
                    };
                }
            }

            return(new AsanPardakhtCallbackResult
            {
                IsSucceed = isSucceed,
                PayGateTranId = payGateTranId,
                Rrn = rrn,
                LastFourDigitOfPAN = lastFourDigitOfPAN,
                Result = verifyResult
            });
        }