payment_active == 'yes' || $this->payment_active == 'yes_save'; } public function isPaymentToCapture() { return $this->payment_active == 'yes_save'; } public function getPaymentRules() { $rules = $this->payment_rules; if (is_array($rules)) { return $rules; } return []; } /** * Backwards-compatible wrapper around the shared schedule-rule matcher. * * @param $rule * @param $date (is included in the shift valid dates) * @param $time * * @return bool */ public function isRuleMatch($rule, $date, $time) { return $this->matchesScheduleRule($rule, $date, $time); } public function getRulePrice($rule, $party) { if (!isset($rule['payment_type'])) return 0; $payment_type = $rule['payment_type']; if ($payment_type == 'fixed') { return isset($rule['price_fixed']) ? floatval($rule['price_fixed']) : 0; } if ($payment_type == 'per_seat') { return isset($rule['price_per_seat']) ? intval($party) * floatval($rule['price_per_seat']) : 0; } if ($payment_type == 'variable') { if (!isset($rule['price_variable'])) return 0; $prices = $rule['price_variable']; if (!is_array($prices)) return 0; $index = intval($party)-1; if ($index <= 0) return 0; if (isset($prices[$index])) { return floatval($prices[$index]); } return floatval($prices[count($prices)-1]); } return 0; } public function getPaymentAmountForBooking($booking, $menu_subtotal = 0) { // When booking has a persisted offer menu selection, use its // authoritative server-side subtotal. Caller can also pass it in. if ($menu_subtotal <= 0) { $settings = $booking->settings; if (is_array($settings) && isset($settings['offer_menu']['subtotal'])) { $menu_subtotal = floatval($settings['offer_menu']['subtotal']); } } return $this->getPaymentAmount($booking->date, $booking->time, $booking->party, $menu_subtotal); } public function getPaymentRule($booking) { $this->getPaymentAmountForBooking($booking); return $this->rule_matched; } public function getPaymentMessage() { $message = ''; if ($this->rule_matched && isset($this->rule_matched['description'])) { $message = $this->rule_matched['description']; } if (empty($message)) { //$message = __eva('To secure your reservation, we kindly ask for a prepayment.').'
' // .__eva('Your booking will be confirmed once the payment is successful.'); $message = [ __eva('To secure your reservation, we kindly ask for a prepayment.'), __eva('Your booking will be confirmed once the payment is successful.') ]; } return $message; } /** * Get the price for a date, time and party * Retun 0 means no payment * * Offers rules (when present and matching) override payment rules. * * @param $date * @param $time * @param $party * * @return float|int */ public function getPaymentAmount($date, $time, $party, $menu_subtotal = 0) { if (!defined('ALEXR_PRO_VERSION')) return 0; // Offers rules win when they match. Their payment_required value is authoritative. $offer_rule = $this->getOfferRuleMatched($date, $time, $party); if ($offer_rule !== null) { $this->rule_matched = $offer_rule; $required = isset($offer_rule['payment_required']) ? $offer_rule['payment_required'] : 'no'; if ($required === 'no') { return 0; } return $this->getOfferRulePrice($offer_rule, $party, $menu_subtotal); } if (!$this->isPaymentActive()) return 0; foreach($this->getPaymentRules() as $rule) { if ($this->isRuleMatch($rule, $date, $time)) { $this->rule_matched = $rule; return $this->getRulePrice($rule, $party); } } $this->rule_matched = null; return 0; } public function isPaymentRequiredForDateTime($date, $time, $party = null) { if (!defined('ALEXR_PRO_VERSION')) return 0; // Offers rules win when they match. Their payment_required value is authoritative. $offer_rule = $this->getOfferRuleMatched($date, $time, $party); if ($offer_rule !== null) { $required = isset($offer_rule['payment_required']) ? $offer_rule['payment_required'] : 'no'; return $required === 'yes' || $required === 'yes_save'; } if (!$this->isPaymentActive()) return 0; foreach($this->getPaymentRules() as $rule) { if ($this->isRuleMatch($rule, $date, $time)) { return true; } } return false; } }