| 1 |
<?php |
| 2 |
/** |
| 3 |
* Receipt payload assembler service. |
| 4 |
* |
| 5 |
* @package WCPOS\WooCommercePOS\Services |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WCPOS\WooCommercePOS\Services; |
| 9 |
|
| 10 |
/** |
| 11 |
* Receipt_Payload_Assembler class. |
| 12 |
*/ |
| 13 |
class Receipt_Payload_Assembler { |
| 14 |
|
| 15 |
/** |
| 16 |
* Assemble receipt sections in canonical payload order. |
| 17 |
* |
| 18 |
* @param array<string,mixed> $sections Already-computed receipt sections. |
| 19 |
* |
| 20 |
* @return array<string,mixed> |
| 21 |
*/ |
| 22 |
public static function assemble( array $sections ): array { |
| 23 |
return array( |
| 24 |
'order' => $sections['order'], |
| 25 |
'store' => $sections['store'], |
| 26 |
'cashier' => $sections['cashier'], |
| 27 |
'customer' => $sections['customer'], |
| 28 |
'lines' => $sections['lines'], |
| 29 |
'fees' => $sections['fees'], |
| 30 |
'shipping' => $sections['shipping'], |
| 31 |
'discounts' => $sections['discounts'], |
| 32 |
'totals' => $sections['totals'], |
| 33 |
'tax' => $sections['tax'], |
| 34 |
'tax_summary' => $sections['tax_summary'], |
| 35 |
'has_tax_summary' => ! empty( $sections['tax_summary'] ), |
| 36 |
'payments' => $sections['payments'], |
| 37 |
'refunds' => $sections['refunds'], |
| 38 |
'fiscal' => $sections['fiscal'], |
| 39 |
'presentation_hints' => $sections['presentation_hints'], |
| 40 |
'i18n' => Receipt_I18n_Labels::get_labels( $sections['presentation_hints']['locale'] ?? '' ), |
| 41 |
); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Assemble fiscal values in canonical section order. |
| 46 |
* |
| 47 |
* @param array<string,mixed> $values Already-computed fiscal values. |
| 48 |
* |
| 49 |
* @return array<string,mixed> |
| 50 |
*/ |
| 51 |
public static function fiscal( array $values ): array { |
| 52 |
return array( |
| 53 |
'immutable_id' => $values['immutable_id'], |
| 54 |
'receipt_number' => $values['receipt_number'], |
| 55 |
'sequence' => $values['sequence'], |
| 56 |
'hash' => $values['hash'], |
| 57 |
'qr_payload' => $values['qr_payload'], |
| 58 |
'tax_agency_code' => $values['tax_agency_code'], |
| 59 |
'signed_at' => $values['signed_at'], |
| 60 |
'signature_excerpt' => $values['signature_excerpt'], |
| 61 |
'document_label' => $values['document_label'], |
| 62 |
'is_reprint' => $values['is_reprint'], |
| 63 |
'reprint_count' => $values['reprint_count'], |
| 64 |
'extra_fields' => $values['extra_fields'], |
| 65 |
); |
| 66 |
} |
| 67 |
} |
| 68 |
|