/** * 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; }
/** * 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']); }
/** * 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; }
/** * 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; }