← All changes
|
includes/Services/Providers/Printnode_Adapter.php
+0
-61
1.10.18
→
1.10.17
View file →
| @@ -7,11 +7,8 @@ | ||
| 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\Logger; | |
| 12 | -use WP_Error; | |
| 13 | -use WP_REST_Response; | |
| 14 | 11 | use WCPOS\WooCommercePOS\Services\Pdf_Renderer; |
| 15 | 12 | use WCPOS\WooCommercePOS\Services\Print_Job_Service; |
| 16 | 13 | use WCPOS\WooCommercePOS\Services\PrintNode_Client; |
| 17 | 14 | |
| @@ -183,64 +180,6 @@ | ||
| 183 | 180 | private function drawer_kick_bytes( string $connector ): string { |
| 184 | 181 | $pin = 'pin5' === Print_Job_Service::normalize_drawer_connector( $connector ) ? "\x01" : "\x00"; |
| 185 | 182 | |
| 186 | 183 | return "\x1B\x70" . $pin . "\x19\xFA"; |
| 187 | - } | |
| 188 | - | |
| 189 | - /** | |
| 190 | - * Submit a diagnostic PDF to a PrintNode printer. | |
| 191 | - * | |
| 192 | - * @param array $printer Registered PrintNode printer. | |
| 193 | - * | |
| 194 | - * @return \WP_REST_Response|WP_Error | |
| 195 | - */ | |
| 196 | - public function test_print( array $printer ) { | |
| 197 | - $api_key = (string) ( $printer['printnode_api_key'] ?? '' ); | |
| 198 | - $pn_printer_id = (int) ( $printer['printnode_printer_id'] ?? 0 ); | |
| 199 | - if ( '' === $api_key || 0 === $pn_printer_id ) { | |
| 200 | - return new WP_Error( | |
| 201 | - 'wcpos_print_job_printnode_unconfigured', | |
| 202 | - __( 'This PrintNode printer is missing its API key or printer id.', 'woocommerce-pos' ), | |
| 203 | - array( 'status' => 400 ) | |
| 204 | - ); | |
| 205 | - } | |
| 206 | - | |
| 207 | - try { | |
| 208 | - $pdf = base64_decode( $this->diagnostic( (string) $printer['name'] )['payload'], true ); | |
| 209 | - } catch ( \Throwable $e ) { | |
| 210 | - // Defense in depth: a Dompdf/font-cache/temp-dir failure must not | |
| 211 | - // surface as an uncaught 500. Mirror the render_payload() guard. | |
| 212 | - Logger::log( 'Cloud print: PrintNode diagnostic PDF render failed: ' . $e->getMessage() ); | |
| 213 | - | |
| 214 | - return new WP_Error( | |
| 215 | - 'wcpos_print_job_diagnostic_failed', | |
| 216 | - __( 'Could not generate the test print.', 'woocommerce-pos' ), | |
| 217 | - array( 'status' => 500 ) | |
| 218 | - ); | |
| 219 | - } | |
| 220 | - | |
| 221 | - $result = ( new PrintNode_Client( $api_key ) )->submit_job( | |
| 222 | - $pn_printer_id, | |
| 223 | - 'WCPOS Test Print', | |
| 224 | - 'pdf_base64', | |
| 225 | - base64_encode( $pdf ) | |
| 226 | - ); | |
| 227 | - | |
| 228 | - if ( is_wp_error( $result ) ) { | |
| 229 | - return new WP_Error( | |
| 230 | - 'wcpos_print_job_printnode_failed', | |
| 231 | - $result->get_error_message(), | |
| 232 | - array( 'status' => 502 ) | |
| 233 | - ); | |
| 234 | - } | |
| 235 | - | |
| 236 | - return new WP_REST_Response( | |
| 237 | - array( | |
| 238 | - 'submitted' => true, | |
| 239 | - 'external_provider' => 'printnode', | |
| 240 | - 'external_job_id' => (string) $result['id'], | |
| 241 | - 'external_state' => 'submitted', | |
| 242 | - ), | |
| 243 | - 201 | |
| 244 | - ); | |
| 245 | 184 | } |
| 246 | 185 | } |