public AsanPardakhtGateway( IHttpContextAccessor httpContextAccessor, IHttpClientFactory httpClientFactory, IGatewayAccountProvider <AsanPardakhtGatewayAccount> accountProvider, IAsanPardakhtCrypto crypto, IOptions <AsanPardakhtGatewayOptions> gatewayOptions, IOptions <MessagesOptions> messageOptions) : base(accountProvider) { _httpContextAccessor = httpContextAccessor; _httpClient = httpClientFactory.CreateClient(this); _crypto = crypto; _gatewayOptions = gatewayOptions.Value; _messageOptions = messageOptions; }
public void Setup() { var mockCrypto = new Mock <IAsanPardakhtCrypto>(); mockCrypto .Setup(crypto => crypto.Encrypt(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .Returns("test"); var decryptedValue = $"{ExpectedAmount},0,test,0,message,test,{ExpectedTransactionCode},test"; mockCrypto .Setup(crypto => crypto.Decrypt(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .Returns(decryptedValue); _crypto = mockCrypto.Object; }
public static string CreateSettleData( AsanPardakhtCallbackResult callbackResult, AsanPardakhtGatewayAccount account, IAsanPardakhtCrypto crypto) { var requestToEncrypt = $"{account.UserName},{account.Password}"; var encryptedRequest = crypto.Encrypt(requestToEncrypt, account.Key, account.IV); return ("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tem=\"http://tempuri.org/\">" + "<soapenv:Header/>" + "<soapenv:Body>" + "<tem:RequestReconciliation>" + $"<tem:merchantConfigurationID>{account.MerchantConfigurationId}</tem:merchantConfigurationID>" + "<!--Optional:-->" + $"<tem:encryptedCredentials>{XmlHelper.EncodeXmlValue(encryptedRequest)}</tem:encryptedCredentials>" + $"<tem:payGateTranID>{callbackResult.PayGateTranId}</tem:payGateTranID>" + "</tem:RequestReconciliation>" + "</soapenv:Body>" + "</soapenv:Envelope>"); }
public static AsanPardakhtCallbackResult CreateCallbackResult( InvoiceContext context, AsanPardakhtGatewayAccount account, HttpRequest httpRequest, IAsanPardakhtCrypto crypto, 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 = crypto.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 { Status = PaymentVerifyResultStatus.Failed, TrackingNumber = context.Payment.TrackingNumber, TransactionCode = rrn, Message = message }; } } return(new AsanPardakhtCallbackResult { IsSucceed = isSucceed, PayGateTranId = payGateTranId, Rrn = rrn, LastFourDigitOfPAN = lastFourDigitOfPAN, Result = verifyResult }); }
//public const string PaymentPageUrl = "https://asan.shaparak.ir/"; //public const string BaseServiceUrl = "https://services.asanpardakht.net/paygate/merchantservices.asmx"; public static string CreateRequestData(Invoice invoice, AsanPardakhtGatewayAccount account, IAsanPardakhtCrypto crypto) { var requestToEncrypt = string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8}", 1, account.UserName, account.Password, invoice.TrackingNumber, invoice.Amount.ToLongString(), "datetime", "", invoice.CallbackUrl, "0" ); var encryptedRequest = crypto.Encrypt(requestToEncrypt, account.Key, account.IV); return ("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tem=\"http://tempuri.org/\">" + "<soapenv:Header/>" + "<soapenv:Body>" + "<tem:RequestOperation>" + $"<tem:merchantConfigurationID>{account.MerchantConfigurationId}</tem:merchantConfigurationID>" + "<!--Optional:-->" + $"<tem:encryptedRequest>{XmlHelper.EncodeXmlValue(encryptedRequest)}</tem:encryptedRequest>" + "</tem:RequestOperation>" + "</soapenv:Body>" + "</soapenv:Envelope>"); }