| 1 |
<?php |
| 2 |
/** |
| 3 |
* Class Rest_API\Legacy\Letterbox_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 Letterbox_Service |
| 19 |
* |
| 20 |
* Legacy service wrapper for letterbox parcel labels. Implements |
| 21 |
* Label_Service_Interface by delegating to |
| 22 |
* Order\Base::maybe_create_letterbox_pipeline() which runs the full Letterbox |
| 23 |
* pipeline (API request → put_label_content → maybe_merge_labels with type |
| 24 |
* 'letterbox'). |
| 25 |
* |
| 26 |
* @package PostNLWooCommerce\Rest_API\Legacy |
| 27 |
*/ |
| 28 |
class Letterbox_Service extends Order_Base implements Label_Service_Interface { |
| 29 |
|
| 30 |
/** |
| 31 |
* No WP hooks are registered by this service class. |
| 32 |
* |
| 33 |
* Required by Order\Base but intentionally a no-op here. |
| 34 |
*/ |
| 35 |
public function init_hooks() { |
| 36 |
// Intentionally empty — this service does not register WordPress hooks. |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Create a PostNL letterbox label and return the normalized label record. |
| 41 |
* |
| 42 |
* Delegates to Order\Base::maybe_create_letterbox_pipeline() — not the public |
| 43 |
* maybe_create_letterbox() — because this service extends Order\Base and that |
| 44 |
* public method now routes through the factory; calling it here would recurse. |
| 45 |
* The pipeline uses the Letterbox\Client and returns the normalized labels |
| 46 |
* array ready to be stored as _postnl_order_metadata['labels']. |
| 47 |
* |
| 48 |
* Callers must ensure $post_data['saved_data']['backend']['letterbox'] === 'yes' |
| 49 |
* so the pipeline guard inside maybe_create_letterbox_pipeline() does not short-circuit. |
| 50 |
* |
| 51 |
* @param array $post_data Context needed to build and send the letterbox request. |
| 52 |
* |
| 53 |
* @return array Normalized label record keyed by 'letterbox'. |
| 54 |
* |
| 55 |
* @throws \Exception If the API request fails or the label array is empty. |
| 56 |
*/ |
| 57 |
public function create( array $post_data ): array { |
| 58 |
return $this->maybe_create_letterbox_pipeline( $post_data ); |
| 59 |
} |
| 60 |
} |
| 61 |
|