protected function buildSingleExpiryElement() { $this->createExpiryMonthControl(); $this->createExpiryYearControl(); $this->expiryMonthControl->setCssClass("hidden-control"); $this->expiryYearControl->setCssClass("hidden-control"); $month = $this->getSelectedExpiryMonth(); $year = $this->getSelectedExpiryYear(); $defaultValue = ''; if ($month !== null && $year !== null) { $defaultValue = str_replace('YY', $year, $this->getExpiryFieldFormat()); $defaultValue = str_replace('MM', $month, $defaultValue); } $this->expiryControl = new Customweb_Form_Control_TextInput($this->getExpiryFieldName(), $defaultValue); $control = new Customweb_Form_Control_MultiControl('expiration', array($this->expiryControl, $this->expiryMonthControl, $this->expiryYearControl)); $this->expiryElement = new Customweb_Form_Element(Customweb_I18n_Translation::__('Card Expiration'), $control, Customweb_I18n_Translation::__('Enter the date on which your card expires.') . Customweb_I18n_Translation::__(" <span class='card-expiry-format-note'>The expected format is '!format' where the 'MM' means the month number and 'YY' the year number.</span>", array('!format' => $this->getExpiryFieldFormat()))); $this->expiryElement->setElementIntention(Customweb_Form_Intention_Factory::getExpirationDateIntention())->setErrorMessage($this->getExpiryElementErrorMessage()); }
/** * This method creates a expiration element. * A expiration date consists of * two controls for the month and the year. * * @param string $monthFieldName * The field name for the month field. * @param string $yearFieldName * The field name for the year field. * @param string $defaultMonth * The preselected month. Example '05' * @param string $defaultYear * The preselected year. Example '2016' * @deprecated Use instead the Customweb_Payment_Authorization_Method_CreditCard_ElementBuilder * @return Customweb_Form_IElement */ public static function getExpirationElement($monthFieldName, $yearFieldName, $defaultMonth = '', $defaultYear = '', $errorMessage = null, $yearLength = 4) { $months = self::getMonthArray(); $years = array('none' => Customweb_I18n_Translation::__('Year')); $current = intval(date('Y')); for ($i = 0; $i < 15; $i++) { if ($yearLength == 4) { $years[$current] = $current; } else { if ($yearLength == 2) { $years[substr($current, 2, 2)] = $current; } else { throw new Exception("Invalid year length defined for the expiration element."); } } $current++; } if (strlen($defaultYear) == 2 && $yearLength == 4) { // Add the leading year numbers in case it is only 2 chars long $defaultYear = '20' . $defaultYear; } $monthControl = new Customweb_Form_Control_Select($monthFieldName, $months, $defaultMonth); $monthControl->addValidator(new Customweb_Form_Validator_NotEmpty($monthControl, Customweb_I18n_Translation::__("Please select the expiry month on your card."))); $yearControl = new Customweb_Form_Control_Select($yearFieldName, $years, $defaultYear); $yearControl->addValidator(new Customweb_Form_Validator_NotEmpty($yearControl, Customweb_I18n_Translation::__("Please select the expiry year on your card."))); $control = new Customweb_Form_Control_MultiControl('expiration', array($monthControl, $yearControl)); $element = new Customweb_Form_Element(Customweb_I18n_Translation::__('Card Expiration'), $control, Customweb_I18n_Translation::__('Select the date on which your card expires.')); $element->setElementIntention(Customweb_Form_Intention_Factory::getExpirationDateIntention())->setErrorMessage($errorMessage); return $element; }