AbstractCoupon implements DiscountInterface
Abstract class for coupon discounts
Attributes
- #[AllowDynamicProperties]
Table of Contents
Interfaces
| DiscountInterface | Discount interface |
Properties
| $date | |
| $fields | |
| $timeStamp |
Methods
| __construct() | Initializes the coupon fields, applying currency, and applicable date |
| active() | Determines whether the coupon is active |
| amount() | Retrieves the amount from the discount that applies for the given currency |
| applies() | Determines whether the coupon applies to the given packages, their options, whether added new or recurring |
| packages() | Retrieves the package IDs of all packages that the coupon supports |
| expired() | Determines whether the coupon has expired for the date given |
| quantityReached() | Determines whether the coupon has reached its quantity limit |
| supportsOptions() | Determines whether the coupon applies to package options |
| supportsPackages() | Determines whether the coupon supports all of the given packages |
| supportsRecurLimits() | Determines whether the coupon requires limitations for recurrences |
| supportsRecurrences() | Determines whether the coupon supports recurrences |
| terms() | Retrieves a list of all coupon terms that the coupon supports |
| validatePackageOptionLimitations() | Validates service options against coupon package option limitations |
Methods
__construct()
Initializes the coupon fields, applying currency, and applicable date
public
__construct(Date $date, ItemInterface $coupon, mixed $timeStamp) : mixed
Parameters
- $date : Date
- $coupon : ItemInterface
-
The coupon item
- $timeStamp : mixed
active()
Determines whether the coupon is active
public
active() : bool
Return values
bool —True if the coupon is active, or false otherwise
amount()
Retrieves the amount from the discount that applies for the given currency
public
amount(mixed $currency) : array<string|int, mixed>
Parameters
- $currency : mixed
-
The ISO 4217 currency code
Return values
array<string|int, mixed> —An array of key/value pairs representing the discount amount for the given currency
applies()
Determines whether the coupon applies to the given packages, their options, whether added new or recurring
public
applies(array<string|int, mixed> $packageIds[, mixed $options = false ][, mixed $recurs = false ]) : bool
Parameters
- $packageIds : array<string|int, mixed>
-
One of the following:
- An array of package IDs that the coupon must apply to
- An array of package IDs mapped to periods and terms [packageID => [period => [term, term]]] that the coupon must apply to
- $options : mixed = false
-
Whether or not the coupon must apply to package options (optional, default false)
- $recurs : mixed = false
-
Whether or not the coupon is being used to recur or not (optional, default false)
Return values
bool —True if the coupon applies, or false otherwise
packages()
Retrieves the package IDs of all packages that the coupon supports
public
packages() : array<string|int, mixed>
Return values
array<string|int, mixed> —An array of package IDs
expired()
Determines whether the coupon has expired for the date given
private
expired() : bool
Return values
bool —True if the coupon is expired, or false otherwise
quantityReached()
Determines whether the coupon has reached its quantity limit
private
quantityReached() : bool
Return values
bool —True if the coupon reached its quantity limit, or false otherwise
supportsOptions()
Determines whether the coupon applies to package options
private
supportsOptions([array<string|int, mixed> $options = null ]) : bool
Parameters
- $options : array<string|int, mixed> = null
-
An array of service options to validate against coupon limitations (optional)
Return values
bool —True if the coupon applies to package options, or false otherwise
supportsPackages()
Determines whether the coupon supports all of the given packages
private
supportsPackages(array<string|int, mixed> $packageIds) : bool
Parameters
- $packageIds : array<string|int, mixed>
-
One of the following:
- An array of package IDs that the coupon must apply to
- An array of package IDs mapped to periods and terms [packageID => [period => [term, term]]] that the coupon must apply to
Return values
bool —True if the coupon applies to all of the given packages, or false otherwise
supportsRecurLimits()
Determines whether the coupon requires limitations for recurrences
private
supportsRecurLimits() : bool
Return values
bool —True if the coupon requires limitations for recurrences, or false otherwise
supportsRecurrences()
Determines whether the coupon supports recurrences
private
supportsRecurrences() : bool
Return values
bool —True if the coupon supports recurrences, or false otherwise
terms()
Retrieves a list of all coupon terms that the coupon supports
private
terms() : array<string|int, mixed>
Return values
array<string|int, mixed> —A list of periods and their supported terms
validatePackageOptionLimitations()
Validates service options against coupon package option limitations
private
validatePackageOptionLimitations() : bool
Return values
bool —True if all package option limitations are met, false otherwise