feat(config): add DefaultEmail to configuration files for payment processing
Build and Deploy to Kubernetes / build-and-deploy (push) Failing after 20h51m56s
Build and Deploy to Kubernetes / build-and-deploy (push) Failing after 20h51m56s
- Introduced DefaultEmail field in cms-config.yaml, appsettings.json, and appsettings.Staging.json to standardize email handling in payment requests. - Updated TwentyCardPaymentService to utilize DefaultEmail when no email is provided in the request, enhancing error handling and user experience.
This commit is contained in:
@@ -19,6 +19,7 @@ public class TwentyCardPaymentService : IPaymentGatewayService
|
||||
private readonly string _terminalId;
|
||||
private readonly string _terminalUsername;
|
||||
private readonly string _terminalPassword;
|
||||
private readonly string _defaultEmail;
|
||||
|
||||
private static readonly JsonSerializerOptions JsonOptions = new()
|
||||
{
|
||||
@@ -43,8 +44,11 @@ public class TwentyCardPaymentService : IPaymentGatewayService
|
||||
?? throw new InvalidOperationException("TwentyCard:TerminalUsername is not configured.");
|
||||
_terminalPassword = configuration["TwentyCard:TerminalPassword"]
|
||||
?? throw new InvalidOperationException("TwentyCard:TerminalPassword is not configured.");
|
||||
_defaultEmail = configuration["TwentyCard:DefaultEmail"] ?? "info@kbs2.ir";
|
||||
|
||||
_httpClient.BaseAddress = new Uri(baseUrl.TrimEnd('/') + "/");
|
||||
if (!_httpClient.DefaultRequestHeaders.Contains("Accept"))
|
||||
_httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Accept", "application/json");
|
||||
_logger.LogInformation("TwentyCard payment service initialized. BaseUrl={BaseUrl}", baseUrl);
|
||||
}
|
||||
|
||||
@@ -72,13 +76,13 @@ public class TwentyCardPaymentService : IPaymentGatewayService
|
||||
["mobile"] = request.Mobile ?? string.Empty,
|
||||
["invoice"] = invoice,
|
||||
["callback"] = request.CallbackUrl,
|
||||
["description"] = request.Description ?? string.Empty
|
||||
["description"] = request.Description ?? string.Empty,
|
||||
// بدون email درگاه ۲۰کارت بهجای validation، HTTP 500 برمیگرداند
|
||||
["email"] = ResolveEmail(request.Email)
|
||||
});
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(request.Email))
|
||||
content.Add(new StringContent(request.Email), "email");
|
||||
if (!string.IsNullOrWhiteSpace(request.NationalId))
|
||||
content.Add(new StringContent(request.NationalId), "national_id");
|
||||
AddFormField(content, "national_id", request.NationalId);
|
||||
|
||||
_logger.LogInformation(
|
||||
"TwentyCard payment request: Amount={Amount} Toman, User={UserId}, Invoice={Invoice}",
|
||||
@@ -241,10 +245,27 @@ public class TwentyCardPaymentService : IPaymentGatewayService
|
||||
{
|
||||
var form = new MultipartFormDataContent();
|
||||
foreach (var (key, value) in fields)
|
||||
form.Add(new StringContent(value ?? string.Empty), key);
|
||||
AddFormField(form, key, value ?? string.Empty);
|
||||
return form;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// شبیه curl --form: بدون Content-Type روی هر part ( بعضی بکاندهای PHP با charset=utf-8 میشکنند).
|
||||
/// </summary>
|
||||
private static void AddFormField(MultipartFormDataContent form, string name, string value)
|
||||
{
|
||||
var part = new StringContent(value ?? string.Empty);
|
||||
part.Headers.ContentType = null;
|
||||
form.Add(part, name);
|
||||
}
|
||||
|
||||
private string ResolveEmail(string? email)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(email) && email.Contains('@', StringComparison.Ordinal))
|
||||
return email.Trim();
|
||||
return _defaultEmail;
|
||||
}
|
||||
|
||||
private sealed class TwentyCardRequestResponse
|
||||
{
|
||||
public string? Message { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user