Esempio n. 1
0
 public function process()
 {
     $request = file_get_contents('php://input');
     if (empty($request)) {
         die("No request data");
     }
     try {
         $productOrdered = $this->connection->receiveProductOrdered();
         $allCodesFromProduct = \CodesWholesale\Resource\Order::getCodes($productOrdered);
         $orderId = $productOrdered->getOrderId();
         $item = $this->itemRetriever->retrieveItem($orderId);
         $params = array('item' => $item, 'allCodesFromProduct' => $allCodesFromProduct);
         $newKeys = $this->newKeysExtractor->extract($params);
         $this->eventDispatcher->dispatchEvent($newKeys);
     } catch (\Exception $e) {
         die('We found error. Probably this is the result of sending test POSTBACK. If your response status is: 200 OK
          it means that you are successfully connected. Error: ' . $e->getMessage());
     }
 }
const SHOULD_FLUSH = 0;
function flushToFile($buffer)
{
    file_put_contents("generated_file.txt", $buffer);
}
if (SHOULD_FLUSH) {
    ob_start("flushToFile");
}
$clientBuilder = new \CodesWholesale\ClientBuilder($params);
$client = $clientBuilder->build();
try {
    // method will parse request and extract parameters
    // get order id, and id of ordered product from request params
    $productOrdered = $client->receiveProductOrdered();
    // ask for bought codes
    $allCodesFromProduct = \CodesWholesale\Resource\Order::getCodes($productOrdered);
    /**
     * Go through bought codes
     */
    foreach ($allCodesFromProduct as $code) {
        /**
         * There are 3 possible code types returned from CW.
         *
         * Pre Order (when codes are not in stock)
         */
        if ($code->isPreOrder()) {
            // check if still some codes are in pre-order state
            echo "Pre-order <br />";
        }
        /**
         * Code as a TEXT