コード例 #1
0
 public function validate($target, \FS\Components\Notifier $notifier)
 {
     preg_match('/^\\+?[1]?[-. ]?\\(?([0-9]{3})\\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/', $target, $matches);
     if (!$matches) {
         $notifier->warning('\'' . $target . '\'' . __(' is not a valid phone number.', FLAGSHIP_SHIPPING_TEXT_DOMAIN));
     }
 }
 public function validate($target, \FS\Components\Notifier $notifier)
 {
     $client = $this->getApplicationContext()->getComponent('\\FS\\Components\\Http\\Client');
     $request = array('from' => array('country' => 'CA', 'state' => $target['freight_shipper_state'], 'city' => $target['freight_shipper_city'], 'postal_code' => $target['origin'], 'address' => $target['freight_shipper_street'], 'name' => $target['shipper_company_name'], 'attn' => $target['shipper_person_name'], 'phone' => $target['shipper_phone_number'], 'ext' => $target['shipper_phone_ext']), 'to' => array('name' => 'FLS Integrity Test', 'attn' => 'FLS Guard', 'address' => '148 Brunswick', 'city' => 'POINTE-CLAIRE', 'state' => 'QC', 'country' => 'CA', 'postal_code' => 'H9R5P9', 'phone' => '1 866 320 8383'), 'packages' => array('items' => array(array('width' => 5, 'height' => 4, 'length' => 3, 'weight' => 2, 'description' => 'For WooCommerce Plugin Settings Integrity')), 'units' => 'imperial', 'type' => 'package'), 'payment' => array('payer' => 'F'));
     $response = $client->post('/ship/rates', $request);
     if (!$response->isSuccessful()) {
         $notifier->error(__('<strong>Shipping Integrity Failure:</strong> <br/>', FLAGSHIP_SHIPPING_TEXT_DOMAIN));
         $notifier->reverse_order('error');
     }
     return $target;
 }
コード例 #3
0
 public function validate($target, \FS\Components\Notifier $notifier)
 {
     $client = $this->getApplicationContext()->getComponent('\\FS\\Components\\Http\\Client');
     $response = $client->get('/addresses/integrity', $target);
     $body = $response->getBody();
     if ($response->isSuccessful() && is_array($body) && $body['is_valid']) {
         return $target;
     }
     // the address is not valid but the api provide a correction
     if ($response->isSuccessful() && !$body['is_valid']) {
         $notifier->warning(__('Address corrected to match with shipper\'s postal code.', FLAGSHIP_SHIPPING_TEXT_DOMAIN));
         $target['postal_code'] = $body['postal_code'];
         $target['state'] = $body['state'];
         $target['city'] = $body['city'];
         return $target;
     }
     foreach ($response->getError() as $error) {
         $notifier->warning($error);
     }
     return $target;
 }
コード例 #4
0
 public function validate($target, \FS\Components\Notifier $notifier)
 {
     // if user set/update token, we need to use the latest entered one
     if (isset($target['token'])) {
         $this->getApplicationContext()->getComponent('\\FS\\Components\\Http\\Client')->setToken($target['token']);
     }
     // enabled?
     if ($target['enabled'] != 'yes') {
         $notifier->warning(__('FlagShip Shipping is disabled.', FLAGSHIP_SHIPPING_TEXT_DOMAIN));
     }
     // phone
     $phoneValidator = new PhoneValidator();
     $phoneValidator->validate($target['shipper_phone_number'], $notifier);
     // address
     $addressValidator = $this->getApplicationContext()->getComponent('\\FS\\Components\\Validation\\AddressValidator');
     $address = $addressValidator->validate(array('postal_code' => $target['origin'], 'state' => $target['freight_shipper_state'], 'city' => $target['freight_shipper_city'], 'country' => 'CA'), $notifier);
     $target['origin'] = $address['postal_code'];
     $target['freight_shipper_state'] = $address['state'];
     $target['freight_shipper_city'] = $address['city'];
     // credentials
     if (!$target['shipper_person_name']) {
         $notifier->warning(__('Shipper person name is missing.', FLAGSHIP_SHIPPING_TEXT_DOMAIN));
     }
     if (!$target['shipper_company_name']) {
         $notifier->warning(__('Shipper company name is missing.', FLAGSHIP_SHIPPING_TEXT_DOMAIN));
     }
     if (!$target['shipper_phone_number']) {
         $notifier->warning(__('Shipper phone number is missing.', FLAGSHIP_SHIPPING_TEXT_DOMAIN));
     }
     if (!$target['freight_shipper_street']) {
         $notifier->warning(__('Shipper address\'s streetline is missing.', FLAGSHIP_SHIPPING_TEXT_DOMAIN));
     }
     // overall integrity, send mock quote request
     $integrityValidator = $this->getApplicationContext()->getComponent('\\FS\\Components\\Validation\\SettingsIntegrityValidator');
     $integrityValidator->validate($target, $notifier);
     return $target;
 }