Add /qr route and refactor payment QR code generation
Introduce a dedicated /qr route for QR code preview via query params. Add PaymentRequest model for payment data and validation, replacing the old inline model. Extract QR code generation to PaymentQrCodeService for reuse. Refactor Home.razor to use new model/service and improve validation/UI. Add EmptyLayout for minimal layout needs. Update .gitignore and _Imports.razor for new structure.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
using QRCoder;
|
||||
using QRPay.Models;
|
||||
|
||||
namespace QRPay.Services;
|
||||
|
||||
public static class PaymentQrCodeService
|
||||
{
|
||||
public static string GenerateDataUri(PaymentRequest paymentRequest)
|
||||
{
|
||||
var payment = new PayBySquareTextGenerator.Payment(
|
||||
paymentRequest.NormalizedIBAN,
|
||||
paymentRequest.Amount ?? 0m,
|
||||
"EUR",
|
||||
"1",
|
||||
paymentRequest.Remark ?? string.Empty);
|
||||
|
||||
payment.ConstantSymbol = "0308";
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(paymentRequest.Name))
|
||||
{
|
||||
payment.BeneficiaryName = paymentRequest.Name;
|
||||
}
|
||||
|
||||
var payBySquare = new PayBySquareTextGenerator.PayBySquareOverkill(payment);
|
||||
var stringData = payBySquare.GeneratePayBySquareOverkillString();
|
||||
|
||||
using var qrCodeData = QRCodeGenerator.GenerateQrCode(stringData, QRCodeGenerator.ECCLevel.Q);
|
||||
using var qrCode = new PngByteQRCode(qrCodeData);
|
||||
var qrCodeImage = qrCode.GetGraphic(10);
|
||||
|
||||
return $"data:image/png;base64,{Convert.ToBase64String(qrCodeImage)}";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user