/** * Make sure that the request sent and retrieved data is correct when fetching * a capture that is not already in the captures list. * * @return void */ public function testFetchCaptureNew() { $json = <<<JSON { "capture_id": "1003", "updated": "from json" } JSON; $this->mock->addResponse(new Response(200, ['Content-Type' => 'application/json'], Stream::factory($json))); $order = new Order($this->connector, '0002'); $capture = new Capture($this->connector, $order->getLocation(), '1002'); $capture['capture_id'] = '1002'; $capture['updated'] = 'not from json'; $order['captures'][] = $capture; $capture = $order->fetchCapture('1003'); $this->assertInstanceOf('Klarna\\Rest\\OrderManagement\\Capture', $capture); $this->assertEquals('/ordermanagement/v1/orders/0002/captures/1003', $capture->getLocation()); $this->assertEquals('from json', $capture['updated']); $this->assertEquals('1003', $capture->getId()); $this->assertEquals($capture->getId(), $capture['capture_id']); }
public function omTriggerSendOut(KCConnector $connector, $order_id, $capture_id) { try { $order = new KCOrder($connector, $order_id); $capture = $order->fetchCapture($capture_id); return $capture->triggerSendout(); } catch (\Exception $e) { $this->log($e->getMessage()); return false; } }
/** * Make sure that a new capture is fetched if it is not in the resource. * * @return void */ public function testFetchCaptureNoCache() { $this->connector->expects($this->once())->method('createRequest')->with('/ordermanagement/v1/orders/12345/captures/2', 'GET', [])->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('200')); $this->response->expects($this->once())->method('hasHeader')->with('Content-Type')->will($this->returnValue(true)); $this->response->expects($this->once())->method('getHeader')->with('Content-Type')->will($this->returnValue('application/json')); $data = ['data' => 'from response json', 'capture_id' => '2']; $this->response->expects($this->once())->method('json')->will($this->returnValue($data)); $order = new Order($this->connector, '12345'); $order['captures'][] = $this->getMockBuilder('Klarna\\Rest\\OrderManagement\\Capture')->disableOriginalConstructor()->getMock(); $order['captures'][0]->expects($this->once())->method('getId')->will($this->returnValue('1')); $capture = $order->fetchCapture('2'); $this->assertInstanceOf('Klarna\\Rest\\OrderManagement\\Capture', $capture); $this->assertEquals('from response json', $capture['data']); $this->assertEquals('2', $capture->getId()); }