public PaymentResult GetPaymentResult(IFormCollection form)
        {
            var paymentResult = new PaymentResult();

            if (form == null)
            {
                paymentResult.ErrorMessage = "Form verisi alınamadı.";
                return(paymentResult);
            }

            var mdStatus = form["mdStatus"];

            if (StringValues.IsNullOrEmpty(mdStatus))
            {
                paymentResult.ErrorMessage = form["mdErrorMsg"];
                paymentResult.ErrorCode    = form["ProcReturnCode"];
                return(paymentResult);
            }

            var response = form["Response"];

            //mdstatus 1,2,3 veya 4 olursa 3D doğrulama geçildi anlamına geliyor
            if (!mdStatus.Equals("1") || !mdStatus.Equals("2") || !mdStatus.Equals("3") || !mdStatus.Equals("4"))
            {
                paymentResult.ErrorMessage = $"{response} - {form["mdErrorMsg"]}";
                paymentResult.ErrorCode    = form["ProcReturnCode"];
                return(paymentResult);
            }

            if (StringValues.IsNullOrEmpty(response) || !response.Equals("Approved"))
            {
                paymentResult.ErrorMessage = $"{response} - {form["ErrMsg"]}";
                paymentResult.ErrorCode    = form["ProcReturnCode"];
                return(paymentResult);
            }

            paymentResult.Success       = true;
            paymentResult.ResponseCode  = mdStatus;
            paymentResult.TransactionId = form["TransId"];
            paymentResult.ErrorMessage  = $"{response} - {form["ErrMsg"]}";

            return(paymentResult);
        }
Beispiel #2
0
        public PaymentResult GetPaymentResult(IFormCollection form)
        {
            var paymentResult = new PaymentResult();

            if (form == null)
            {
                paymentResult.ErrorMessage = "Form verisi alınamadı.";
                return(paymentResult);
            }

            string merchantId   = ""; //Mağaza numarası
            string merchantPass = ""; //Mağaza numarası

            var hashstr = merchantId + merchantPass + form["OrderId"] + form["AuthCode"] + form["ProcReturnCode"] + form["ResponseRnd"];
            var cryptoServiceProvider = new SHA1CryptoServiceProvider();
            var inputbytes            = cryptoServiceProvider.ComputeHash(Encoding.UTF8.GetBytes(hashstr));
            var hashData = Convert.ToBase64String(inputbytes);

            if (!hashData.Equals(form["ResponseHash"]))
            {
                paymentResult.ErrorMessage = "3D güvenlik imzası geçersiz.";
                return(paymentResult);
            }

            var result = form["TxnResult"];

            if (StringValues.IsNullOrEmpty(result) || !result.Equals("Approved"))
            {
                paymentResult.ErrorMessage = $"{result} - {form["ErrorMessage"]}";
                paymentResult.ErrorCode    = form["ProcReturnCode"];
                return(paymentResult);
            }

            paymentResult.Success       = true;
            paymentResult.ResponseCode  = form["ProcReturnCode"];
            paymentResult.TransactionId = form["OrderId"];
            paymentResult.ErrorMessage  = $"{result} - {form["ErrMsg"]}";

            return(paymentResult);
        }
        public PaymentResult GetPaymentResult(IFormCollection form)
        {
            var paymentResult = new PaymentResult();

            if (form == null)
            {
                paymentResult.ErrorMessage = "Form verisi alınamadı.";
                return(paymentResult);
            }

            var status = form["Status"];

            if (StringValues.IsNullOrEmpty(status))
            {
                paymentResult.ErrorMessage = "İşlem sonuç bilgisi alınamadı.";
                return(paymentResult);
            }

            if (status != "Y")
            {
                if (ErrorCodes.ContainsKey(form["ErrorCode"]))
                {
                    paymentResult.ErrorMessage = ErrorCodes[form["ErrorCode"]];
                }
                else
                {
                    paymentResult.ErrorMessage = "3D doğrulama başarısız";
                }

                paymentResult.ErrorCode = form["ErrorCode"];
                return(paymentResult);
            }

            string requestXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                                "<VposRequest>" +
                                "<MerchantId>" + form["MerchantId"] + "</MerchantId>" +
                                "<Password>" + form["get724_merchant_password"] + "</Password>" +
                                "<TerminalNo>" + form["get724_user_name"] + "</TerminalNo>" +
                                "<Pan>" + form["Pan"] + "</Pan>" +
                                "<Expiry>" + form["expire_date"] + "</Expiry>" +
                                "<CurrencyAmount>" + form["amount"] + "</CurrencyAmount>" +
                                "<CurrencyCode>" + form["PurchCurrency"] + "</CurrencyCode>" +
                                "<TransactionType>Sale</TransactionType>" +
                                "<TransactionId></TransactionId>";

            //boş veya 0 olan taksit bilgisini gönderme
            if (int.TryParse(form["InstallmentCount"], out int installment) && installment > 0)
            {
                requestXml += "<NumberOfInstallments>" + installment + "</NumberOfInstallments>";
            }

            requestXml += "<CardHoldersName>" + form["card_holders_name"] + "</CardHoldersName>" +
                          "<Cvv>" + form["cv2"] + "</Cvv>" +
                          "<ECI>" + form["Eci"] + "</ECI>" +
                          "<CAVV>" + form["CAVV"] + "</CAVV>" +
                          "<MpiTransactionId>" + form["VerifyEnrollmentRequestId"] + "</MpiTransactionId>" +
                          "<OrderId>" + form["VerifyEnrollmentRequestId"] + "</OrderId>" +
                          "<ClientIp>" + _httpContextAccessor.HttpContext.Connection.RemoteIpAddress + "</ClientIp>" +
                          "<TransactionDeviceSource>0</TransactionDeviceSource>" +
                          "</VposRequest>";

            //Canlı https://onlineodeme.vakifbank.com.tr:4443/VposService/v3/Vposreq.aspx
            string requestUrl = "https://onlineodemetest.vakifbank.com.tr:4443/VposService/v3/Vposreq.aspx";//TEST

            var parameters = new Dictionary <string, string>();

            parameters.Add("prmstr", requestXml);
            var    response        = client.PostAsync(requestUrl, new FormUrlEncodedContent(parameters)).GetAwaiter().GetResult();
            string responseContent = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();

            var xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(responseContent);
            var resultCodeNode   = xmlDocument.SelectSingleNode("VposResponse/ResultCode");
            var resultDetailNode = xmlDocument.SelectSingleNode("VposResponse/ResultDetail");

            if (resultCodeNode.InnerText != "0000")
            {
                paymentResult.ErrorMessage = resultDetailNode.InnerText;
                paymentResult.ErrorCode    = resultCodeNode.InnerText;
                return(paymentResult);
            }

            paymentResult.Success       = true;
            paymentResult.ResponseCode  = resultCodeNode.InnerText;
            paymentResult.TransactionId = form["Xid"];
            paymentResult.ErrorMessage  = resultDetailNode.InnerText;
            paymentResult.ErrorCode     = resultCodeNode.InnerText;

            return(paymentResult);
        }