public function create($token_type = 'DEFAULT', $licensee_number = '', $custom_properties = array()) { $token_type = strtoupper($token_type); if ($token_type != 'DEFAULT' && $token_type != 'SHOP') { throw new NetLicensingException('Wrong token type, expected DEFAULT or SHOP, given ' . $token_type); } if ($custom_properties) { foreach ($custom_properties as $name => $value) { $params[$name] = $value; } } $params['tokenType'] = $token_type; if ($token_type == 'SHOP') { $params['licenseeNumber'] = $licensee_number; } $response = $this->nlic_connect->post($this->_getServiceUrl(), $params); $properties_array = NetLicensingAPI::getPropertiesByXml($response); if (empty($properties_array)) { return FALSE; } $properties = reset($properties_array); $token = $this->_createEntity(); $token->setProperties($properties, TRUE); return $token; }
public function validate($licensee_number, $product_number = '', $license_name = '') { $params = array(); $licensee_number = (string) $licensee_number; if (empty($licensee_number)) { throw new NetLicensingException('Licensee Number cannot be empty'); } //check product number(s) if (!empty($product_number)) { switch (gettype($product_number)) { case 'string': $params['productNumber'] = $product_number; break; case 'array': $count = count($product_number); $index = $count > 1 ? 0 : ''; foreach ($product_number as $number) { switch (gettype($number)) { case 'int': $params['productNumber' . $index] = (string) $number; break; case 'string': $params['productNumber' . $index] = $number; break; case 'object': if ($number instanceof Product) { if (!$number->getOldProperty('number')) { throw new NetLicensingException('Validation error: product number cannot be empty'); } $params['productNumber' . $index] = $number->getOldProperty('number'); } else { throw new NetLicensingException('Validation error: entity ' . get_class($number) . ' is invalid; must be instanceof Product'); } break; default: throw new NetLicensingException('Validation error: product number cannot be ' . gettype($product_number)); break; } if ($count > 1) { $index++; } } break; default: if (!is_string($license_name)) { throw new NetLicensingException('Validation error: wrong product number type provided ' . gettype($product_number)); } break; } } if ($license_name) { if (!is_string($license_name)) { throw new NetLicensingException('Validation error: license name is not string ' . gettype($product_number)); } $params['licenseeName'] = $license_name; } $response = $this->nlic_connect->get($this->_getServiceRequestUrl() . '/' . $licensee_number . '/validate', $params); return NetLicensingAPI::getPropertiesByXml($response); }
protected function _delete($number, NetLicensingAPI $nlic_connect, $force_cascade = FALSE) { $params = array(); $service_url = $this->_getServiceRequestUrl(); if ($force_cascade) { $params['forceCascade'] = TRUE; } $response = $nlic_connect->delete($service_url . '/' . $number, $params); $status_code = $nlic_connect->getHttpStatusCode(); return !empty($status_code) && $status_code == '204' ? TRUE : FALSE; }