using AIK.Models.ApiModels.Payment; using AIK.ViewModels.Integral; using CommunityToolkit.Mvvm.DependencyInjection; using System; using System.Windows; namespace AIK.Views.MenuPages.Integral { public partial class PaymentQrCodeWindow : Window { private readonly PaymentQrCodeViewModel _viewModel; public PaymentQrCodeWindow(PaymentParametersPC payment, decimal amount, byte[]? qrCodeBytes) { InitializeComponent(); _viewModel = Ioc.Default.GetRequiredService(); _viewModel.PaymentSucceeded += OnPaymentSucceeded; DataContext = _viewModel; _viewModel.Start(payment, amount, qrCodeBytes ?? Array.Empty()); #if !(CN || TEST) PaymentTitleText.Text = "PayPal支付"; QrCodeBorder.Visibility = Visibility.Collapsed; PaypalHintBorder.Visibility = Visibility.Visible; #endif } protected override void OnClosed(EventArgs e) { _viewModel.Stop(); _viewModel.PaymentSucceeded -= OnPaymentSucceeded; base.OnClosed(e); } private void OnPaymentSucceeded() { DialogResult = true; Close(); } private void CloseButton_Click(object sender, RoutedEventArgs e) { #if CN || TEST Close(); #else _viewModel.ReopenPaypal(); #endif } } }