public function Charge::__construct in Commerce Recurring Framework 8
Constructs a new Charge object.
Parameters
array $definition: The definition.
File
- src/
Charge.php, line 65
Class
- Charge
- Represents a charge.
Namespace
Drupal\commerce_recurringCode
public function __construct(array $definition) {
foreach ([
'title',
'unit_price',
'billing_period',
'full_billing_period',
] as $required_property) {
if (empty($definition[$required_property])) {
throw new \InvalidArgumentException(sprintf('Missing required property "%s".', $required_property));
}
}
if (isset($definition['purchased_entity']) && !$definition['purchased_entity'] instanceof PurchasableEntityInterface) {
throw new \InvalidArgumentException(sprintf('The "purchased_entity" property must be an instance of %s.', PurchasableEntityInterface::class));
}
if (!$definition['unit_price'] instanceof Price) {
throw new \InvalidArgumentException(sprintf('The "unit_price" property must be an instance of %s.', Price::class));
}
if (!$definition['billing_period'] instanceof BillingPeriod) {
throw new \InvalidArgumentException(sprintf('The "billing_period" property must be an instance of %s.', BillingPeriod::class));
}
if (!$definition['full_billing_period'] instanceof BillingPeriod) {
throw new \InvalidArgumentException(sprintf('The "full_billing_period" property must be an instance of %s.', BillingPeriod::class));
}
$this->purchasedEntity = isset($definition['purchased_entity']) ? $definition['purchased_entity'] : NULL;
$this->title = $definition['title'];
$this->quantity = isset($definition['quantity']) ? $definition['quantity'] : '1';
$this->unitPrice = $definition['unit_price'];
$this->billingPeriod = $definition['billing_period'];
$this->fullBillingPeriod = $definition['full_billing_period'];
}