/** * Returns an API resource that you can trust. * * @param Payplug\Payplug $payplug the client configuration. * * @return Payplug\Resource\APIResource The consistent API resource. * * @throws Payplug\Exception\UndefinedAttributeException when the local resource is invalid. */ function getConsistentResource(Payplug\Payplug $payplug = null) { if (!array_key_exists('id', $this->_attributes)) { throw new Payplug\Exception\UndefinedAttributeException('The id of the payment is not set.'); } return Payment::retrieve($this->_attributes['id'], $payplug); }
public function testPaymentRetrieve() { $GLOBALS['CURLOPT_URL_DATA'] = null; $this->_requestMock->expects($this->once())->method('exec')->will($this->returnValue('{"status":"ok"}')); $this->_requestMock->expects($this->any())->method('getinfo')->will($this->returnCallback(function ($option) { switch ($option) { case CURLINFO_HTTP_CODE: return 200; } return null; })); $this->_requestMock->expects($this->any())->method('setopt')->will($this->returnCallback(function ($option, $value = null) { switch ($option) { case CURLOPT_URL: $GLOBALS['CURLOPT_URL_DATA'] = $value; return true; } return true; })); $payment = Payment::retrieve('a_payment_id'); $this->assertStringEndsWith('a_payment_id', $GLOBALS['CURLOPT_URL_DATA']); $this->assertEquals('ok', $payment->status); unset($GLOBALS['CURLOPT_URL_DATA']); }