PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.11
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.11
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 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 1.9.14 All 163 releases
woocommerce-pos / includes / Services / Cloud_Print_Diagnostic.php

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

73 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Builds cloud-print test/diagnostic payloads per provider.
4 *
5 * @package WCPOS\WooCommercePOS\Services
6 */
7
8 namespace WCPOS\WooCommercePOS\Services;
9
10 /**
11 * Cloud_Print_Diagnostic class.
12 */
13 class Cloud_Print_Diagnostic {
14 /**
15 * Build a base64 diagnostic payload + content type for a provider.
16 *
17 * @param string $provider Provider key.
18 * @param string $printer_name Display name.
19 *
20 * @return array{content_type:string, payload:string}
21 *
22 * @throws \RuntimeException When the provider has no server-side diagnostic.
23 */
24 public function build( string $provider, string $printer_name ): array {
25 if ( ! Provider::supports_server_diagnostic( $provider ) ) {
26 throw new \RuntimeException( esc_html( 'No server-side diagnostic for provider: ' . $provider ) );
27 }
28
29 $adapter = Provider::adapter( $provider );
30 if ( null === $adapter ) {
31 throw new \RuntimeException( esc_html( 'Unknown cloud-print provider: ' . $provider ) );
32 }
33
34 return $adapter->diagnostic( $printer_name );
35 }
36
37 /**
38 * Build a PrintNode diagnostic receipt as PDF bytes.
39 *
40 * @param string $printer_name Display name.
41 *
42 * @throws \RuntimeException When the PrintNode adapter cannot be resolved.
43 *
44 * @return string PDF document bytes.
45 */
46 public function build_pdf( string $printer_name ): string {
47 $adapter = Provider::adapter( 'printnode' );
48 if ( null === $adapter ) {
49 throw new \RuntimeException( esc_html( 'Unknown cloud-print provider: printnode' ) );
50 }
51
52 return base64_decode( $adapter->diagnostic( $printer_name )['payload'], true );
53 }
54
55 /**
56 * Build a Star Document Markup diagnostic receipt.
57 *
58 * @param string $printer_name Display name.
59 *
60 * @throws \RuntimeException When the Star Online adapter cannot be resolved.
61 *
62 * @return string Star Document Markup source.
63 */
64 public function star_markup( string $printer_name ): string {
65 $adapter = Provider::adapter( 'star-online' );
66 if ( null === $adapter ) {
67 throw new \RuntimeException( esc_html( 'Unknown cloud-print provider: star-online' ) );
68 }
69
70 return base64_decode( $adapter->diagnostic( $printer_name )['payload'], true );
71 }
72 }
73