| 1 |
<?php |
| 2 |
/** |
| 3 |
* Class Rest_API\Legacy\Label_Service file. |
| 4 |
* |
| 5 |
* @package PostNLWooCommerce\Rest_API\Legacy |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace PostNLWooCommerce\Rest_API\Legacy; |
| 9 |
|
| 10 |
use PostNLWooCommerce\Order\Base as Order_Base; |
| 11 |
use PostNLWooCommerce\Rest_API\Contracts\Label_Service_Interface; |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* Class Label_Service |
| 19 |
* |
| 20 |
* Legacy service wrapper for outbound shipping labels. Implements |
| 21 |
* Label_Service_Interface by delegating to Order\Base::create_label_pipeline() |
| 22 |
* (API request → check_label_and_barcode → put_label_content → |
| 23 |
* maybe_merge_labels) so no label-generation logic is duplicated. |
| 24 |
* |
| 25 |
* @package PostNLWooCommerce\Rest_API\Legacy |
| 26 |
*/ |
| 27 |
class Label_Service extends Order_Base implements Label_Service_Interface { |
| 28 |
|
| 29 |
/** |
| 30 |
* No WP hooks are registered by this service class. |
| 31 |
* |
| 32 |
* Required by Order\Base but intentionally a no-op here. |
| 33 |
*/ |
| 34 |
public function init_hooks() { |
| 35 |
// Intentionally empty — this service does not register WordPress hooks. |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Create a PostNL shipping label and return the normalized label record. |
| 40 |
* |
| 41 |
* Delegates to Order\Base::create_label_pipeline() — not the public |
| 42 |
* create_label() — because this service extends Order\Base and create_label() |
| 43 |
* now routes through the factory; calling it here would recurse. The pipeline |
| 44 |
* runs the full flow: API request → check_label_and_barcode → |
| 45 |
* put_label_content → maybe_merge_labels. The returned array is ready to be |
| 46 |
* stored as _postnl_order_metadata['labels']. |
| 47 |
* |
| 48 |
* @param array $post_data Context needed to build and send the label request. |
| 49 |
* |
| 50 |
* @return array Normalized label record keyed by label-type string. |
| 51 |
* |
| 52 |
* @throws \Exception If the API request fails or the label array is empty. |
| 53 |
*/ |
| 54 |
public function create( array $post_data ): array { |
| 55 |
return $this->create_label_pipeline( $post_data ); |
| 56 |
} |
| 57 |
} |
| 58 |
|