PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.16
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.16
1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 1.9.14 1.9.13 All 162 releases
woocommerce-pos / includes / Services / Fiscal_Receipt_Service.php

Fiscal_Receipt_Service.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.16, at includes/Services/Fiscal_Receipt_Service.php

85 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Fiscal receipt service.
4 *
5 * @package WCPOS\WooCommercePOS\Services
6 */
7
8 namespace WCPOS\WooCommercePOS\Services;
9
10 /**
11 * Fiscal_Receipt_Service class.
12 */
13 class Fiscal_Receipt_Service {
14 /**
15 * Submission status meta key.
16 */
17 const META_KEY_SUBMISSION_STATUS = '_wcpos_receipt_submission_status';
18
19 /**
20 * Submission status updated timestamp meta key.
21 */
22 const META_KEY_STATUS_UPDATED_AT = '_wcpos_receipt_submission_status_updated_at';
23
24 /**
25 * Valid submission statuses.
26 */
27 const VALID_STATUSES = array( 'pending', 'sent', 'failed' );
28
29 /**
30 * Enrich fiscal payload via extension hook.
31 *
32 * @param array $snapshot Fiscal snapshot payload.
33 * @param int $order_id Order ID.
34 *
35 * @return array
36 */
37 public function enrich_snapshot( array $snapshot, int $order_id ): array {
38 $enriched = apply_filters( 'woocommerce_pos_fiscal_snapshot_enrich', $snapshot, $order_id );
39
40 return \is_array( $enriched ) ? $enriched : $snapshot;
41 }
42
43 /**
44 * Persist fiscal submission status.
45 *
46 * @param int $order_id Order ID.
47 * @param string $status Submission status.
48 */
49 public function set_submission_status( int $order_id, string $status ): void {
50 if ( ! in_array( $status, self::VALID_STATUSES, true ) ) {
51 return;
52 }
53
54 update_post_meta( $order_id, self::META_KEY_SUBMISSION_STATUS, $status );
55 update_post_meta( $order_id, self::META_KEY_STATUS_UPDATED_AT, current_time( 'mysql', true ) );
56 }
57
58 /**
59 * Get submission status for an order.
60 *
61 * @param int $order_id Order ID.
62 *
63 * @return string
64 */
65 public function get_submission_status( int $order_id ): string {
66 $status = get_post_meta( $order_id, self::META_KEY_SUBMISSION_STATUS, true );
67
68 if ( in_array( $status, self::VALID_STATUSES, true ) ) {
69 return $status;
70 }
71
72 return 'pending';
73 }
74
75 /**
76 * Trigger retry hook and mark submission pending.
77 *
78 * @param int $order_id Order ID.
79 */
80 public function retry_submission( int $order_id ): void {
81 $this->set_submission_status( $order_id, 'pending' );
82 do_action( 'woocommerce_pos_fiscal_submission_retry', $order_id );
83 }
84 }
85