Exemplo n.º 1
0
 /**
  * Update a customer.
  *
  * @param   array $data API data for customer update
  * @param   Payplug\Payplug $payplug the client configuration
  *
  * @return  null|Customer the new Customer instance
  *
  * @throws  Payplug\Exception\ConfigurationNotSetException
  */
 public function update(array $data, Payplug\Payplug $payplug = null)
 {
     if ($payplug === null) {
         $payplug = Payplug\Payplug::getDefaultConfiguration();
     }
     $httpClient = new Payplug\Core\HttpClient($payplug);
     $response = $httpClient->patch(Payplug\Core\APIRoutes::getRoute(Payplug\Core\APIRoutes::CUSTOMER_RESOURCE, $this->id), $data);
     return Payment::fromAttributes($response['httpResponse']);
 }
Exemplo n.º 2
0
 /**
  * Create a card.
  *
  * @param   Customer|string $customer The customer object or id
  * @param   array $data API data for customer creation
  * @param   Payplug\Payplug $payplug the client configuration
  *
  * @return  null|Card the created card
  *
  * @throws  Payplug\Exception\ConfigurationNotSetException
  */
 public static function create($customer, array $data, Payplug\Payplug $payplug = null)
 {
     if ($payplug === null) {
         $payplug = Payplug\Payplug::getDefaultConfiguration();
     }
     if ($customer instanceof Customer) {
         $customer = $customer->id;
     }
     $httpClient = new Payplug\Core\HttpClient($payplug);
     $response = $httpClient->post(Payplug\Core\APIRoutes::getRoute(Payplug\Core\APIRoutes::CARD_RESOURCE, null, array('CUSTOMER_ID' => $customer)), $data);
     return Payment::fromAttributes($response['httpResponse']);
 }
Exemplo n.º 3
0
 /**
  * Tries to recompose an API Resource from its attributes. For example, when you got it from a notification.
  * The API Resource must have a known 'object' property.
  *
  * @param   array   $attributes The attributes of the object.
  *
  * @return  IVerifiableAPIResource  An unsafe API Resource.
  *
  * @throws  Payplug\Exception\UnknownAPIResourceException When the given object is unknown.
  */
 public static function factory(array $attributes)
 {
     if (!array_key_exists('object', $attributes)) {
         throw new Payplug\Exception\UnknownAPIResourceException('Missing "object" property.');
     }
     switch ($attributes['object']) {
         case 'payment':
             return Payplug\Resource\Payment::fromAttributes($attributes);
         case 'refund':
             return Payplug\Resource\Refund::fromAttributes($attributes);
     }
     throw new Payplug\Exception\UnknownAPIResourceException('Unknown "object" property "' . $attributes['object'] . '".');
 }
Exemplo n.º 4
0
 /**
  * Creates a Payment.
  *
  * @param   array               $data       API data for payment creation
  * @param   Payplug\Payplug    $payplug    the client configuration
  *
  * @return  null|Payment the created payment instance
  *
  * @throws  Payplug\Exception\ConfigurationNotSetException
  */
 public static function create(array $data, Payplug\Payplug $payplug = null)
 {
     if ($payplug === null) {
         $payplug = Payplug\Payplug::getDefaultConfiguration();
     }
     $httpClient = new Payplug\Core\HttpClient($payplug);
     $response = $httpClient->post(Payplug\Core\APIRoutes::getRoute(Payplug\Core\APIRoutes::PAYMENT_RESOURCE), $data);
     return Payment::fromAttributes($response['httpResponse']);
 }
Exemplo n.º 5
0
 public function testRetrieveConsistentPayment()
 {
     function testRetrieveConsistentPayment_getinfo($option)
     {
         switch ($option) {
             case CURLINFO_HTTP_CODE:
                 return 200;
         }
         return null;
     }
     $this->_requestMock->expects($this->once())->method('exec')->will($this->returnValue('{"id": "pay_345"}'));
     $this->_requestMock->expects($this->any())->method('setopt')->will($this->returnValue(true));
     $this->_requestMock->expects($this->any())->method('getinfo')->will($this->returnCallback(function ($option) {
         switch ($option) {
             case CURLINFO_HTTP_CODE:
                 return 200;
         }
         return null;
     }));
     $payment1 = Payment::fromAttributes(array('id' => 'pay_123'));
     $payment2 = $payment1->getConsistentResource($this->_configuration);
     $this->assertEquals('pay_123', $payment1->id);
     $this->assertEquals('pay_345', $payment2->id);
 }
Exemplo n.º 6
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']);
 }