label).' '.$this->getMetaData('code'); } #[Override] public function getValue(): int|float { return 0 - $this->calculatedValue; } public function getModel() {} public function onLoad(): void { $giftupCode = (string)$this->getMetaData('code'); if ($giftupCode === '') { return; } try { $manager = resolve(Manager::class); // Get gift card by code $giftCard = $manager->fetchGiftCard($giftupCode); $manager->validateGiftCard($giftCard); $cartSubtotal = Cart::content()->subtotalWithoutConditions(); $this->giftCardValue = min($cartSubtotal, $giftCard->remainingValue); } catch (Exception $ex) { flash()->alert($ex->getMessage())->now(); $this->removeMetaData('code'); } } public function beforeApply(): ?false { return $this->giftCardValue ? null : false; } #[Override] public function getActions(): array { $actions = [ 'value' => 0 - $this->giftCardValue, ]; return [$actions]; } }