Files
zemailnator/app/Models/CouponUsage.php
idevakk 27ac13948c feat: implement comprehensive multi-provider payment processing system
- Add unified payment provider architecture with contract-based design
  - Implement 6 payment providers: Stripe, Lemon Squeezy, Polar, Oxapay, Crypto, Activation Keys
  - Create subscription management with lifecycle handling (create, cancel, pause, resume, update)
  - Add coupon system with usage tracking and trial extensions
  - Build Filament admin resources for payment providers, subscriptions, coupons, and trials
  - Implement payment orchestration service with provider registry and configuration management
  - Add comprehensive payment logging and webhook handling for all providers
  - Create customer analytics dashboard with revenue, churn, and lifetime value metrics
  - Add subscription migration service for provider switching
  - Include extensive test coverage for all payment functionality
2025-11-19 09:37:00 -08:00

79 lines
1.5 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class CouponUsage extends Model
{
protected $fillable = [
'coupon_id',
'user_id',
'subscription_id',
'discount_amount',
'currency',
'used_at',
'metadata',
];
protected $casts = [
'discount_amount' => 'decimal:2',
'used_at' => 'datetime',
'metadata' => 'array',
];
protected $dates = [
'used_at',
];
/**
* Relationships
*/
public function coupon()
{
return $this->belongsTo(Coupon::class);
}
public function user()
{
return $this->belongsTo(User::class);
}
public function subscription()
{
return $this->belongsTo(Subscription::class);
}
/**
* Get formatted discount amount
*/
public function getFormattedDiscountAttribute(): string
{
return $this->currency.' '.number_format($this->discount_amount, 2);
}
/**
* Scope: By user
*/
public function scopeByUser($query, $userId)
{
return $query->where('user_id', $userId);
}
/**
* Scope: By coupon
*/
public function scopeByCoupon($query, $couponId)
{
return $query->where('coupon_id', $couponId);
}
/**
* Scope: Within date range
*/
public function scopeBetweenDates($query, $startDate, $endDate)
{
return $query->whereBetween('used_at', [$startDate, $endDate]);
}
}