public static async Task <PaymentRequestResult> CreateRequestResult(HttpResponseMessage responseMessage, HttpContext httpContext, YekPayGatewayAccount account, MessagesOptions optionsMessages) { var message = await responseMessage.Content.ReadAsStringAsync(); var response = JsonConvert.DeserializeObject <YekPayResponseModel>(message); if (response == null) { return(PaymentRequestResult.Failed(optionsMessages.InvalidDataReceivedFromGateway, account.Name)); } if (response.Code != SuccessCode) { var failureMessage = response.Description ?? optionsMessages.UnexpectedErrorText; return(PaymentRequestResult.Failed(failureMessage, account.Name)); } var paymentPageUrl = PaymentPageUrl + response.Authority; var descriptor = GatewayTransporterDescriptor.CreateRedirect(paymentPageUrl); var transporter = new DefaultGatewayTransporter(httpContext, descriptor); var result = PaymentRequestResult.Succeed(transporter, account.Name); result.DatabaseAdditionalData.Add(AuthorityAdditionalDataKey, response.Authority); return(result); }
public static PaymentRequestResult CreateRequestResult(string webServiceResponse, HttpContext httpContext, ParsianGatewayAccount account, MessagesOptions messagesOptions) { var token = XmlHelper.GetNodeValueFromXml(webServiceResponse, "Token", "https://pec.Shaparak.ir/NewIPGServices/Sale/SaleService"); var status = XmlHelper.GetNodeValueFromXml(webServiceResponse, "Status", "https://pec.Shaparak.ir/NewIPGServices/Sale/SaleService"); var message = XmlHelper.GetNodeValueFromXml(webServiceResponse, "Message", "https://pec.Shaparak.ir/NewIPGServices/Sale/SaleService"); var isSucceed = !status.IsNullOrEmpty() && status == "0" && !token.IsNullOrEmpty(); if (!isSucceed) { if (message == null) { message = messagesOptions.PaymentFailed; } return(PaymentRequestResult.Failed(message, account.Name)); } var paymentPageUrl = $"{PaymentPageUrl}?Token={token}"; var transporterDescriptor = GatewayTransporterDescriptor.CreateRedirect(paymentPageUrl); var transporter = new DefaultGatewayTransporter(httpContext, transporterDescriptor); var result = PaymentRequestResult.Succeed(transporter, account.Name); result.DatabaseAdditionalData.Add("token", token); return(result); }
public static PaymentRequestResult CreateRequestResult(MelliApiRequestResult result, HttpContext httpContext, MelliGatewayAccount account, MessagesOptions messagesOptions) { if (result == null) { return(PaymentRequestResult.Failed(messagesOptions.UnexpectedErrorText)); } var isSucceed = result.ResCode == SuccessCode; if (!isSucceed) { string message; if (result.ResCode == DuplicateTrackingNumberCode) { message = messagesOptions.DuplicateTrackingNumber; } else { message = !result.Description.IsNullOrEmpty() ? result.Description : MelliRequestResultTranslator.Translate(result.ResCode, messagesOptions); } return(PaymentRequestResult.Failed(message, account.Name)); } var paymentPageUrl = $"{PaymentPageUrl}/Index?token={result.Token}"; var transporterDescriptor = GatewayTransporterDescriptor.CreateRedirect(paymentPageUrl); var transporter = new DefaultGatewayTransporter(httpContext, transporterDescriptor); return(PaymentRequestResult.Succeed(transporter, account.Name)); }
public static PaymentRequestResult CreateRequestResult(string response, HttpContext httpContext, ZarinPalGatewayAccount account, MessagesOptions messagesOptions) { var status = XmlHelper.GetNodeValueFromXml(response, "Status", "http://zarinpal.com/"); var authority = XmlHelper.GetNodeValueFromXml(response, "Authority", "http://zarinpal.com/"); var isSucceed = string.Equals(status, NumericOkResult, StringComparison.InvariantCultureIgnoreCase); if (!isSucceed) { var message = ZarinPalStatusTranslator.Translate(status, messagesOptions); return(PaymentRequestResult.Failed(message, account.Name)); } var paymentPageUrl = GetWebPageUrl(account.IsSandbox) + authority; var transporterDescriptor = GatewayTransporterDescriptor.CreateRedirect(paymentPageUrl); var transporter = new DefaultGatewayTransporter(httpContext, transporterDescriptor); return(PaymentRequestResult.Succeed(transporter, account.Name)); }
/// <summary> /// Creates an instance of <see cref="PaymentRequestResult"/> which indicates a successful result and a Gateway Transporter with type of Redirect. /// </summary> /// <param name="gatewayAccountName"></param> /// <param name="httpContext"></param> /// <param name="url">Page URL.</param> public static PaymentRequestResult SucceedWithRedirect( string gatewayAccountName, HttpContext httpContext, string url) { var descriptor = GatewayTransporterDescriptor.CreateRedirect(url); var transporter = new DefaultGatewayTransporter(httpContext, descriptor); return(Succeed(transporter, gatewayAccountName)); }
public async Task Transporter_Redirects_Correctly() { const string expectedUrl = "http://test.com"; var descriptor = GatewayTransporterDescriptor.CreateRedirect(expectedUrl); IGatewayTransporter transporter = new DefaultGatewayTransporter(_httpContext, descriptor); await transporter.TransportAsync(); Assert.AreEqual((int)HttpStatusCode.Redirect, _httpContext.Response.StatusCode); Assert.IsNotNull(_httpContext.Response.Headers[HeaderNames.Location]); Assert.AreEqual(expectedUrl, _httpContext.Response.Headers[HeaderNames.Location]); }
public static PaymentRequestResult CreateRequestResult(string response, HttpContext httpContext, PayIrGatewayAccount account) { var result = JsonConvert.DeserializeObject <PayIrRequestResponseModel>(response); if (!result.IsSucceed) { return(PaymentRequestResult.Failed(result.ErrorMessage, account.Name)); } var paymentPageUrl = $"{PaymentPageUrl}{result.Token}"; var transporterDescriptor = GatewayTransporterDescriptor.CreateRedirect(paymentPageUrl); var transporter = new DefaultGatewayTransporter(httpContext, transporterDescriptor); return(PaymentRequestResult.Succeed(transporter, account.Name)); }
public static async Task <PaymentRequestResult> CreateRequestResult( HttpResponseMessage responseMessage, HttpContext httpContext, IdPayGatewayAccount account) { var response = await responseMessage.Content.ReadAsStringAsync().ConfigureAwaitFalse(); if (!responseMessage.IsSuccessStatusCode) { var errorModel = JsonConvert.DeserializeObject <IdPayErrorModel>(response); return(PaymentRequestResult.Failed(errorModel.ToString(), account.Name)); } var result = JsonConvert.DeserializeObject <IdPayRequestResultModel>(response); var transporterDescriptor = GatewayTransporterDescriptor.CreateRedirect(result.Link); var transporter = new DefaultGatewayTransporter(httpContext, transporterDescriptor); return(PaymentRequestResult.Succeed(transporter, account.Name)); }