AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Subscription.php 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace App\Models;
  3. use Carbon\CarbonInterface;
  4. use Database\Factories\SubscriptionFactory;
  5. use Illuminate\Database\Eloquent\Factories\HasFactory;
  6. use Illuminate\Database\Eloquent\Model;
  7. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  8. /**
  9. * A merchant's paid plan, kept in step with Stripe.
  10. *
  11. * @property int $id
  12. * @property int $user_id
  13. * @property int|null $plan_id
  14. * @property string|null $stripe_customer_id
  15. * @property string|null $stripe_subscription_id
  16. * @property string|null $status
  17. * @property CarbonInterface|null $current_period_end
  18. * @property bool $cancel_at_period_end
  19. * @property-read Plan|null $plan
  20. * @property-read User $user
  21. */
  22. class Subscription extends Model
  23. {
  24. /** @use HasFactory<SubscriptionFactory> */
  25. use HasFactory;
  26. /**
  27. * Stripe states in which the merchant keeps their plan.
  28. * "past_due" is included: a card failed, and Stripe is still retrying it.
  29. *
  30. * @var list<string>
  31. */
  32. public const array ACTIVE_STATUSES = ['active', 'trialing', 'past_due'];
  33. /**
  34. * @return BelongsTo<User, $this>
  35. */
  36. public function user(): BelongsTo
  37. {
  38. return $this->belongsTo(User::class);
  39. }
  40. /**
  41. * @return BelongsTo<Plan, $this>
  42. */
  43. public function plan(): BelongsTo
  44. {
  45. return $this->belongsTo(Plan::class);
  46. }
  47. public function isActive(): bool
  48. {
  49. return $this->plan_id !== null && in_array($this->status, self::ACTIVE_STATUSES, true);
  50. }
  51. /**
  52. * @return array<string, string>
  53. */
  54. protected function casts(): array
  55. {
  56. return [
  57. 'current_period_end' => 'datetime',
  58. 'cancel_at_period_end' => 'boolean',
  59. ];
  60. }
  61. }