/**
  * Build list of required fields
  * TODO: Determine if this ever needs to be overridden per gateway, or if
  * all the per-country / per-gateway cases can be expressed declaratively
  * in payment method / submethod metadata.  If that's the case, move this
  * function (to DataValidator?)
  * @return array of field names (empty if no payment method set)
  */
 public function getRequiredFields()
 {
     $required_fields = array();
     $validation = array();
     // Add any country-specific required fields
     if (isset($this->config['country_fields'])) {
         $country = $this->getData_Unstaged_Escaped('country');
         if ($country && isset($this->config['country_fields'][$country])) {
             $validation = $this->config['country_fields'][$country];
         }
     }
     if ($this->getPaymentMethod()) {
         $methodMeta = $this->getPaymentMethodMeta();
         if (isset($methodMeta['validation'])) {
             $validation = $methodMeta['validation'] + $validation;
         }
     }
     if ($this->getPaymentSubmethod()) {
         $submethodMeta = $this->getPaymentSubmethodMeta();
         if (isset($submethodMeta['validation'])) {
             // submethod validation can override method validation
             // TODO: child method anything should supersede parent method
             // anything, and PaymentMethod should handle that.
             $validation = $submethodMeta['validation'] + $validation;
         }
     }
     foreach ($validation as $type => $enabled) {
         if ($enabled !== true) {
             continue;
         }
         switch ($type) {
             case 'address':
                 $check_not_empty = array('street', 'city', 'country', 'zip');
                 $country = $this->getData_Unstaged_Escaped('country');
                 if ($country && Subdivisions::getByCountry($country)) {
                     $check_not_empty[] = 'state';
                 }
                 break;
             case 'creditCard':
                 $check_not_empty = array('card_num', 'cvv', 'expiration', 'card_type');
                 break;
             case 'name':
                 $check_not_empty = array('fname', 'lname');
                 break;
             default:
                 $check_not_empty = array($type);
                 continue;
         }
         $required_fields = array_unique(array_merge($required_fields, $check_not_empty));
     }
     return $required_fields;
 }
 protected function setStateOptions(&$data)
 {
     $state_list = Subdivisions::getByCountry($data['country']);
     $data['state_options'] = array();
     foreach ($state_list as $abbr => $name) {
         $selected = isset($data['state']) && $data['state'] === $abbr;
         $data['state_options'][] = array('abbr' => $abbr, 'name' => $name, 'selected' => $selected);
     }
 }
예제 #3
0
 /**
  * Get a reference to the ISO-3166-2 (Subdivisions) database singleton.
  *
  * @return \JeremyWorboys\IsoCodes\Subdivisions
  */
 public static function subdivisions()
 {
     return Subdivisions::sharedInstance();
 }