/**
  * @param Request $request
  * @param StoreEntity $store
  * @return string
  * @throws InvalidShopifyHmac
  */
 public function verifyWebhookRequest(Request $request, StoreEntity $store)
 {
     $hmac_header = $request->headers->get('X_SHOPIFY_HMAC_SHA256');
     $calculated_hmac = base64_encode(hash_hmac('sha256', $request->getContent(), $store->getShopifySecretToken(), true));
     if ($hmac_header != $calculated_hmac) {
         throw new InvalidShopifyHmac();
     }
     return $calculated_hmac;
 }
 /**
  * @param StoreEntity $store
  * @return Client
  */
 public function createClient(StoreEntity $store)
 {
     $client = new Client(array("shopUrl" => $store->getShopifyStoreUrl(), "X-Shopify-Access-Token" => $store->getShopifyAccessToken()));
     $loggerName = sprintf('shopify_%s', str_replace(' ', '_', strtolower($store->getStoreLabel())));
     $loggerPath = sprintf('%s/%s.log', $this->logPath, $loggerName);
     $log = new Logger($loggerName);
     $log->pushHandler(new StreamHandler($loggerPath, $this->logLevel));
     $subscriber = new LogSubscriber($log);
     $client->getEmitter()->attach($subscriber);
     return $client;
 }
 /**
  * @param $catalog
  * @param StoreEntity $shopifyStore
  * @return array|null|object|CatalogEntity
  * @throws NoResultException
  */
 public function getCatalog($catalog, StoreEntity $shopifyStore)
 {
     //Might not be needed this
     if ($catalog == CatalogEntity::$ALL) {
         $catalogs = $this->catalogRepository->findBy(['storeId' => $shopifyStore->getStoreId()]);
     } else {
         $catalogs = $this->catalogRepository->findBy(['storeId' => $shopifyStore->getStoreId(), 'catalogName' => $catalog]);
     }
     if (!$catalogs) {
         throw new NoResultException('No catalogs found');
     }
     return $catalogs;
 }
Ejemplo n.º 4
0
 /**
  * @param StoreEntity $store
  * @param ErpOrderEntity $erpOrder
  * @return ErpShipmentEntity
  * @throws ErpShipmentNotFound
  */
 public function getShipment(StoreEntity $store, ErpOrderEntity $erpOrder)
 {
     $request = $this->client->createRequest('GET', sprintf('%s/shipments/?order=%s', $store->getErpUrl(), $erpOrder->getOrderId()), ['auth' => [$store->getErpUsername(), $store->getErpPassword()]]);
     try {
         $response = $this->sendRequest($request)->xml();
     } catch (\Exception $e) {
         throw new ErpShipmentNotFound(sprintf('Not shipment can be found with the order id %s', $erpOrder->getOrderId()));
     }
     return ErpShipmentEntity::createFromShipmentXMLObject($response);
 }
 /**
  * @param StoreEntity $store
  */
 public function checkHandlingFeeProductAndCreateIt(StoreEntity $store)
 {
     try {
         if ($store->getShopifyHandlingFeeProductId()) {
             $this->shopifyClient->checkHandlingFeeProduct($store);
         } else {
             $erpProduct = ErpProductEntity::createHandlingFeeProduct();
             $product = $this->shopifyClient->saveProduct($store, $erpProduct);
             $store->setShopifyHandlingFeeProductId($product->getVariantId());
             $this->storeRepository->save($store);
         }
     } catch (NoShopifyProductFound $e) {
         //Add the handling fee product
         $erpProduct = ErpProductEntity::createHandlingFeeProduct();
         $product = $this->shopifyClient->saveProduct($store, $erpProduct);
         $store->setShopifyHandlingFeeProductId($product->getVariantId());
         $this->storeRepository->save($store);
     }
 }
Ejemplo n.º 6
0
 /**
  * Load data fixtures with the passed EntityManager
  *
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $store = new StoreEntity();
     $store->setStoreLabel('My Test Store');
     $store->setSyncProducts(1);
     $store->setShopifyAccessToken('06ccecd6867cc78d4423e4bb8058a984');
     $store->setShopifyStoreUrl('erpapitest.myshopify.com');
     $store->setErpUrl('http://robots.lapineinc.com');
     $store->setErpUsername('CSGTEST');
     $store->setErpPassword('yG9uFFrLeHZ56LL4');
     $store->setShopifySecretToken('MySecretToken');
     $store->setShopifyHandlingFeeProductId(1);
     $manager->persist($store);
     $manager->flush();
 }