ifnex/03_WordPress/wp-content/plugins/ifnex-bridge/includes/api-client.php
Kazem Alghasi b25bfda597 feat(core): enhance order processing and bridge integration
Refactor the order and shipment lifecycle across WordPress and Laravel,
improving multi-package handling, payment automation, and frontend
reliability.

- Laravel:
  - Rename `package_number` to `package_no` and `description` to
    `content_description` in `ShipmentPackage` model and controller.
  - Update `PaymentController` to automatically transition approved
    shipments to `Processed` status upon successful payment.
  - Adjust `OrderPaymentService` to validate against `Approved` status
    instead of `PendingPayment`.
  - Expose `/countries` endpoint as a public route (unauthenticated).
  - Remove obsolete `read_excel.php` utility.

- WordPress (Bridge Plugin & Theme):
  - Implement AJAX handler for wallet-based order payments.
  - Update `ifnex-order-form.js` to support multi-package input names
    and auto-select Iran based on shipment direction.
  - Improve error handling and feedback in the order form and country
    loading logic.
  - Add automatic tracking submission when an `awb` parameter is
    present in the URL.
  - Update CSS with `!important` flags to ensure correct visibility
    of form steps and dashboard elements.
  - Implement cache-busting for plugin assets and prevent OPcache
    stale files via header controls.
  - Optimize theme logo loading with eager loading and explicit
    dimensions.
2026-09-09 12:03:58 +03:30

58 lines
1.6 KiB
PHP

<?php
if (function_exists('opcache_reset')) { @opcache_reset(); }
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
header('Pragma: no-cache');
/**
* IFNEX API Client
* اتصال به API لاراول برای استعلام ترکینگ
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class IFNEX_API_Client {
private $api_url;
private $api_key;
public function __construct() {
$this->api_url = rtrim(get_option('ifnex_api_url', 'http://localhost:8000/api/v1'), '/');
$this->api_key = get_option('ifnex_api_key', '');
}
public function track_shipment($awb_no) {
if (empty($this->api_key)) {
return new WP_Error('no_api_key', 'API Key تنظیم نشده است.');
}
$url = $this->api_url . '/track/' . urlencode($awb_no);
$args = array(
'headers' => array(
'Authorization' => 'Bearer ' . $this->api_key,
'Accept' => 'application/json',
),
'timeout' => 30,
);
$response = wp_remote_get($url, $args);
if (is_wp_error($response)) {
return $response;
}
$body = wp_remote_retrieve_body($response);
$data = json_decode($body, true);
if ($response['response']['code'] === 404) {
return new WP_Error('not_found', 'مرسوله‌ای با این کد پیدا نشد.');
}
if ($response['response']['code'] !== 200) {
return new WP_Error('api_error', 'خطا در ارتباط با API: ' . ($data['message'] ?? 'Unknown error'));
}
return $data;
}
}