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.
39 lines
985 B
PHP
39 lines
985 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/**
|
|
* رکورد مصرف کد تخفیف (Audit).
|
|
*
|
|
* هر مصرف موفق یک کد تخفیف روی یک سفارش، یک رکورد در این جدول ثبت میکند.
|
|
* ایندکس یکتا روی (discount_code_id, shipment_id) مصرف دوباره را روی همان
|
|
* سفارش در سطح دیتابیس هم مسدود میکند.
|
|
*/
|
|
class DiscountCodeUsage extends Model
|
|
{
|
|
protected $fillable = [
|
|
'discount_code_id',
|
|
'user_id',
|
|
'shipment_id',
|
|
'discounted_amount',
|
|
];
|
|
|
|
public function discountCode(): BelongsTo
|
|
{
|
|
return $this->belongsTo(DiscountCode::class);
|
|
}
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function shipment(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Shipment::class);
|
|
}
|
|
}
|