Example #1
0
 /**
  * List the refunds of this payment.
  *
  * @param   Payplug\Payplug     $payplug    the client configuration
  *
  * @return  null|Refund[]   the array of refunds of this payment
  *
  * @throws  Payplug\Exception\InvalidPaymentException
  * @throws  Payplug\Exception\UnexpectedAPIResponseException
  */
 public function listRefunds(Payplug\Payplug $payplug = null)
 {
     if (!array_key_exists('id', $this->getAttributes())) {
         throw new Payplug\Exception\InvalidPaymentException("This payment object has no id. You can't list refunds on it.");
     }
     return Refund::listRefunds($this->id, $payplug);
 }
Example #2
0
 public function testRefundsListFromPaymentObject()
 {
     $GLOBALS['CURLOPT_URL_DATA'] = null;
     $this->_requestMock->expects($this->once())->method('exec')->will($this->returnValue('{"data":[{"id": "refund1"}, {"id": "refund2"}]}'));
     $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;
     }));
     $refunds = Refund::listRefunds(Payment::fromAttributes(array('id' => 'a_payment_id')));
     $this->assertContains('a_payment_id', $GLOBALS['CURLOPT_URL_DATA']);
     $this->assertEquals(2, count($refunds));
     $this->assertTrue('refund1' === $refunds[0]->id || 'refund2' === $refunds[1]->id);
     $this->assertTrue(('refund1' === $refunds[1]->id || 'refund2' === $refunds[1]->id) && $refunds[0]->id !== $refunds[1]->id);
     unset($GLOBALS['CURLOPT_URL_DATA']);
 }