Implement critical security hardening and resolve a P0 bug in the discount code consumption flow. This update transitions the system from a development-heavy configuration to a production-ready state. Key changes: - Fix P0 bug where `consumeDiscountCode()` was missing, breaking order registration; replaced with a robust `DiscountCodeService` using `discount_code_usages` for audit trails and idempotency. - Implement strict production guards for the Zarinpal payment gateway to prevent accidental mock processing in live environments. - Refactor WordPress bridge asset management to use `filemtime` based versioning instead of `time()` to prevent unnecessary cache busting. - Remove debug-only hacks (`opcache_reset`, `header` cache control) from the WordPress plugin. - Enhance file upload security by enforcing strict `mimetypes` validation. - Update `.gitignore` to exclude sensitive WordPress configuration files and local PHPUnit caches. - Add comprehensive documentation for production deployment, including security checklists and key rotation procedures. - Update test suite to reflect new architecture and ensure 100% coverage of the discount service.
55 lines
1.5 KiB
PHP
55 lines
1.5 KiB
PHP
<?php
|
|
/**
|
|
* 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;
|
|
}
|
|
}
|