public static async Task <PaymentVerifyResult> CreateVerifyResult(HttpResponseMessage responseMessage, MessagesOptions messagesOptions) { var response = await responseMessage.Content.ReadAsStringAsync().ConfigureAwaitFalse(); if (!responseMessage.IsSuccessStatusCode) { var errorModel = JsonConvert.DeserializeObject <IdPayErrorModel>(response); return(PaymentVerifyResult.Failed(errorModel.ToString())); } var result = JsonConvert.DeserializeObject <IdPayVerifyResultModel>(response); if (result == null) { return(PaymentVerifyResult.Failed(messagesOptions.InvalidDataReceivedFromGateway)); } if (result.Status.IsNullOrEmpty() || result.TrackId.IsNullOrEmpty()) { return(PaymentVerifyResult.Failed(messagesOptions.InvalidDataReceivedFromGateway)); } if (result.Status != Succeed) { return(PaymentVerifyResult.Failed($"Verification failed. Status: {result.Status}")); } return(PaymentVerifyResult.Succeed(result.TrackId, messagesOptions.PaymentSucceed)); }
public static async Task <PaymentVerifyResult> CreateVerifyResult(HttpResponseMessage responseMessage, MessagesOptions messagesOptions) { var message = await responseMessage.Content.ReadAsStringAsync(); var response = JsonConvert.DeserializeObject <ZibalPaymentVerifyResponseModel>(message); if (response == null) { return(PaymentVerifyResult.Failed(messagesOptions.InvalidDataReceivedFromGateway)); } if (response.Result != SuccessCode) { var verifyResult = PaymentVerifyResult.Failed(response.Message); verifyResult.GatewayResponseCode = response.Result.ToString(); if (response.Result == PaymentAlreadyVerifiedCode) { verifyResult.Status = PaymentVerifyResultStatus.AlreadyVerified; } return(verifyResult); } return(PaymentVerifyResult.Succeed(response.RefNumber.ToString(), messagesOptions.PaymentSucceed)); }
public static PaymentVerifyResult CreateVerifyResult(string response, MessagesOptions messagesOptions) { var result = JsonConvert.DeserializeObject <PayIrVerifyResponseModel>(response); PaymentVerifyResult verifyResult; if (result.IsSucceed) { verifyResult = PaymentVerifyResult.Succeed(result.TransId, messagesOptions.PaymentSucceed); } else { var message = $"ErrorCode: {result.ErrorCode}, ErrorMessage: {result.ErrorMessage}"; verifyResult = PaymentVerifyResult.Failed(message); } var additionalData = new PayIrVerifyAdditionalData { CardNumber = result.CardNumber, FactorNumber = result.FactorNumber, Description = result.Description, Mobile = result.Mobile }; verifyResult.SetPayIrAdditionalData(additionalData); return(verifyResult); }
public static async Task <PaymentVerifyResult> CreateVerifyResult(HttpResponseMessage responseMessage, MessagesOptions optionsMessages) { var message = await responseMessage.Content.ReadAsStringAsync(); var response = JsonConvert.DeserializeObject <ZibalVerifyResponseModel>(message); if (response == null) { return(PaymentVerifyResult.Failed(optionsMessages.InvalidDataReceivedFromGateway)); } if (response.Result != SuccessCode) { var failureMessage = ZibalTranslator.TranslateResult(response.Result) ?? optionsMessages.PaymentFailed; if (response.Status != null) { failureMessage = ZibalTranslator.TranslateStatus((int)response.Status) ?? optionsMessages.PaymentFailed; } return(PaymentVerifyResult.Failed(failureMessage)); } var successMessage = $"{optionsMessages.PaymentSucceed}-status is {response.Result}"; return(PaymentVerifyResult.Succeed(response.RefNumber.ToString(), successMessage)); }
public static PaymentVerifyResult CreateVerifyResult(string response, MessagesOptions messagesOptions) { var result = JsonConvert.DeserializeObject <PayIrVerifyResponseModel>(response); if (!result.IsSucceed) { var message = $"ErrorCode: {result.ErrorCode}, ErrorMessage: {result.ErrorMessage}"; return(PaymentVerifyResult.Failed(message)); } return(PaymentVerifyResult.Succeed(result.TransId, messagesOptions.PaymentSucceed)); }
/// <inheritdoc /> public override async Task <IPaymentVerifyResult> VerifyAsync(InvoiceContext context, CancellationToken cancellationToken = default) { var request = _httpContextAccessor.HttpContext.Request; var callbackResult = await GetCallbackResult(cancellationToken); if (!callbackResult.IsSucceed) { return(PaymentVerifyResult.Failed(callbackResult.Message)); } var transactionCode = await request.TryGetParamAsync("TransactionCode", cancellationToken).ConfigureAwaitFalse(); return(PaymentVerifyResult.Succeed(transactionCode.Value, _messageOptions.Value.PaymentSucceed)); }
public static PaymentVerifyResult CreateVerifyResult(string response, MessagesOptions messagesOptions) { var status = XmlHelper.GetNodeValueFromXml(response, "Status", "http://zarinpal.com/"); var refId = XmlHelper.GetNodeValueFromXml(response, "RefID", "http://zarinpal.com/"); var isSucceed = string.Equals(status, OkResult, StringComparison.InvariantCultureIgnoreCase); if (!isSucceed) { var message = $"Error {status}"; return(PaymentVerifyResult.Failed(message)); } return(PaymentVerifyResult.Succeed(refId, messagesOptions.PaymentSucceed)); }
/// <inheritdoc /> public override async Task <IPaymentVerifyResult> VerifyAsync(InvoiceContext context, CancellationToken cancellationToken = default) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var account = await GetAccountAsync(context.Payment).ConfigureAwaitFalse(); var callbackResult = await PayPingGatewayHelper.GetCallbackResult( _httpContextAccessor.HttpContext.Request, context, _options.Messages, cancellationToken); if (!callbackResult.IsSucceed) { return(PaymentVerifyResult.Failed(callbackResult.Message)); } var verificationModel = PayPingGatewayHelper.CreateVerificationModel(context, callbackResult); _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", account.AccessToken); //Send Verify pay Request var response = await _httpClient.PostJsonAsync(_pingGatewayOptions.ApiVerificationUrl, verificationModel, cancellationToken); //Check if we ran into an Issue if (!response.IsSuccessStatusCode) { return(PaymentVerifyResult.Failed(_options.Messages.PaymentFailed)); } //Get Response data var responseBody = await response.Content.ReadAsStringAsync(); var responseModel = JsonConvert.DeserializeObject <VerifyPayResponseModel>(responseBody); if (responseModel.Amount != (long)context.Payment.Amount) { var message = $"{_options.Messages.PaymentFailed} Amount is not valid."; return(PaymentVerifyResult.Failed(message)); } return(PaymentVerifyResult.Succeed(callbackResult.RefId, _options.Messages.PaymentSucceed)); }
public static async Task <PaymentVerifyResult> CreateVerifyResult(HttpResponseMessage responseMessage, MessagesOptions optionsMessages) { var message = await responseMessage.Content.ReadAsStringAsync(); var response = JsonConvert.DeserializeObject <YekPayVerificationResponseModel>(message); if (response == null) { return(PaymentVerifyResult.Failed(optionsMessages.InvalidDataReceivedFromGateway)); } if (response.Code != SuccessCode) { var failureMessage = response.Description ?? optionsMessages.PaymentFailed; return(PaymentVerifyResult.Failed(failureMessage)); } return(PaymentVerifyResult.Succeed(response.Reference, optionsMessages.PaymentSucceed)); }
public static PaymentVerifyResult CreateVerifyResult(string response, MessagesOptions messagesOptions) { var status = XmlHelper.GetNodeValueFromXml(response, "Status", "http://zarinpal.com/"); var refId = XmlHelper.GetNodeValueFromXml(response, "RefID", "http://zarinpal.com/"); var isSucceed = string.Equals(status, NumericOkResult, StringComparison.OrdinalIgnoreCase); if (!isSucceed) { var message = ZarinPalStatusTranslator.Translate(status, messagesOptions); var verifyResultStatus = string.Equals(status, NumericAlreadyOkResult, StringComparison.OrdinalIgnoreCase) ? PaymentVerifyResultStatus.AlreadyVerified : PaymentVerifyResultStatus.Failed; return(new PaymentVerifyResult { Status = verifyResultStatus, Message = message }); } return(PaymentVerifyResult.Succeed(refId, messagesOptions.PaymentSucceed)); }
/// <inheritdoc /> public override async Task <IPaymentVerifyResult> VerifyAsync(InvoiceContext context, CancellationToken cancellationToken = default) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var account = await GetAccountAsync(context.Payment).ConfigureAwaitFalse(); var request = _httpContextAccessor.HttpContext.Request; var refId = await request.TryGetParamAsync("refid", cancellationToken); var amount = await request.TryGetParamAsAsync <long>("amount", cancellationToken); var clientRefId = await request.TryGetParamAsync("clientrefid", cancellationToken); var isValid = true; var message = ""; if (!refId.Exists) { isValid = false; message += "RefId isn't received."; } if (!amount.Exists) { isValid = false; message += "Amount isn't received."; } if (!clientRefId.Exists) { isValid = false; message += "ClientRefId isn't received."; } else { if (clientRefId.Value != context.Payment.TrackingNumber.ToString()) { isValid = false; message += "ClientRefId isn't valid."; } } if (!isValid) { message = $"{_options.Messages.InvalidDataReceivedFromGateway}{message}"; return(PaymentVerifyResult.Failed(message)); } var verificationModel = new VerifyPayRequestModel { Amount = (long)context.Payment.Amount, RefId = refId.Value }; _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", account.AccessToken); //Send Verify pay Request var response = await _httpClient.PostJsonAsync(_pingGatewayOptions.ApiVerificationUrl, verificationModel, cancellationToken); //Check if we ran into an Issue if (!response.IsSuccessStatusCode) { return(PaymentVerifyResult.Failed(_options.Messages.PaymentFailed)); } //Get Response data var responseBody = await response.Content.ReadAsStringAsync(); var responseModel = JsonConvert.DeserializeObject <VerifyPayResponseModel>(responseBody); if (responseModel.Amount != (long)context.Payment.Amount) { message = $"{_options.Messages.PaymentFailed} Amount is not valid."; return(PaymentVerifyResult.Failed(message)); } return(PaymentVerifyResult.Succeed(refId.Value, _options.Messages.PaymentSucceed)); }