|
|
@@ -20,6 +20,7 @@ public class InvoiceModel : PageModel |
|
|
private readonly DonateCodeApiOptions _donateCodeApiOptions; |
|
|
private readonly DonateCodeApiOptions _donateCodeApiOptions; |
|
|
private const string ServiceName = "NtuInvoiceGateway"; |
|
|
private const string ServiceName = "NtuInvoiceGateway"; |
|
|
private const string DonateCodeCacheKey = "DonateCodeList"; |
|
|
private const string DonateCodeCacheKey = "DonateCodeList"; |
|
|
|
|
|
private const string InvoiceDataTempKey = "InvoiceFormData"; |
|
|
|
|
|
|
|
|
public InvoiceModel( |
|
|
public InvoiceModel( |
|
|
ILogger<InvoiceModel> logger, |
|
|
ILogger<InvoiceModel> logger, |
|
|
@@ -52,11 +53,17 @@ public class InvoiceModel : PageModel |
|
|
|
|
|
|
|
|
public void OnGet() |
|
|
public void OnGet() |
|
|
{ |
|
|
{ |
|
|
|
|
|
RestoreInvoiceDataFromTempData(); |
|
|
RestoreDisplayValuesFromTempData(); |
|
|
RestoreDisplayValuesFromTempData(); |
|
|
NormalizeInvoiceData(); |
|
|
NormalizeInvoiceData(); |
|
|
// 如果有 GET 參數,設置顯示資訊 |
|
|
// 如果有 GET 參數,設置顯示資訊 |
|
|
DisplayTransDateTime = InvoiceData.TransDateTime; |
|
|
DisplayTransDateTime = InvoiceData.TransDateTime; |
|
|
DisplayTransAmount = InvoiceData.TransAmount; |
|
|
DisplayTransAmount = InvoiceData.TransAmount; |
|
|
|
|
|
|
|
|
|
|
|
if (!Request.Query.Any()) |
|
|
|
|
|
{ |
|
|
|
|
|
ModelState.Clear(); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public async Task<IActionResult> OnGetDonateCodesAsync() |
|
|
public async Task<IActionResult> OnGetDonateCodesAsync() |
|
|
@@ -280,6 +287,7 @@ public class InvoiceModel : PageModel |
|
|
SuccessMessage = "發票資訊送出成功!"; |
|
|
SuccessMessage = "發票資訊送出成功!"; |
|
|
TempData[nameof(DisplayTransDateTime)] = DisplayTransDateTime; |
|
|
TempData[nameof(DisplayTransDateTime)] = DisplayTransDateTime; |
|
|
TempData[nameof(DisplayTransAmount)] = DisplayTransAmount; |
|
|
TempData[nameof(DisplayTransAmount)] = DisplayTransAmount; |
|
|
|
|
|
TempData[InvoiceDataTempKey] = JsonSerializer.Serialize(InvoiceData); |
|
|
_logger.LogInformation("{ServiceName} - {ActionName} submitted successfully for OrderID: {OrderID}", |
|
|
_logger.LogInformation("{ServiceName} - {ActionName} submitted successfully for OrderID: {OrderID}", |
|
|
ServiceName, actionName, InvoiceData.OrderID); |
|
|
ServiceName, actionName, InvoiceData.OrderID); |
|
|
return RedirectToPage(); |
|
|
return RedirectToPage(); |
|
|
@@ -337,4 +345,32 @@ public class InvoiceModel : PageModel |
|
|
DisplayTransAmount = amount; |
|
|
DisplayTransAmount = amount; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void RestoreInvoiceDataFromTempData() |
|
|
|
|
|
{ |
|
|
|
|
|
if (!TempData.TryGetValue(InvoiceDataTempKey, out var invoiceDataObj) || |
|
|
|
|
|
invoiceDataObj is not string invoiceDataJson || |
|
|
|
|
|
string.IsNullOrWhiteSpace(invoiceDataJson)) |
|
|
|
|
|
{ |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
|
|
|
var restoredData = JsonSerializer.Deserialize<InvoiceRequest>(invoiceDataJson, new JsonSerializerOptions |
|
|
|
|
|
{ |
|
|
|
|
|
PropertyNameCaseInsensitive = true |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
if (restoredData != null) |
|
|
|
|
|
{ |
|
|
|
|
|
InvoiceData = restoredData; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
catch (JsonException ex) |
|
|
|
|
|
{ |
|
|
|
|
|
_logger.LogWarning(ex, "{ServiceName} - {ActionName} failed to restore invoice data from temp data", |
|
|
|
|
|
ServiceName, nameof(RestoreInvoiceDataFromTempData)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |