public function omCapture(KCConnector $connector, $order_id, $data) { try { $order = new KCOrder($connector, $order_id); return $order->createCapture($data); } catch (\Exception $e) { $this->log($e->getMessage()); return false; } }
/** * Make sure that the request sent is correct and that the location is updated * when creating an order. * * @return void */ public function testCreateCapture() { $this->mock->addResponse(new Response(201, ['Location' => 'http://somewhere/a-path'])); $order = new Order($this->connector, '0002'); $capture = $order->createCapture(['data' => 'goes here']); $this->assertInstanceOf('Klarna\\Rest\\OrderManagement\\Capture', $capture); $this->assertEquals('http://somewhere/a-path', $capture->getLocation()); $request = $this->history->getLastRequest(); $this->assertEquals('POST', $request->getMethod()); $this->assertEquals('/ordermanagement/v1/orders/0002/captures', $request->getPath()); $this->assertEquals('application/json', $request->getHeader('Content-Type')); $this->assertEquals('{"data":"goes here"}', strval($request->getBody())); $this->assertAuthorization($request); }
/** * Make sure that a capture is created properly. * * @return void */ public function testCreateCapture() { $data = ['data' => 'goes here']; $this->connector->expects($this->once())->method('createRequest')->with('/ordermanagement/v1/orders/12345/captures', 'POST', ['json' => $data])->will($this->returnValue($this->request)); $this->connector->expects($this->once())->method('send')->with($this->request)->will($this->returnValue($this->response)); $this->response->expects($this->once())->method('getStatusCode')->will($this->returnValue('201')); $this->response->expects($this->once())->method('hasHeader')->with('Location')->will($this->returnValue(true)); $this->response->expects($this->once())->method('getHeader')->with('Location')->will($this->returnValue('http://somewhere/a-path')); $order = new Order($this->connector, '12345'); $capture = $order->createCapture($data); $this->assertEquals('http://somewhere/a-path', $capture->getLocation()); }