← 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 | } |