Пример #1
0
 /**
  * Sends an order confirmation to Nosto.
  *
  * @param NostoOrderInterface $order the order to confirm.
  * @param null $customerId the Nosto customer ID of the user who placed the order.
  * @throws NostoException on failure.
  * @return true on success.
  */
 public function confirm(NostoOrderInterface $order, $customerId = null)
 {
     $request = $this->initApiRequest($customerId);
     $response = $request->post($this->getOrderAsJson($order));
     if ($response->getCode() !== 200) {
         throw Nosto::createHttpException('Failed to send order confirmation to Nosto.', $request, $response);
     }
     return true;
 }
Пример #2
0
 /**
  * Sends a currency exchange rate update request to Nosto via the API.
  *
  * @param NostoCurrencyExchangeRateCollection $collection the collection of rates to update.
  * @return bool if the update was successful.
  * @throws NostoException if the request cannot be created.
  * @throws NostoHttpException if the request was sent but failed.
  */
 public function update(NostoCurrencyExchangeRateCollection $collection)
 {
     $request = $this->initApiRequest();
     $response = $request->post($this->getCollectionAsJson($collection));
     if ($response->getCode() !== 200) {
         throw Nosto::createHttpException(sprintf('Failed to update currency exchange rates for account %s.', $this->account->getName()), $request, $response);
     }
     return true;
 }
Пример #3
0
 /**
  * Sends the product re-crawl request to nosto.
  *
  * @return bool true on success, false otherwise.
  * @throws NostoException if the request fails or cannot be made.
  */
 public function send()
 {
     $request = $this->initApiRequest();
     $response = $request->post($this->getCollectionAsJson());
     if ($response->getCode() !== 200) {
         throw Nosto::createHttpException('Failed to send product re-crawl to Nosto.', $request, $response);
     }
     return true;
 }
Пример #4
0
 /**
  * Authenticates the application with the given code to receive an access token.
  *
  * @param string $code code sent by the authorization server to exchange for an access token.
  * @return NostoOAuthToken
  *
  * @throws NostoException
  */
 public function authenticate($code)
 {
     if (empty($code)) {
         throw new NostoException('Invalid authentication token');
     }
     $request = new NostoHttpRequest();
     $request->setUrl(self::$baseUrl . self::PATH_TOKEN);
     $request->setReplaceParams(array('{cid}' => $this->clientId, '{sec}' => $this->clientSecret, '{uri}' => $this->redirectUrl, '{cod}' => $code));
     $response = $request->get();
     $result = $response->getJsonResult(true);
     if ($response->getCode() !== 200) {
         throw Nosto::createHttpException('Failed to authenticate with code.', $request, $response);
     }
     $merchantName = isset($result['merchant_name']) ? $result['merchant_name'] : null;
     $accessToken = isset($result['access_token']) ? $result['access_token'] : null;
     return new NostoOAuthToken($merchantName, $accessToken);
 }
Пример #5
0
 /**
  * Signs the user in to Nosto via SSO.
  *
  * Requires that the account has a valid sso token associated with it.
  *
  * @param NostoAccount $account the account to sign into.
  * @param NostoAccountMetaSingleSignOnInterface $meta the SSO meta-data.
  * @return string a secure login url.
  *
  * @throws NostoException on failure.
  */
 public function sso(NostoAccount $account, NostoAccountMetaSingleSignOnInterface $meta)
 {
     $token = $account->getApiToken(NostoApiToken::API_SSO);
     if (is_null($token)) {
         throw new NostoException(sprintf('No `%s` API token found for account "%s".', NostoApiToken::API_SSO, $account->getName()));
     }
     $request = new NostoHttpRequest();
     $request->setUrl(NostoHttpRequest::$baseUrl . NostoHttpRequest::PATH_SSO_AUTH);
     $request->setReplaceParams(array('{platform}' => $meta->getPlatform(), '{email}' => $meta->getEmail()));
     $request->setContentType('application/x-www-form-urlencoded');
     $request->setAuthBasic('', $token->getValue());
     $response = $request->post(http_build_query(array('fname' => $meta->getFirstName(), 'lname' => $meta->getLastName())));
     if ($response->getCode() !== 200) {
         throw Nosto::createHttpException('Failed to sign into Nosto using Single Sign On.', $request, $response);
     }
     $result = $response->getJsonResult();
     if (empty($result->login_url)) {
         throw new NostoException('No "login_url" returned when logging in employee to Nosto');
     }
     return $result->login_url;
 }
Пример #6
0
 /**
  * Sends a POST request to delete all the products currently in the collection.
  *
  * @return bool if the request was successful.
  * @throws NostoException on failure.
  */
 public function delete()
 {
     $request = $this->initApiRequest();
     $request->setPath(NostoApiRequest::PATH_PRODUCTS_DISCONTINUE);
     $response = $request->post($this->getCollectionIdsAsJson());
     if ($response->getCode() !== 200) {
         throw Nosto::createHttpException('Failed to delete Nosto product(s).', $request, $response);
     }
     return true;
 }