Example #1
0
 /**
  * List the cards of a customer.
  *
  * @param   string|Customer $customer the customer id or the customer object
  * @param   int $perPage the number of results per page
  * @param   int $page the page number
  * @param   Payplug\Payplug $payplug the client configuration
  *
  * @return  Card[] an array containing the cards.
  *
  * @throws Payplug\Exception\ConfigurationNotSetException
  * @throws Payplug\Exception\UnexpectedAPIResponseException
  */
 public static function listCards($customer, $perPage = null, $page = null, Payplug\Payplug $payplug = null)
 {
     if ($payplug === null) {
         $payplug = Payplug\Payplug::getDefaultConfiguration();
     }
     if ($customer instanceof Customer) {
         $customer = $customer->id;
     }
     $httpClient = new Payplug\Core\HttpClient($payplug);
     $pagination = array('per_page' => $perPage, 'page' => $page);
     $response = $httpClient->get(Payplug\Core\APIRoutes::getRoute(Payplug\Core\APIRoutes::CARD_RESOURCE, null, array('CUSTOMER_ID' => $customer), $pagination));
     if (!array_key_exists('data', $response['httpResponse']) || !is_array($response['httpResponse']['data'])) {
         throw new Payplug\Exception\UnexpectedAPIResponseException("Expected API response to contain 'data' key referencing an array.", $response['httpResponse']);
     }
     $cards = array();
     foreach ($response['httpResponse']['data'] as &$card) {
         $cards[] = Card::fromAttributes($card);
     }
     return $cards;
 }
Example #2
0
 public function testCardDeleteCardObject()
 {
     function testCardDeleteCardObject_getinfo($option)
     {
         switch ($option) {
             case CURLINFO_HTTP_CODE:
                 return 200;
         }
         return null;
     }
     $GLOBALS['CURLOPT_URL_DATA'] = null;
     function testCardDeleteCardObject_setopt($option, $value = null)
     {
         switch ($option) {
             case CURLOPT_URL:
                 $GLOBALS['CURLOPT_URL_DATA'] = $value;
                 return true;
         }
         return true;
     }
     $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;
     }));
     $card = Card::fromAttributes(array('id' => 'a_card_id', 'customer_id' => 'a_customer_id'));
     $card->delete();
     $this->assertContains('a_customer_id', $GLOBALS['CURLOPT_URL_DATA']);
     $this->assertStringEndsWith('a_card_id', $GLOBALS['CURLOPT_URL_DATA']);
     unset($GLOBALS['CURLOPT_URL_DATA']);
 }
Example #3
0
 /**
  * Add a card to this customer.
  *
  * @param   array $data the card data
  * @param   Payplug\Payplug $payplug the client configuration
  *
  * @return  Card the created card object
  *
  * @throws  Payplug\Exception\InvalidPaymentException
  * @throws  Payplug\Exception\UnexpectedAPIResponseException
  */
 public function addCard($data, Payplug\Payplug $payplug = null)
 {
     return Payplug\Resource\Card::create($this, $data, $payplug);
 }