Ejemplo n.º 1
0
 /**
  * @param  Doctrine\Common\Collections\Collection                   $collection
  * @throws AntiMattr\Sears\Exception\Connection\ConnectionException
  * @throws AntiMattr\Sears\Exception\Http\BadRequestException
  * @throws AntiMattr\Sears\Exception\IntegrationException
  */
 public function updateShipments(Collection $collection)
 {
     $handler = $this->requestHandlerFactory->createRequestHandler('updateShipments');
     $resource = sprintf('/SellerPortal/api/oms/asn/v5?email=%s&password=%s', 'xxxxxx', 'yyyyyy');
     $request = $this->messageFactory->createRequest('PUT', $resource, 'http://www.example.com');
     $integrationException = null;
     try {
         $handler->bindCollection($request, $collection);
     } catch (IntegrationException $e) {
         $integrationException = $e;
     }
     $requestString = $request->__toString();
     $this->log($requestString);
     $response = $this->messageFactory->createResponse();
     $response->addHeader('1.0 200 OK');
     if (!empty($this->headers)) {
         $response->addHeaders($this->headers);
     }
     if ('' != $this->content) {
         $response->setContent($this->content);
     }
     $responseString = $response->__toString();
     $this->log($responseString);
     $this->reset();
     if ($integrationException) {
         throw $integrationException;
     }
 }
Ejemplo n.º 2
0
 /**
  * @param  Doctrine\Common\Collections\Collection                   $collection
  * @throws AntiMattr\Sears\Exception\Connection\ConnectionException
  * @throws AntiMattr\Sears\Exception\Http\BadRequestException
  * @throws AntiMattr\Sears\Exception\IntegrationException
  */
 public function updateShipments(Collection $collection)
 {
     $handler = $this->requestHandlerFactory->createRequestHandler('updateShipments');
     $resource = sprintf('/SellerPortal/api/oms/asn/v5?email=%s&password=%s', $this->email, $this->password);
     $request = $this->messageFactory->createRequest('PUT', $resource, $this->host);
     $integrationException = null;
     try {
         $handler->bindCollection($request, $collection);
     } catch (IntegrationException $e) {
         $integrationException = $e;
     }
     $this->updateHeaders($request);
     $requestString = $request->__toString();
     $this->log($requestString);
     $response = $this->messageFactory->createResponse();
     try {
         $this->buzz->send($request, $response);
     } catch (ClientException $e) {
         $subject = $e->getMessage();
         throw new ConnectionException($subject);
     }
     $responseString = $response->__toString();
     $this->log($responseString);
     if ($integrationException) {
         throw $integrationException;
     }
 }
Ejemplo n.º 3
0
 /**
  * @param Doctrine\Common\Collections\Collection       $products
  * @param AntiMattr\Twitter\Marketplace\Model\Merchant $merchant
  * @param int                                          $attempt
  *
  * @throws AntiMattr\Twitter\Marketplace\Exception\AbstractAuthException
  * @throws AntiMattr\Twitter\Marketplace\Exception\ConnectionException
  * @throws AntiMattr\Twitter\Marketplace\Exception\Http\BadRequestException
  * @throws AntiMattr\Twitter\Marketplace\Exception\Http\InternalErrorException
  * @throws AntiMattr\Twitter\Marketplace\Exception\Http\NotFoundException
  * @throws AntiMattr\Twitter\Marketplace\Exception\Http\UnauthorizedException
  * @throws AntiMattr\Twitter\Marketplace\Exception\IntegrationException
  */
 public function updateProducts(Collection $products, Merchant $merchant, $attempt = 1)
 {
     $this->checkMerchantCredentials($merchant);
     $oAuth = $merchant->getOAuth();
     $consumerKey = $oAuth->getConsumerKey();
     $consumerSecret = $oAuth->getConsumerSecret();
     $oAuthToken = $oAuth->getOAuthToken();
     $oAuthTokenSecret = $oAuth->getOAuthTokenSecret();
     $this->checkAccountId($merchant);
     $resource = sprintf("/1.1/commerce/accounts/%s/item_urls/", $merchant->getAccountId());
     $request = $this->messageFactory->createFormRequest('PUT', $resource, $this->host);
     $response = $this->messageFactory->createResponse();
     $urls = array();
     foreach ($products as $product) {
         $urls[] = $product->getMeta()->offsetGet('url');
     }
     if (empty($urls) || count($urls) > 5) {
         $message = 'Update Products require at least 1 and a most 5 urls';
         throw new IntegrationException($message);
     }
     $urls = implode(",", $urls);
     $request->setField('urls', $urls);
     $this->requestSigner->bind($oAuth, $request);
     $this->log($request);
     try {
         $this->buzz->send($request, $response);
         $this->log($response);
         $responseHandler = $this->responseHandlerFactory->createResponseHandler('products');
         $responseHandler->bind($response, $products);
     } catch (InternalErrorException $e) {
         if ($attempt >= $this->maxRetries) {
             throw new ConnectionException($e->getMessage());
         }
         $nextAttempt = $attempt + 1;
         $this->log("Attempt " . $nextAttempt);
         usleep($this->retryDelay * $attempt);
         $this->updateProducts($products, $merchant, $nextAttempt);
     }
 }
 /**
  * @param AntiMattr\Common\Address\AddressInterface $address
  *
  * @return AntiMattr\AddressVerifier\Event\VerificationEvent $event
  *
  * @throws AntiMattr\AddressVerifier\Exception\Connection\ConnectionException
  * @throws AntiMattr\AddressVerifier\Exception\Connection\TimeoutException
  * @throws AntiMattr\AddressVerifier\Exception\IntegrationException
  * @throws AntiMattr\AddressVerifier\Exception\Location\CorrectionException
  * @throws AntiMattr\AddressVerifier\Exception\Location\StreetAddressException     
  */
 public function verifyLocation(AddressInterface $address)
 {
     if (!($streetAddressLine1 = $address->getStreetAddressLine1())) {
         throw new IntegrationException('Verify address missing street address line 1');
     }
     if (!($locality = $address->getLocality())) {
         throw new IntegrationException('Verify address missing locality');
     }
     if (!($region = $address->getRegion())) {
         throw new IntegrationException('Verify address missing region');
     }
     if (!($postalCode = $address->getPostalCode())) {
         throw new IntegrationException('Verify address missing postal code');
     }
     $streetAddressLine2 = $address->getStreetAddressLine2() ?: '';
     $params = array('address[street]' => $streetAddressLine1, 'address[unit]' => $streetAddressLine2, 'address[city]' => $locality, 'address[state]' => $region, 'address[zip]' => $postalCode, 'apikey' => $this->apiKey);
     $query = http_build_query($params);
     $resource = sprintf("/addresses.json?%s", $query);
     $request = $this->messageFactory->createRequest('GET', $resource, 'https://bpi.briteverify.com');
     $response = $this->messageFactory->createResponse();
     $event = $this->eventFactory->createEvent($address);
     $this->buzz->setTimeout($this->timeout);
     $this->log($request);
     try {
         $this->buzz->send($request, $response);
         $this->log($response);
         $statusCode = $response->getStatusCode();
         if ($statusCode !== 200) {
             $message = $response->getReasonPhrase();
             throw new IntegrationException($message);
         }
         $content = json_decode($response->getContent());
         if ($content->status === 'invalid') {
             $message = $content->error;
             throw new StreetAddressException($message);
         }
         if ($content->corrected === true) {
             $newAddress = new GenericAddress();
             if (isset($content->street)) {
                 $newAddress->setStreetAddressLine1($content->street);
             }
             if (isset($content->unit)) {
                 $newAddress->setStreetAddressLine2($content->unit);
             }
             if (isset($content->city)) {
                 $newAddress->setLocality($content->city);
             }
             if (isset($content->state_code)) {
                 $newAddress->setRegion($content->state_code);
             }
             if (isset($content->zip)) {
                 $postalCode = isset($content->plus4) ? $content->zip . '-' . $content->plus4 : $content->zip;
                 $newAddress->setPostalCode($postalCode);
             }
             if (isset($content->country_code)) {
                 $newAddress->setCountry($content->country_code);
             }
             throw new CorrectionException($newAddress);
         }
     } catch (ClientException $e) {
         $subject = $e->getMessage();
         if (0 !== preg_match('/timed out/', $subject)) {
             throw new TimeoutException($subject);
         }
         throw new ConnectionException($subject);
     }
     return $event;
 }