Example #1
0
 protected function setUp()
 {
     $this->_configuration = new Payplug\Payplug('abc');
     Payplug\Payplug::setDefaultConfiguration($this->_configuration);
     $this->_requestMock = $this->getMock('\\Payplug\\Core\\IHttpRequest');
     Payplug\Core\HttpClient::$REQUEST_HANDLER = $this->_requestMock;
 }
Example #2
0
 /**
  * Lists the last refunds of a payment.
  *
  * @param   string|Payment      $payment        the payment id or the payment object
  * @param   Payplug\Payplug     $payplug        the client configuration
  *
  * @return  null|Refund[]   an array containing the refunds on success.
  *
  * @throws Payplug\Exception\ConfigurationNotSetException
  * @throws Payplug\Exception\UnexpectedAPIResponseException
  */
 public static function listRefunds($payment, Payplug\Payplug $payplug = null)
 {
     if ($payplug === null) {
         $payplug = Payplug\Payplug::getDefaultConfiguration();
     }
     if ($payment instanceof Payment) {
         $payment = $payment->id;
     }
     $httpClient = new Payplug\Core\HttpClient($payplug);
     $response = $httpClient->get(Payplug\Core\APIRoutes::getRoute(Payplug\Core\APIRoutes::REFUND_RESOURCE, null, array('PAYMENT_ID' => $payment)));
     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']);
     }
     $refunds = array();
     foreach ($response['httpResponse']['data'] as &$refund) {
         $refunds[] = Refund::fromAttributes($refund);
     }
     return $refunds;
 }
Example #3
0
        <?php 
echo "<h2><i class='fa fa-list'></i> Latest payments:</h2><hr />";
echo "<table class='table table-striped'>";
echo "<thead>";
echo "<tr>";
echo "<td class='text-center'></td>";
echo "<td class='text-center'>Amount</td>";
echo "<td class='text-center'>Customer</td>";
echo "<td class='text-center'>Creation date</td>";
echo "<td class='text-center'>Status</td>";
echo "<td class='text-center'>Payment ID</td>";
echo "<td class='text-center'></td>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
\Payplug\Payplug::setSecretKey($secretkey);
$payments = \Payplug\Payment::listPayments(50, 0);
$payment = $payments['data'][0];
foreach ($payments['data'] as $payment) {
    $is_paid = $payment->is_paid;
    $error_code = $payment->failure->code;
    $is_refunded = $payment->is_refunded;
    $cardid = $payment->card->id;
    if ($error_code == "aborted") {
        $aborted = "true";
    } else {
        $aborted = "false";
    }
    echo "<tr>";
    echo "<td class='text-center'>";
    if ($payment->hosted_payment != null && $payment->save_card == true) {
Example #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']);
 }
Example #5
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 #6
0
 /**
  * List customers.
  *
  * @param   Payplug\Payplug $payplug the client configuration
  *
  * @param   int $perPage the number of results per page
  * @param   int $page the page number
  * @return  Customer[] the array of payments
  *
  * @throws  Payplug\Exception\InvalidPaymentException
  * @throws  Payplug\Exception\UnexpectedAPIResponseException
  */
 public static function listCustomers($perPage = null, $page = null, Payplug\Payplug $payplug = null)
 {
     if ($payplug === null) {
         $payplug = Payplug\Payplug::getDefaultConfiguration();
     }
     $httpClient = new Payplug\Core\HttpClient($payplug);
     $pagination = array('per_page' => $perPage, 'page' => $page);
     $response = $httpClient->get(Payplug\Core\APIRoutes::getRoute(Payplug\Core\APIRoutes::CUSTOMER_RESOURCE, null, array(), $pagination));
     if (!array_key_exists('data', $response['httpResponse']) || !is_array($response['httpResponse']['data'])) {
         throw new Payplug\Exception\UnexpectedAPIResponseException("Expected 'data' key in API response.", $response['httpResponse']);
     }
     $customers = array();
     foreach ($response['httpResponse']['data'] as &$customer) {
         $customers[] = Customer::fromAttributes($customer);
     }
     return $customers;
 }