public async Task <RefundPaymentResult> RefundRequest(RefundPaymentRequest request) { string merchantId = request.BankParameters["merchantId"]; string terminalId = request.BankParameters["terminalId"]; //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("N");//virgülden sonraki sıfırlara gerek yok string currencyCode = PaymentProviderFactory.CurrencyCodes[request.CurrencyIsoCode]; if (currencyCode == "TRY") { currencyCode = "TL";//yapıkredi halen eski Türk lirası kodunu kullanıyor } string requestXml = $@"<?xml version=""1.0"" encoding=""utf-8""?> <posnetRequest> <mid>{merchantId}</mid> <tid>{terminalId}</tid> <tranDateRequired>1</tranDateRequired> <return> <amount>{amount}</amount> <currencyCode>{currencyCode}</currencyCode> <hostLogKey>{request.ReferenceNumber.Split('-').First().Trim()}</hostLogKey> </return> </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(RefundPaymentResult.Failed(errorMessage)); } var transactionId = xmlDocument.SelectSingleNode("posnetResponse/hostlogkey")?.InnerText; return(RefundPaymentResult.Successed(transactionId)); }
public async Task <RefundPaymentResult> RefundRequest(RefundPaymentRequest request) { string clientId = request.BankParameters["clientId"]; string userName = request.BankParameters["refundUsername"]; string password = request.BankParameters["refundUserPassword"]; string requestXml = $@"<?xml version=""1.0"" encoding=""utf-8""?> <CC5Request> <Name>{userName}</Name> <Password>{password}</Password> <ClientId>{clientId}</ClientId> <Type>Credit</Type> <OrderId>{request.OrderNumber}</OrderId> </CC5Request>"; var response = await client.PostAsync(request.BankParameters["verifyUrl"], new StringContent(requestXml, Encoding.UTF8, "text/xml")); string responseContent = await response.Content.ReadAsStringAsync(); var xmlDocument = new XmlDocument(); xmlDocument.LoadXml(responseContent); if (xmlDocument.SelectSingleNode("CC5Response/Response") == null || xmlDocument.SelectSingleNode("CC5Response/Response").InnerText != "Approved") { var errorMessage = xmlDocument.SelectSingleNode("CC5Response/ErrMsg")?.InnerText ?? string.Empty; if (string.IsNullOrEmpty(errorMessage)) { errorMessage = "Bankadan hata mesajı alınamadı."; } return(RefundPaymentResult.Failed(errorMessage)); } if (xmlDocument.SelectSingleNode("CC5Response/ProcReturnCode") == null || xmlDocument.SelectSingleNode("CC5Response/ProcReturnCode").InnerText != "00") { var errorMessage = xmlDocument.SelectSingleNode("CC5Response/ErrMsg")?.InnerText ?? string.Empty; if (string.IsNullOrEmpty(errorMessage)) { errorMessage = "Bankadan hata mesajı alınamadı."; } return(RefundPaymentResult.Failed(errorMessage)); } var transactionId = xmlDocument.SelectSingleNode("CC5Response/TransId")?.InnerText ?? string.Empty; return(RefundPaymentResult.Successed(transactionId, transactionId)); }
public async Task <RefundPaymentResult> RefundRequest(RefundPaymentRequest request) { string shopCode = request.BankParameters["shopCode"]; string userCode = request.BankParameters["refundUserCode"]; string userPass = request.BankParameters["refundUserPass"]; StringBuilder formBuilder = new StringBuilder(); formBuilder.AppendFormat("ShopCode={0}&", shopCode); formBuilder.AppendFormat("PurchAmount={0}&", request.TotalAmount.ToString(new CultureInfo("en-US"))); formBuilder.AppendFormat("Currency={0}&", request.CurrencyIsoCode); formBuilder.Append("OrderId=&"); formBuilder.Append("TxnType=Refund&"); formBuilder.AppendFormat("orgOrderId={0}&", request.OrderNumber); formBuilder.AppendFormat("UserCode={0}&", userCode); formBuilder.AppendFormat("UserPass={0}&", userPass); formBuilder.Append("SecureType=NonSecure&"); formBuilder.AppendFormat("Lang={0}&", request.LanguageIsoCode.ToUpper()); formBuilder.Append("MOTO=0"); HttpResponseMessage response = await client.PostAsync(request.BankParameters["verifyUrl"], new StringContent(formBuilder.ToString(), Encoding.UTF8, "application/x-www-form-urlencoded")); string responseContent = await response.Content.ReadAsStringAsync(); if (string.IsNullOrEmpty(responseContent)) { return(RefundPaymentResult.Failed("İade işlemi başarısız.")); } responseContent = responseContent.Replace(";;", ";").Replace(";", "&"); System.Collections.Specialized.NameValueCollection responseParams = HttpUtility.ParseQueryString(responseContent); if (responseParams["ProcReturnCode"] != "00") { return(RefundPaymentResult.Failed(responseParams["ErrorMessage"])); } return(RefundPaymentResult.Successed(responseParams["TransId"], responseParams["TransId"])); }
public async Task <RefundPaymentResult> RefundRequest(RefundPaymentRequest request) { string merchantId = request.BankParameters["merchantId"]; string merchantPassword = request.BankParameters["merchantPassword"]; string requestXml = $@"<VposRequest> <MerchantId>{merchantId}</MerchantId> <Password>{merchantPassword}</Password> <TransactionType>Refund</TransactionType> <ReferenceTransactionId>{request.TransactionId}</ReferenceTransactionId> <ClientIp>{_httpContextAccessor.HttpContext.Connection.RemoteIpAddress}</ClientIp> </VposRequest>"; var parameters = new Dictionary <string, string>(); parameters.Add("prmstr", requestXml); var response = await client.PostAsync(request.BankParameters["verifyUrl"], new FormUrlEncodedContent(parameters)); string responseContent = await response.Content.ReadAsStringAsync(); var xmlDocument = new XmlDocument(); xmlDocument.LoadXml(responseContent); if (xmlDocument.SelectSingleNode("VposResponse/ResultCode") == null || xmlDocument.SelectSingleNode("VposResponse/ResultCode").InnerText != "0000") { string errorMessage = xmlDocument.SelectSingleNode("VposResponse/ResultDetail")?.InnerText ?? string.Empty; if (string.IsNullOrEmpty(errorMessage)) { errorMessage = "Bankadan hata mesajı alınamadı."; } return(RefundPaymentResult.Failed(errorMessage)); } var transactionId = xmlDocument.SelectSingleNode("VposResponse/TransactionId")?.InnerText; return(RefundPaymentResult.Successed(transactionId)); }
public async Task <RefundPaymentResult> RefundRequest(RefundPaymentRequest request) { string terminalUserId = request.BankParameters["terminalUserId"]; string terminalId = request.BankParameters["terminalId"]; string terminalMerchantId = request.BankParameters["terminalMerchantId"]; string refundUserId = request.BankParameters["refundUserId"]; string refundUserPassword = request.BankParameters["refundUserPassword"]; string mode = request.BankParameters["mode"];//PROD | TEST //garanti terminal numarasını 9 haneye tamamlamak için başına sıfır eklenmesini istiyor. string _terminalid = string.Format("{0:000000000}", int.Parse(terminalId)); //garanti 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("N");//virgülden sonraki sıfırlara gerek yok //provizyon şifresi ve 9 haneli terminal numarasının birleşimi ile bir hash oluşturuluyor string securityData = GetSHA1($"{refundUserPassword}{_terminalid}"); //ilgili veriler birleştirilip hash oluşturuluyor string hashstr = GetSHA1($"{request.OrderNumber}{terminalId}{amount}{securityData}"); string requestXml = $@"<?xml version=""1.0"" encoding=""utf-8""?> <GVPSRequest> <Mode>{mode}</Mode> <Version>v0.01</Version> <ChannelCode></ChannelCode> <Terminal> <ProvUserID>{refundUserId}</ProvUserID> <HashData>{hashstr}</HashData> <UserID>{terminalUserId}</UserID> <ID>{terminalId}</ID> <MerchantID>{terminalMerchantId}</MerchantID> </Terminal> <Customer> <IPAddress>{request.CustomerIpAddress}</IPAddress> <EmailAddress></EmailAddress> </Customer> <Order> <OrderID>{request.OrderNumber}</OrderID> <GroupID></GroupID> </Order> <Transaction> <Type>refund</Type> <InstallmentCnt>{request.Installment}</InstallmentCnt> <Amount>{amount}</Amount> <CurrencyCode>{request.CurrencyIsoCode}</CurrencyCode> <CardholderPresentCode>0</CardholderPresentCode> <MotoInd>N</MotoInd> <OriginalRetrefNum>{request.ReferenceNumber}</OriginalRetrefNum> </Transaction> </GVPSRequest>"; var response = await client.PostAsync(request.BankParameters["verifyUrl"], new StringContent(requestXml, Encoding.UTF8, "text/xml")); string responseContent = await response.Content.ReadAsStringAsync(); var xmlDocument = new XmlDocument(); xmlDocument.LoadXml(responseContent); if (xmlDocument.SelectSingleNode("GVPSResponse/Transaction/Response/ReasonCode") == null || xmlDocument.SelectSingleNode("GVPSResponse/Transaction/Response/ReasonCode").InnerText != "00" || xmlDocument.SelectSingleNode("GVPSResponse/Transaction/Response/ReasonCode").InnerText != "0000") { string errorMessage = xmlDocument.SelectSingleNode("GVPSResponse/Transaction/Response/ErrorMsg")?.InnerText ?? string.Empty; if (string.IsNullOrEmpty(errorMessage)) { errorMessage = "Bankadan hata mesajı alınamadı."; } return(RefundPaymentResult.Failed(errorMessage)); } string transactionId = xmlDocument.SelectSingleNode("GVPSResponse/Transaction/RetrefNum")?.InnerText; return(RefundPaymentResult.Successed(transactionId, transactionId)); }