public static PaymentVerifyResult CreateSettleResult( string response, AsanPardakhtCallbackResult callbackResult, MessagesOptions messagesOptions) { var result = XmlHelper.GetNodeValueFromXml(response, "RequestReconciliationResult", "http://tempuri.org/"); var isSucceed = result == "600"; string message; if (isSucceed) { message = messagesOptions.PaymentSucceed; } else { message = AsanPardakhtResultTranslator.TranslateReconcilation(result, messagesOptions) ?? messagesOptions.PaymentFailed; } var verifyResult = new PaymentVerifyResult { IsSucceed = isSucceed, TransactionCode = callbackResult.Rrn, Message = message }; verifyResult.DatabaseAdditionalData.Add("PayGateTranId", callbackResult.PayGateTranId); verifyResult.DatabaseAdditionalData.Add("LastFourDigitOfPAN", callbackResult.LastFourDigitOfPAN); return(verifyResult); }
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)); }
public static AsanPardakhtVerifyResult CheckVerifyResult( string response, AsanPardakhtCallbackResult callbackResult, MessagesOptions messagesOptions) { var result = XmlHelper.GetNodeValueFromXml(response, "RequestVerificationResult", "http://tempuri.org/"); var isSucceed = result == "500"; PaymentVerifyResult verifyResult = null; if (!isSucceed) { var message = AsanPardakhtResultTranslator.TranslateVerification(result, messagesOptions); verifyResult = callbackResult.Result; verifyResult.Message = message; } return(new AsanPardakhtVerifyResult { IsSucceed = isSucceed, Result = verifyResult }); }
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 }); }