PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.21
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.21
1.10.25 1.10.24 1.10.23 1.10.22 1.10.21 1.10.20 1.10.19 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 All 169 releases
← All changes | includes/Services/Providers/Star_Online_Adapter.php +40 -1 1.10.2 → 1.10.21 View file →
@@ -7,8 +7,11 @@
7 7
8 8 namespace WCPOS\WooCommercePOS\Services\Providers;
9 9
10 10 use WCPOS\WooCommercePOS\Interfaces\Push_Provider_Adapter_Interface;
11 +use WCPOS\WooCommercePOS\Services\Print_Job_Service;
12 +use WCPOS\WooCommercePOS\Services\Cloud_Print_Trigger_Service;
13 +use WP_Error;
11 14 use WCPOS\WooCommercePOS\Services\Star_Online_Client;
12 15
13 16 /**
14 17 * Star_Online_Adapter class.
@@ -55,9 +58,10 @@
55 58 public function diagnostic( string $printer_name ): array {
56 59 $name = str_replace( array( '[', ']' ), array( '[[', ']]' ), $printer_name );
57 60 $markup = '[align: middle][bold: on]WCPOS[bold: off]' . "\nCloud Print Test\n[align: left]";
58 61 $markup .= 'Printer: ' . $name . "\nDate: " . gmdate( 'Y-m-d H:i' ) . "\n";
59 - $markup .= "If you can read this, printing works!\n[feed][cut]";
62 + // Three feeds before the cut, matching the receipt templates' bottom margin.
63 + $markup .= "If you can read this, printing works!\n[feed][feed][feed][cut]";
60 64
61 65 return array(
62 66 'content_type' => $this->content_type(),
63 67 'payload' => base64_encode( $markup ),
@@ -150,6 +154,41 @@
150 154 'error' => $error,
151 155 'external_job_id' => '',
152 156 'drawer_error' => '',
153 157 );
158 + }
159 +
160 + /**
161 + * Queue a Star Markup test receipt and submit it through the push pipeline.
162 + *
163 + * @param array $printer Registered star-online printer.
164 + *
165 + * @return \WP_REST_Response|WP_Error
166 + */
167 + public function test_print( array $printer ) {
168 + $jobs = new Print_Job_Service();
169 + $diag = $this->diagnostic( (string) $printer['name'] );
170 +
171 + $id = $jobs->create(
172 + array(
173 + 'printer_id' => $printer['id'],
174 + 'content_type' => 'text/vnd.star.markup',
175 + 'payload' => $diag['payload'],
176 + )
177 + );
178 + if ( $id <= 0 ) {
179 + return new WP_Error(
180 + 'wcpos_print_job_create_failed',
181 + __( 'Print job could not be created.', 'woocommerce-pos' ),
182 + array( 'status' => 500 )
183 + );
184 + }
185 +
186 + wp_schedule_single_event( time(), Cloud_Print_Trigger_Service::CRON_SUBMIT, array( $id ) );
187 + ( new \WCPOS\WooCommercePOS\Services\Cloud_Print_Submit_Service() )->submit( $id );
188 +
189 + $response = rest_ensure_response( $jobs->get( $id ) );
190 + $response->set_status( 201 );
191 +
192 + return $response;
154 193 }
155 194 }