Example #1
0
 function testRequest()
 {
     $order = new Order();
     $order->setCode('abc')->setEmail('*****@*****.**')->setWaitDays(3)->addProduct((new Product())->setName('test')->setCode(789));
     $client = new Client('abc', 'pass');
     $request = $client->createRequest($order);
     $this->assertEquals('POST', $request->getMethod());
     $this->assertEquals('http://www.wiarygodneopinie.pl/gate.php?type=php&email=info%40example.org&login=abc&pass=pass&queue=3&order_no=abc', $request->getUri());
     $this->assertEquals('products=%5B%7B%22opi_product_name%22%3A%22test%22%2C%22opi_product_id%22%3A789%7D%5D', (string) $request->getBody());
 }
Example #2
0
 public function createRequest(Order $order)
 {
     $query = ['type' => 'php', 'email' => $order->getEmail(), 'login' => $this->getLogin(), 'pass' => $this->getPassword(), 'queue' => $order->getWaitDays(), 'order_no' => $order->getCode()];
     $products = [];
     foreach ($order->getProducts() as $product) {
         $productData = [];
         if (!empty($product->getBrand())) {
             $productData['opi_product_firm'] = $product->getBrand();
         }
         if (!empty($product->getName())) {
             $productData['opi_product_name'] = $product->getName();
         }
         if (!empty($product->getCode())) {
             $productData['opi_product_id'] = $product->getCode();
         }
         $products[] = $productData;
     }
     return new Request('POST', 'http://www.wiarygodneopinie.pl/gate.php?' . http_build_query($query), ['Content-Type' => 'application/x-www-form-urlencoded'], http_build_query(['products' => json_encode($products)]));
 }