← All changes
|
includes/Services/Providers/Star_Online_Adapter.php
+38
-0
1.10.8
→
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. |
| @@ -151,6 +154,41 @@ | ||
| 151 | 154 | 'error' => $error, |
| 152 | 155 | 'external_job_id' => '', |
| 153 | 156 | 'drawer_error' => '', |
| 154 | 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; | |
| 155 | 193 | } |
| 156 | 194 | } |