Example #1
0
 /**
  * Open a refund on the payment.
  *
  * @param   array               $data       the refund data
  * @param   Payplug\Payplug    $payplug    the client configuration
  *
  * @return  Refund|null the opened refund instance
  *
  * @throws  Payplug\Exception\InvalidPaymentException when the id of the payment is invalid
  */
 public function refund(array $data = null, Payplug\Payplug $payplug = null)
 {
     if (!array_key_exists('id', $this->getAttributes())) {
         throw new Payplug\Exception\InvalidPaymentException("This payment object has no id. It can't be refunded.");
     }
     return Refund::create($this->id, $data, $payplug);
 }
Example #2
0
 public function testRefundCreateFromPaymentObject()
 {
     $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;
     }));
     $refund = Refund::create(Payment::fromAttributes(array('id' => 'a_payment_id')), array('amount' => 3300));
     $this->assertEquals('ok', $refund->status);
     $this->assertContains('a_payment_id', $GLOBALS['CURLOPT_URL_DATA']);
     unset($GLOBALS['CURLOPT_URL_DATA']);
 }