+sub _maybe_attach_zugferd_data {
+ my ($record) = @_;
+
+ return if !blessed($record)
+ || !$record->can('customer')
+ || !$record->customer
+ || !$record->can('create_pdf_a_print_options')
+ || !$record->can('create_zugferd_data')
+ || !$record->customer->create_zugferd_invoices_for_this_customer;
+
+ my $xmlfile = File::Temp->new;
+ $xmlfile->print($record->create_zugferd_data);
+ $xmlfile->close;
+
+ my %driver_options = (
+ pdf_a => $record->create_pdf_a_print_options(zugferd_xmp_data => $record->create_zugferd_xmp_data),
+ pdf_attachments => [
+ { source => $xmlfile,
+ name => 'ZUGFeRD-invoice.xml',
+ description => $::locale->text('ZUGFeRD invoice'),
+ relationship => '/Alternative',
+ mime_type => 'text/xml',
+ }
+ ],
+ );
+
+ return %driver_options;
+}
+