Beispiel #1
0
        public Task <PaymentGatewayResult> ThreeDGatewayRequest(PaymentGatewayRequest request)
        {
            try
            {
                string clientId    = request.BankParameters["clientId"];
                string processType = request.BankParameters["processType"];
                string storeKey    = request.BankParameters["storeKey"];
                string storeType   = request.BankParameters["storeType"];
                string totalAmount = request.TotalAmount.ToString(new CultureInfo("en-US"));
                string random      = DateTime.Now.ToString();

                Dictionary <string, object> parameters = new Dictionary <string, object>();
                parameters.Add("clientid", clientId);
                parameters.Add("amount", totalAmount);      //kuruş ayrımı nokta olmalı!!!
                parameters.Add("oid", request.OrderNumber); //sipariş numarası

                //işlem başarılı da olsa başarısız da olsa callback sayfasına yönlendirerek kendi tarafımızda işlem sonucunu kontrol ediyoruz
                parameters.Add("okUrl", request.CallbackUrl);   //başarılı dönüş adresi
                parameters.Add("failUrl", request.CallbackUrl); //hatalı dönüş adresi
                parameters.Add("islemtipi", processType);       //direk satış
                parameters.Add("rnd", random);                  //rastgele bir sayı üretilmesi isteniyor

                string installment = string.Empty;

                if (request.Installment > 1)
                {
                    installment = request.Installment.ToString();
                    parameters.Add("taksit", request.Installment);//taksit sayısı | 1 veya boş tek çekim olur
                }

                string hashstr = $"{clientId}{request.OrderNumber}{totalAmount}{request.CallbackUrl}{request.CallbackUrl}{processType}{installment}{random}{storeKey}";
                SHA1CryptoServiceProvider cryptoServiceProvider = new SHA1CryptoServiceProvider();
                byte[] inputbytes = cryptoServiceProvider.ComputeHash(Encoding.UTF8.GetBytes(hashstr));
                string hashData   = Convert.ToBase64String(inputbytes);

                parameters.Add("hash", hashData);                    //hash data
                parameters.Add("currency", request.CurrencyIsoCode); //ISO code TL 949 | EURO 978 | Dolar 840

                if (!request.CommonPaymentPage)
                {
                    parameters.Add("pan", request.CardNumber);
                    parameters.Add("cardHolderName", request.CardHolderName);
                    parameters.Add("Ecom_Payment_Card_ExpDate_Month", request.ExpireMonth); //kart bitiş ay'ı
                    parameters.Add("Ecom_Payment_Card_ExpDate_Year", request.ExpireYear);   //kart bitiş yıl'ı
                    parameters.Add("cv2", request.CvvCode);                                 //kart güvenlik kodu
                    parameters.Add("cardType", "1");                                        //kart tipi visa 1 | master 2 | amex 3
                }

                parameters.Add("storetype", storeType);
                parameters.Add("lang", request.LanguageIsoCode);//iki haneli dil iso kodu

                return(Task.FromResult(PaymentGatewayResult.Successed(parameters, request.BankParameters["gatewayUrl"])));
            }
            catch (Exception ex)
            {
                return(Task.FromResult(PaymentGatewayResult.Failed(ex.ToString())));
            }
        }
Beispiel #2
0
        public Task <PaymentGatewayResult> ThreeDGatewayRequest(PaymentGatewayRequest request)
        {
            try
            {
                string shopCode    = request.BankParameters["shopCode"];
                string txnType     = request.BankParameters["txnType"];
                string storeKey    = request.BankParameters["storeKey"];
                string secureType  = request.BankParameters["secureType"];
                string totalAmount = request.TotalAmount.ToString(new CultureInfo("en-US"));
                string random      = DateTime.Now.ToString();

                Dictionary <string, object> parameters = new Dictionary <string, object>();
                parameters.Add("ShopCode", shopCode);
                parameters.Add("PurchAmount", totalAmount);     //kuruş ayrımı nokta olmalı!!!
                parameters.Add("OrderId", request.OrderNumber); //sipariş numarası

                //işlem başarılı da olsa başarısız da olsa callback sayfasına yönlendirerek kendi tarafımızda işlem sonucunu kontrol ediyoruz
                parameters.Add("OkUrl", request.CallbackUrl);   //başarılı dönüş adresi
                parameters.Add("FailUrl", request.CallbackUrl); //hatalı dönüş adresi
                parameters.Add("TxnType", txnType);             //direk satış
                parameters.Add("Rnd", random);                  //rastgele bir sayı üretilmesi isteniyor

                //üretici kartı taksit desteği
                if (request.ManufacturerCard)
                {
                    parameters.Add("AgricultureTxnFlag", "T");
                    parameters.Add("PaymentFrequency", request.Installment);
                    parameters.Add("MaturityPeriod", request.Installment);
                }
                else
                {
                    //normal taksit
                    parameters.Add("InstallmentCount", request.Installment);//taksit sayısı | 1 veya boş tek çekim olur
                }

                string hashstr = $"{shopCode}{request.OrderNumber}{totalAmount}{request.CallbackUrl}{request.CallbackUrl}{txnType}{request.Installment}{random}{storeKey}";
                SHA1CryptoServiceProvider cryptoServiceProvider = new SHA1CryptoServiceProvider();
                byte[] inputbytes = cryptoServiceProvider.ComputeHash(Encoding.UTF8.GetBytes(hashstr));
                string hashData   = Convert.ToBase64String(inputbytes);

                parameters.Add("Hash", hashData);                    //hash data
                parameters.Add("Currency", request.CurrencyIsoCode); //TL ISO code | EURO 978 | Dolar 840
                parameters.Add("Pan", request.CardNumber);

                parameters.Add("Expiry", $"{request.ExpireMonth}{request.ExpireYear}"); //kart bitiş ay-yıl birleşik
                parameters.Add("Cvv2", request.CvvCode);                                //kart güvenlik kodu
                parameters.Add("CartType", request.CardType);                           //kart tipi visa 1 | master 2 | amex 3
                parameters.Add("SecureType", secureType);
                parameters.Add("Lang", request.LanguageIsoCode.ToUpper());              //iki haneli dil iso kodu

                return(Task.FromResult(PaymentGatewayResult.Successed(parameters, request.BankParameters["gatewayUrl"])));
            }
            catch (Exception ex)
            {
                return(Task.FromResult(PaymentGatewayResult.Failed(ex.ToString())));
            }
        }
Beispiel #3
0
        public async Task <PaymentGatewayResult> ProcessOrder(OrderModel order)
        {
            var result = new PaymentGatewayResult();

            result = order.PaymentGateway switch
            {
                PaymentGateway.PayPal => result = await this._paypalClient.ProcessBilling(order),
                PaymentGateway.Stripe => result = await this._stripeClient.ProcessBilling(order),
                _ => throw new ArgumentException("Unexpected Gateway", nameof(order.PaymentGateway)),
            };

            return(result);
        }
Beispiel #4
0
        public async Task CorrectlyReceivesData()
        {
            ServerMock.MockSuccesfullClientResponse("123");
            PaymentGatewayResult result = await this.Client.ProcessBilling(
                new OrderModel
            {
                Number = "123"
            });

            result.Should().NotBeNull()
            .And.BeEquivalentTo(new PaymentGatewayResult {
                Success = true
            });
        }
        public async Task <PaymentGatewayResult> ProcessBilling(OrderModel order)
        {
            await this._httpClient.BaseUrl
            .AppendPathSegment("post")
            .PostJsonAsync(order)
            .ReceiveJson <PaymentGatewayResult>();

            // Let's pretend we had a succsefull call.
            var response = new PaymentGatewayResult {
                Success = true
            };

            return(response);
        }
        public Task <PaymentGatewayResult> ThreeDGatewayRequest(PaymentGatewayRequest request)
        {
            try
            {
                string mbrId       = request.BankParameters["mbrId"];      //Mağaza numarası
                string merchantId  = request.BankParameters["merchantId"]; //Mağaza numarası
                string userCode    = request.BankParameters["userCode"];   //
                string userPass    = request.BankParameters["userPass"];   //Mağaza anahtarı
                string txnType     = request.BankParameters["txnType"];    //İşlem tipi
                string secureType  = request.BankParameters["secureType"];
                string totalAmount = request.TotalAmount.ToString(new CultureInfo("en-US"));

                var parameters = new Dictionary <string, object>();
                parameters.Add("MbrId", mbrId);
                parameters.Add("MerchantId", merchantId);
                parameters.Add("UserCode", userCode);
                parameters.Add("UserPass", userPass);
                parameters.Add("PurchAmount", totalAmount);                             //kuruş ayrımı nokta olmalı!!!
                parameters.Add("Currency", request.CurrencyIsoCode);                    //TL:949, USD:840, EUR:978
                parameters.Add("OrderId", request.OrderNumber);                         //sipariş numarası
                parameters.Add("TxnType", txnType);                                     //direk satış
                parameters.Add("SecureType", secureType);                               //NonSecure, 3Dpay, 3DModel, 3DHost
                parameters.Add("Pan", request.CardNumber);                              //kart numarası
                parameters.Add("Expiry", $"{request.ExpireMonth}{request.ExpireYear}"); //kart bitiş ay-yıl birleşik
                parameters.Add("Cvv2", request.CvvCode);                                //kart güvenlik kodu
                parameters.Add("Lang", request.LanguageIsoCode);                        //iki haneli dil iso kodu

                //işlem başarılı da olsa başarısız da olsa callback sayfasına yönlendirerek kendi tarafımızda işlem sonucunu kontrol ediyoruz
                parameters.Add("OkUrl", request.CallbackUrl);   //başarılı dönüş adresi
                parameters.Add("FailUrl", request.CallbackUrl); //hatalı dönüş adresi

                string installment = request.Installment.ToString();
                if (request.Installment < 2)
                {
                    installment = string.Empty;                  //0 veya 1 olması durumunda taksit bilgisini boş gönderiyoruz
                }
                parameters.Add("InstallmentCount", installment); //taksit sayısı | 0, 1 veya boş tek çekim olur

                return(Task.FromResult(PaymentGatewayResult.Successed(parameters, request.BankParameters["gatewayUrl"])));
            }
            catch (Exception ex)
            {
                return(Task.FromResult(PaymentGatewayResult.Failed(ex.ToString())));
            }
        }
        public async Task <PaymentGatewayResult> ThreeDGatewayRequest(PaymentGatewayRequest request)
        {
            string merchantId = request.BankParameters["merchantId"];
            string terminalId = request.BankParameters["terminalId"];
            string posnetId   = request.BankParameters["posnetId"];

            try
            {
                //yapıkredi bankasında tutar bilgisinde nokta, virgül gibi değerler istenmiyor. 1.10 TL'lik işlem 110 olarak gönderilmeli. Yani tutarı 100 ile çarpabiliriz.
                string amount = (request.TotalAmount * 100m).ToString("0.##", new CultureInfo("en-US"));//virgülden sonraki sıfırlara gerek yok

                string requestXml = $@"<?xml version=""1.0"" encoding=""utf-8""?>
                                        <posnetRequest>
                                            <mid>{merchantId}</mid>
                                            <tid>{terminalId}</tid>
                                            <oosRequestData>
                                                <posnetid>{posnetId}</posnetid>
                                                <XID>{request.OrderNumber}</XID>
                                                <amount>{amount}</amount>
                                                <currencyCode>{CurrencyCodes[request.CurrencyIsoCode]}</currencyCode>
                                                <installment>{string.Format("{0:00}", request.Installment)}</installment>
                                                <tranType>Sale</tranType>
                                                <cardHolderName>{request.CardHolderName}</cardHolderName>
                                                <ccno>{request.CardNumber}</ccno>
                                                <expDate>{request.ExpireMonth}{request.ExpireYear}</expDate>
                                                <cvc>{request.CvvCode}</cvc>
                                            </oosRequestData>
                                        </posnetRequest>";

                var httpParameters = new Dictionary <string, string>();
                httpParameters.Add("xmldata", requestXml);

                var response = await client.PostAsync(request.BankParameters["verifyUrl"], new FormUrlEncodedContent(httpParameters));

                string responseContent = await response.Content.ReadAsStringAsync();

                var xmlDocument = new XmlDocument();
                xmlDocument.LoadXml(responseContent);

                if (xmlDocument.SelectSingleNode("posnetResponse/approved") == null ||
                    xmlDocument.SelectSingleNode("posnetResponse/approved").InnerText != "1")
                {
                    string errorMessage = xmlDocument.SelectSingleNode("posnetResponse/respText")?.InnerText ?? string.Empty;
                    if (string.IsNullOrEmpty(errorMessage))
                    {
                        errorMessage = "Bankadan hata mesajı alınamadı.";
                    }

                    return(PaymentGatewayResult.Failed(errorMessage));
                }

                var data1Node = xmlDocument.SelectSingleNode("posnetResponse/oosRequestDataResponse/data1");
                var data2Node = xmlDocument.SelectSingleNode("posnetResponse/oosRequestDataResponse/data2");
                var signNode  = xmlDocument.SelectSingleNode("posnetResponse/oosRequestDataResponse/sign");

                var parameters = new Dictionary <string, object>();
                parameters.Add("posnetData", data1Node.InnerText);
                parameters.Add("posnetData2", data2Node.InnerText);
                parameters.Add("digest", signNode.InnerText);

                parameters.Add("mid", merchantId);
                parameters.Add("posnetID", posnetId);

                //Vade Farklı işlemler için kullanılacak olan kampanya kodunu belirler.
                //Üye İşyeri için tanımlı olan kampanya kodu, İşyeri Yönetici Ekranlarına giriş yapıldıktan sonra, Üye İşyeri bilgileri sayfasından öğrenilebilinir.
                parameters.Add("vftCode", string.Empty);

                parameters.Add("merchantReturnURL", request.CallbackUrl); //geri dönüş adresi
                parameters.Add("lang", request.LanguageIsoCode);
                parameters.Add("url", string.Empty);                      //openANewWindow 1 olarak ayarlanırsa buraya gidilecek url verilmeli
                parameters.Add("openANewWindow", "0");                    //POST edilecek formun yeni bir sayfaya mı yoksa mevcut sayfayı mı yönlendirileceği
                parameters.Add("useJokerVadaa", "1");                     //yapıkredi kartlarında vadaa kullanılabilirse izin verir

                return(PaymentGatewayResult.Successed(parameters, request.BankParameters["gatewayUrl"]));
            }
            catch (Exception ex)
            {
                return(PaymentGatewayResult.Failed(ex.ToString()));
            }
        }
        public Task <PaymentGatewayResult> ThreeDGatewayRequest(PaymentGatewayRequest request)
        {
            try
            {
                string shopCode   = request.BankParameters["shopCode"];
                string txnType    = request.BankParameters["txnType"];
                string storeKey   = request.BankParameters["storeKey"];
                string secureType = request.BankParameters["secureType"];
                string random     = DateTime.Now.ToString();

                var parameters = new Dictionary <string, object>();
                parameters.Add("ShopCode", shopCode);
                parameters.Add("OrderId", request.OrderNumber);//sipariş numarası

                //işlem başarılı da olsa başarısız da olsa callback sayfasına yönlendirerek kendi tarafımızda işlem sonucunu kontrol ediyoruz
                parameters.Add("OkUrl", request.CallbackUrl);                           //başarılı dönüş adresi
                parameters.Add("FailUrl", request.CallbackUrl);                         //hatalı dönüş adresi
                parameters.Add("TxnType", txnType);                                     //direk satış
                parameters.Add("Rnd", random);                                          //rastgele bir sayı üretilmesi isteniyor

                parameters.Add("Currency", request.CurrencyIsoCode);                    //TL ISO code | EURO 978 | Dolar 840
                parameters.Add("Pan", request.CardNumber);
                parameters.Add("Expiry", $"{request.ExpireMonth}{request.ExpireYear}"); //kart bitiş ay-yıl birleşik
                parameters.Add("Cvv2", request.CvvCode);                                //kart güvenlik kodu
                parameters.Add("CartType", request.CardType);                           //kart tipi visa 1 | master 2 | amex 3
                parameters.Add("SecureType", secureType);
                parameters.Add("Lang", request.LanguageIsoCode.ToUpper());              //iki haneli dil iso kodu

                //kuruş ayrımı nokta olmalı!!!
                string totalAmount = request.TotalAmount.ToString(new CultureInfo("en-US"));
                parameters.Add("PurchAmount", totalAmount);

                string installment = request.Installment.ToString();
                if (request.Installment < 2 || request.ManufacturerCard) //üretici kart durumunda taksit boş olacak
                {
                    installment = string.Empty;                          //0 veya 1 olması durumunda taksit bilgisini boş gönderiyoruz
                }
                //üretici kartı taksit desteği
                if (request.ManufacturerCard && request.Installment > 1)
                {
                    string maturity = request.Installment.ToString();
                    parameters.Add("AgricultureTxnFlag", "T");
                    parameters.Add("PaymentFrequency", maturity);
                    parameters.Add("MaturityPeriod", maturity);
                }

                //normal taksit
                parameters.Add("InstallmentCount", installment); //taksit sayısı | 1 veya boş tek çekim olur
                parameters.Add("taksitsayisi", installment);     //taksit sayısı | 1 veya boş tek çekim olur

                var hashBuilder = new StringBuilder();
                hashBuilder.Append(shopCode);
                hashBuilder.Append(request.OrderNumber);
                hashBuilder.Append(totalAmount);
                hashBuilder.Append(request.CallbackUrl);
                hashBuilder.Append(request.CallbackUrl);
                hashBuilder.Append(txnType);
                hashBuilder.Append(installment);
                hashBuilder.Append(random);
                hashBuilder.Append(storeKey);

                var hashData = GetSHA1(hashBuilder.ToString());
                parameters.Add("Hash", hashData);//hash data

                return(Task.FromResult(PaymentGatewayResult.Successed(parameters, request.BankParameters["gatewayUrl"])));
            }
            catch (Exception ex)
            {
                return(Task.FromResult(PaymentGatewayResult.Failed(ex.ToString())));
            }
        }
Beispiel #9
0
        public Task <PaymentGatewayResult> ThreeDGatewayRequest(PaymentGatewayRequest request)
        {
            try
            {
                string terminalUserId       = request.BankParameters["terminalUserId"];
                string terminalId           = request.BankParameters["terminalId"];
                string terminalMerchantId   = request.BankParameters["terminalMerchantId"];
                string terminalProvUserId   = request.BankParameters["terminalProvUserId"];
                string terminalProvPassword = request.BankParameters["terminalProvPassword"];
                string storeKey             = request.BankParameters["storeKey"]; //garanti sanal pos ekranından üreteceğimiz güvenlik anahtarı
                string mode = request.BankParameters["mode"];                     //PROD | TEST
                string type = "sales";

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

                if (!request.CommonPaymentPage)
                {
                    parameters.Add("cardnumber", request.CardNumber);
                    parameters.Add("cardcvv2", request.CvvCode);                //kart güvenlik kodu
                    parameters.Add("cardexpiredatemonth", request.ExpireMonth); //kart bitiş ay'ı
                    parameters.Add("cardexpiredateyear", request.ExpireYear);   //kart bitiş yıl'ı
                }

                parameters.Add("secure3dsecuritylevel", "3D_PAY");//SMS onaylı ödeme modeli 3DPay olarak adlandırılıyor.
                parameters.Add("mode", mode);
                parameters.Add("apiversion", "v0.01");
                parameters.Add("terminalprovuserid", terminalProvUserId);
                parameters.Add("terminaluserid", terminalUserId);
                parameters.Add("terminalmerchantid", terminalMerchantId);
                parameters.Add("terminalid", terminalId);
                parameters.Add("txntype", type);                            //direk satış
                parameters.Add("txncurrencycode", request.CurrencyIsoCode); //TL ISO code | EURO 978 | Dolar 840
                parameters.Add("lang", request.LanguageIsoCode);
                parameters.Add("motoind", "N");
                parameters.Add("customeripaddress", request.CustomerIpAddress);
                parameters.Add("orderaddressname1", request.CardHolderName);
                parameters.Add("orderid", request.OrderNumber);//sipariş numarası

                //işlem başarılı da olsa başarısız da olsa callback sayfasına yönlendirerek kendi tarafımızda işlem sonucunu kontrol ediyoruz
                parameters.Add("successurl", request.CallbackUrl); //başarılı dönüş adresi
                parameters.Add("errorurl", request.CallbackUrl);   //hatalı dönüş adresi

                //garanti bankasında tutar bilgisinde nokta, virgül gibi değerler istenmiyor. 1.10 TL'lik işlem 110 olarak gönderilmeli. Yani tutarı 100 ile çarpabiliriz.
                string amount = (request.TotalAmount * 100m).ToString("0.##", new CultureInfo("en-US"));//virgülden sonraki sıfırlara gerek yok
                parameters.Add("txnamount", amount);

                string installment = request.Installment.ToString();
                if (request.Installment < 2)
                {
                    installment = string.Empty;                     //0 veya 1 olması durumunda taksit bilgisini boş gönderiyoruz
                }
                parameters.Add("txninstallmentcount", installment); //taksit sayısı | boş tek çekim olur

                var hashBuilder = new StringBuilder();
                hashBuilder.Append(terminalId);
                hashBuilder.Append(request.OrderNumber);
                hashBuilder.Append(amount);
                hashBuilder.Append(request.CallbackUrl);
                hashBuilder.Append(request.CallbackUrl);
                hashBuilder.Append(type);
                hashBuilder.Append(installment);
                hashBuilder.Append(storeKey);

                //garanti tarafından terminal numarasını 9 haneye tamamlamak için başına sıfır eklenmesi isteniyor.
                string _terminalid = string.Format("{0:000000000}", int.Parse(terminalId));

                //provizyon şifresi ve 9 haneli terminal numarasının birleşimi ile bir hash oluşturuluyor
                string securityData = GetSHA1($"{terminalProvPassword}{_terminalid}");
                hashBuilder.Append(securityData);

                var hashData = GetSHA1(hashBuilder.ToString());
                parameters.Add("secure3dhash", hashData);

                return(Task.FromResult(PaymentGatewayResult.Successed(parameters, request.BankParameters["gatewayUrl"])));
            }
            catch (Exception ex)
            {
                return(Task.FromResult(PaymentGatewayResult.Failed(ex.ToString())));
            }
        }
Beispiel #10
0
        public Task <PaymentGatewayResult> ThreeDGatewayRequest(PaymentGatewayRequest request)
        {
            try
            {
                string clientId    = request.BankParameters["clientId"];
                string processType = request.BankParameters["processType"];
                string storeKey    = request.BankParameters["storeKey"];
                string storeType   = request.BankParameters["storeType"];
                string random      = DateTime.Now.ToString();

                var parameters = new Dictionary <string, object>();
                parameters.Add("clientid", clientId);
                parameters.Add("oid", request.OrderNumber);//sipariş numarası

                if (!request.CommonPaymentPage)
                {
                    parameters.Add("pan", request.CardNumber);
                    parameters.Add("cardHolderName", request.CardHolderName);
                    parameters.Add("Ecom_Payment_Card_ExpDate_Month", request.ExpireMonth); //kart bitiş ay'ı
                    parameters.Add("Ecom_Payment_Card_ExpDate_Year", request.ExpireYear);   //kart bitiş yıl'ı
                    parameters.Add("cv2", request.CvvCode);                                 //kart güvenlik kodu
                    parameters.Add("cardType", "1");                                        //kart tipi visa 1 | master 2 | amex 3
                }

                //işlem başarılı da olsa başarısız da olsa callback sayfasına yönlendirerek kendi tarafımızda işlem sonucunu kontrol ediyoruz
                parameters.Add("okUrl", request.CallbackUrl);        //başarılı dönüş adresi
                parameters.Add("failUrl", request.CallbackUrl);      //hatalı dönüş adresi
                parameters.Add("islemtipi", processType);            //direk satış
                parameters.Add("rnd", random);                       //rastgele bir sayı üretilmesi isteniyor
                parameters.Add("currency", request.CurrencyIsoCode); //ISO code TL 949 | EURO 978 | Dolar 840
                parameters.Add("storetype", storeType);
                parameters.Add("lang", request.LanguageIsoCode);     //iki haneli dil iso kodu

                //kuruş ayrımı nokta olmalı!!!
                string totalAmount = request.TotalAmount.ToString(new CultureInfo("en-US"));
                parameters.Add("amount", totalAmount);

                string installment = request.Installment.ToString();
                if (request.Installment > 1)
                {
                    parameters.Add("taksit", request.Installment);//taksit sayısı | 1 veya boş tek çekim olur
                }
                else
                {
                    installment = string.Empty;//0 veya 1 olması durumunda taksit bilgisini boş gönderiyoruz
                }
                var hashBuilder = new StringBuilder();
                hashBuilder.Append(clientId);
                hashBuilder.Append(request.OrderNumber);
                hashBuilder.Append(totalAmount);
                hashBuilder.Append(request.CallbackUrl);
                hashBuilder.Append(request.CallbackUrl);
                hashBuilder.Append(processType);
                hashBuilder.Append(installment);
                hashBuilder.Append(random);
                hashBuilder.Append(storeKey);

                var hashData = GetSHA1(hashBuilder.ToString());
                parameters.Add("hash", hashData);//hash data

                return(Task.FromResult(PaymentGatewayResult.Successed(parameters, request.BankParameters["gatewayUrl"])));
            }
            catch (Exception ex)
            {
                return(Task.FromResult(PaymentGatewayResult.Failed(ex.ToString())));
            }
        }
Beispiel #11
0
        public async Task <IActionResult> Confirm(Guid paymentId)
        {
            if (paymentId == Guid.Empty)
            {
                VerifyGatewayResult failModel = VerifyGatewayResult.Failed("Ödeme bilgisi geçersiz.");
                return(View("Fail", failModel));
            }

            //get transaction by identifier
            PaymentTransaction payment = await _paymentService.GetByOrderNumber(paymentId);

            if (payment == null)
            {
                VerifyGatewayResult failModel = VerifyGatewayResult.Failed("Ödeme bilgisi geçersiz.");
                return(View("Fail", failModel));
            }

            PaymentGatewayRequest bankRequest = JsonConvert.DeserializeObject <PaymentGatewayRequest>(payment.BankRequest);

            if (bankRequest == null)
            {
                VerifyGatewayResult failModel = VerifyGatewayResult.Failed("Ödeme bilgisi geçersiz.");
                return(View("Fail", failModel));
            }

            if (!IPAddress.TryParse(bankRequest.CustomerIpAddress, out IPAddress ipAddress))
            {
                bankRequest.CustomerIpAddress = HttpContext.Connection.RemoteIpAddress.ToString();
            }

            if (bankRequest.CustomerIpAddress == "::1")
            {
                bankRequest.CustomerIpAddress = "127.0.0.1";
            }

            IPaymentProvider provider = _paymentProviderFactory.Create(bankRequest.BankName);

            //set callback url
            bankRequest.CallbackUrl = new Uri($"{Request.GetHostUrl(false)}{Url.RouteUrl("Callback", new { paymentId = payment.OrderNumber })}");

            //gateway request
            PaymentGatewayResult gatewayResult = await provider.ThreeDGatewayRequest(bankRequest);

            //check result status
            if (!gatewayResult.Success)
            {
                VerifyGatewayResult failModel = VerifyGatewayResult.Failed(gatewayResult.ErrorMessage);
                return(View("Fail", failModel));
            }

            //html content
            if (gatewayResult.HtmlContent)
            {
                return(View(model: gatewayResult.HtmlFormContent));
            }

            //create form submit with parameters
            string model = _paymentProviderFactory.CreatePaymentFormHtml(gatewayResult.Parameters, gatewayResult.GatewayUrl);

            return(View(model: model));
        }
Beispiel #12
0
        public async Task <PaymentGatewayResult> ThreeDGatewayRequest(PaymentGatewayRequest request)
        {
            try
            {
                //Total amount (100 = 1TL)
                var amount = Convert.ToInt32(request.TotalAmount * 100m).ToString();

                var merchantOrderId = request.OrderNumber;
                var merchantId      = request.BankParameters["merchantId"];
                var customerId      = request.BankParameters["customerNumber"];
                var userName        = request.BankParameters["userName"];
                var password        = request.BankParameters["password"];

                string installment = request.Installment.ToString();
                if (request.Installment < 2)
                {
                    installment = string.Empty;//0 veya 1 olması durumunda taksit bilgisini boş gönderiyoruz
                }
                //merchantId, merchantOrderId, amount, okUrl, failUrl, userName and password
                var hashData = CreateHash(merchantId, merchantOrderId, amount, request.CallbackUrl.ToString(), request.CallbackUrl.ToString(), userName, password);

                var requestXml = $@"<KuveytTurkVPosMessage
                    xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
                    xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
                        <APIVersion>1.0.0</APIVersion>
                        <OkUrl>{request.CallbackUrl}</OkUrl>
                        <FailUrl>{request.CallbackUrl}</FailUrl>
                        <HashData>{hashData}</HashData>
                        <MerchantId>{merchantId}</MerchantId>
                        <CustomerId>{customerId}</CustomerId>
                        <UserName>{userName}</UserName>
                        <CardNumber>{request.CardNumber}</CardNumber>
                        <CardExpireDateYear>{string.Format("{0:00}", request.ExpireYear)}</CardExpireDateYear>
                        <CardExpireDateMonth>{string.Format("{0:00}", request.ExpireMonth)}</CardExpireDateMonth>
                        <CardCVV2>{request.CvvCode}</CardCVV2>
                        <CardHolderName>{request.CardHolderName}</CardHolderName>
                        <CardType></CardType>
                        <BatchID>0</BatchID>
                        <TransactionType>Sale</TransactionType>
                        <InstallmentCount>{installment}</InstallmentCount>
                        <Amount>{amount}</Amount>
                        <DisplayAmount>{amount}</DisplayAmount>
                        <CurrencyCode>{string.Format("{0:0000}", int.Parse(request.CurrencyIsoCode))}</CurrencyCode>
                        <MerchantOrderId>{merchantOrderId}</MerchantOrderId>
                        <TransactionSecurity>3</TransactionSecurity>
                        </KuveytTurkVPosMessage>";

                //send request
                var response = await client.PostAsync(request.BankParameters["gatewayUrl"], new StringContent(requestXml, Encoding.UTF8, "text/xml"));

                string responseContent = await response.Content.ReadAsStringAsync();

                //failed
                if (string.IsNullOrWhiteSpace(responseContent))
                {
                    return(PaymentGatewayResult.Failed("Ödeme sırasında bir hata oluştu."));
                }

                //successed
                return(PaymentGatewayResult.Successed(responseContent, request.BankParameters["gatewayUrl"]));
            }
            catch (Exception ex)
            {
                return(PaymentGatewayResult.Failed(ex.ToString()));
            }
        }
Beispiel #13
0
        public async Task <PaymentGatewayResult> ThreeDGatewayRequest(PaymentGatewayRequest request)
        {
            try
            {
                string merchantId       = request.BankParameters["merchantId"];
                string merchantPassword = request.BankParameters["merchantPassword"];
                string enrollmentUrl    = request.BankParameters["enrollmentUrl"];

                var httpParameters = new Dictionary <string, string>();
                httpParameters.Add("Pan", request.CardNumber);
                httpParameters.Add("ExpiryDate", $"{request.ExpireYear}{request.ExpireMonth}");
                httpParameters.Add("PurchaseAmount", request.TotalAmount.ToString(new CultureInfo("en-US")));
                httpParameters.Add("Currency", request.CurrencyIsoCode);//TL 949 | EURO 978 | Dolar 840

                /*
                 * Visa 100
                 * Master Card 200
                 * American Express 300
                 */
                httpParameters.Add("BrandName", "100");
                httpParameters.Add("VerifyEnrollmentRequestId", request.OrderNumber); //sipariş numarası
                httpParameters.Add("SessionInfo", "1");                               //banka dökümanları sabit bir değer
                httpParameters.Add("MerchantID", merchantId);
                httpParameters.Add("MerchantPassword", merchantPassword);
                httpParameters.Add("SuccessUrl", request.CallbackUrl.ToString());
                httpParameters.Add("FailureUrl", request.CallbackUrl.ToString());

                if (request.Installment > 1)
                {
                    httpParameters.Add("InstallmentCount", request.Installment.ToString());
                }

                var response = await client.PostAsync(enrollmentUrl, new FormUrlEncodedContent(httpParameters));

                string responseContent = await response.Content.ReadAsStringAsync();

                var xmlDocument = new XmlDocument();
                xmlDocument.LoadXml(responseContent);
                var statusNode = xmlDocument.SelectSingleNode("IPaySecure/Message/VERes/Status");
                if (statusNode.InnerText != "Y")
                {
                    var messageErrorNode     = xmlDocument.SelectSingleNode("IPaySecure/ErrorMessage");
                    var messageErrorCodeNode = xmlDocument.SelectSingleNode("IPaySecure/MessageErrorCode");

                    return(PaymentGatewayResult.Failed(messageErrorNode.InnerText, messageErrorCodeNode?.InnerText));
                }

                var pareqNode   = xmlDocument.SelectSingleNode("IPaySecure/Message/VERes/PaReq");
                var termUrlNode = xmlDocument.SelectSingleNode("IPaySecure/Message/VERes/TermUrl");
                var mdNode      = xmlDocument.SelectSingleNode("IPaySecure/Message/VERes/MD");
                var acsUrlNode  = xmlDocument.SelectSingleNode("IPaySecure/Message/VERes/ACSUrl");

                var parameters = new Dictionary <string, object>();
                parameters.Add("PaReq", pareqNode.InnerText);
                parameters.Add("TermUrl", termUrlNode.InnerText);
                parameters.Add("MD", mdNode.InnerText);

                //form post edilecek url xml response içerisinde bankadan dönüyor
                return(PaymentGatewayResult.Successed(parameters, acsUrlNode.InnerText));
            }
            catch (Exception ex)
            {
                return(PaymentGatewayResult.Failed(ex.ToString()));
            }
        }