public static PaymentRequestResult CreateRequestResult( string webServiceResponse, HttpContext httpContext, ParsianGatewayAccount account, ParsianGatewayOptions gatewayOptions, 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 = $"{gatewayOptions.PaymentPageUrl}?Token={token}"; var result = PaymentRequestResult.SucceedWithRedirect(account.Name, httpContext, paymentPageUrl); result.DatabaseAdditionalData.Add("token", token); return(result); }
public static async Task <PaymentRequestResult> CreateRequestResult( HttpResponseMessage responseMessage, HttpContext httpContext, YekPayGatewayAccount account, YekPayGatewayOptions gatewayOptions, 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 = gatewayOptions.PaymentPageUrl + response.Authority; var result = PaymentRequestResult.SucceedWithRedirect(account.Name, httpContext, paymentPageUrl); result.DatabaseAdditionalData.Add(AuthorityAdditionalDataKey, response.Authority); return(result); }
public static async Task <PaymentRequestResult> CreateRequestResult( HttpResponseMessage responseMessage, HttpContext httpContext, ZibalGatewayAccount account, ZibalGatewayOptions gatewayOptions, MessagesOptions messagesOptions) { var message = await responseMessage.Content.ReadAsStringAsync(); var response = JsonConvert.DeserializeObject <ZibalResponseModel>(message); if (response == null) { return(PaymentRequestResult.Failed(messagesOptions.InvalidDataReceivedFromGateway, account.Name)); } if (response.Result != SuccessCode) { var failureMessage = ZibalTranslator.TranslateResult(response.Result) ?? response.Message ?? messagesOptions.PaymentFailed; return(PaymentRequestResult.Failed(failureMessage, account.Name, response.Result.ToString())); } var paymentPageUrl = string.IsNullOrEmpty(response.PayLink) ? GetPaymentPageUrl(gatewayOptions.PaymentPageUrl, response.TrackId) : response.PayLink; var result = PaymentRequestResult.SucceedWithRedirect(account.Name, httpContext, paymentPageUrl); result.DatabaseAdditionalData.Add(TrackIdAdditionalDataKey, response.TrackId.ToString()); return(result); }
public static PaymentRequestResult CreateRequestResult(string response, HttpContext httpContext, PayIrGatewayAccount account, PayIrGatewayOptions gatewayOptions) { var result = JsonConvert.DeserializeObject <PayIrRequestResponseModel>(response); if (!result.IsSucceed) { return(PaymentRequestResult.Failed(result.ErrorMessage, account.Name)); } var paymentPageUrl = $"{gatewayOptions.PaymentPageUrl}{result.Token}"; return(PaymentRequestResult.SucceedWithRedirect(account.Name, httpContext, paymentPageUrl)); }
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); return(PaymentRequestResult.SucceedWithRedirect(account.Name, httpContext, result.Link)); }
internal static async Task <PaymentRequestResult> CreateRequestResult( HttpResponseMessage responseMessage, HttpContext httpContext, FanAvaGatewayAccount account, FanAvaGatewayOptions gatewayOptions) { var response = await responseMessage.Content.ReadAsStringAsync().ConfigureAwaitFalse(); if (!responseMessage.IsSuccessStatusCode) { return(PaymentRequestResult.Failed(response.ToString(), account.Name)); } var result = JsonSerializer.Deserialize <FanAvaRequestResultModel>(response); var url = QueryHelpers.AddQueryString(gatewayOptions.PaymentPageUrl, new Dictionary <string, string> { { "token", result.Token }, { "lang", "fa" } }); return(PaymentRequestResult.SucceedWithRedirect(account.Name, httpContext, url)); }
public static PaymentRequestResult CreateRequestResult(string response, HttpContext httpContext, ZarinPalGatewayAccount account, ZarinPalGatewayOptions gatewayOptions, 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, gatewayOptions) + authority; return(PaymentRequestResult.SucceedWithRedirect(account.Name, httpContext, paymentPageUrl)); }
/// <inheritdoc /> public override async Task <IPaymentRequestResult> RequestAsync(Invoice invoice, CancellationToken cancellationToken = default) { if (invoice == null) { throw new ArgumentNullException(nameof(invoice)); } var account = await GetAccountAsync(invoice).ConfigureAwaitFalse(); _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", account.AccessToken); var body = new CreatePayRequestModel { Amount = invoice.Amount, Description = invoice.GetPayPingRequest()?.Description, PayerIdentity = invoice.GetPayPingRequest()?.Mobile, PayerName = invoice.GetPayPingRequest()?.PayerName, ReturnUrl = invoice.CallbackUrl, ClientRefId = invoice.TrackingNumber.ToString() }; //Send Create pay Request var response = await _httpClient.PostJsonAsync(_pingGatewayOptions.ApiRequestUrl, body, cancellationToken); //Check if we ran into an Issue response.EnsureSuccessStatusCode(); //Get Response data var responseBody = await response.Content.ReadAsStringAsync(); //Convert Response data to Model and get PayCode var createPayResult = JsonConvert.DeserializeObject <CreatePayResponseModel>(responseBody); //Redirect User to gateway with the Code var url = _pingGatewayOptions.PaymentPageUrl.ToggleStringAtEnd("/", shouldHave: true) + createPayResult.Code; return(PaymentRequestResult.SucceedWithRedirect(account.Name, _httpContextAccessor.HttpContext, url)); }
public static PaymentRequestResult CreateRequestResult( MelliApiRequestResult result, HttpContext httpContext, MelliGatewayAccount account, MelliGatewayOptions gatewayOptions, 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 = $"{gatewayOptions.PaymentPageUrl}/Index?token={result.Token}"; return(PaymentRequestResult.SucceedWithRedirect(account.Name, httpContext, paymentPageUrl)); }