$cardsApi = $client->getCardsApi();
CardsApi
Retrieves a list of cards owned by the account making the request. A max of 25 cards will be returned.
function listCards(
?string $cursor = null,
?string $customerId = null,
?bool $includeDisabled = false,
?string $referenceId = null,
?string $sortOrder = null
): ApiResponse
Parameter | Type | Tags | Description |
---|---|---|---|
cursor |
?string |
Query, Optional | A pagination cursor returned by a previous call to this endpoint. Provide this to retrieve the next set of results for your original query. See Pagination for more information. |
customerId |
?string |
Query, Optional | Limit results to cards associated with the customer supplied. By default, all cards owned by the merchant are returned. |
includeDisabled |
?bool |
Query, Optional | Includes disabled cards. By default, all enabled cards owned by the merchant are returned. |
referenceId |
?string |
Query, Optional | Limit results to cards associated with the reference_id supplied. |
sortOrder |
?string(SortOrder) |
Query, Optional | Sorts the returned list by when the card was created with the specified order. This field defaults to ASC. |
This method returns a Square\Utils\ApiResponse
instance. The getResult()
method on this instance returns the response data which is of type ListCardsResponse
.
$includeDisabled = false;
$apiResponse = $cardsApi->listCards(
null,
null,
$includeDisabled
);
if ($apiResponse->isSuccess()) {
$listCardsResponse = $apiResponse->getResult();
} else {
$errors = $apiResponse->getErrors();
}
// Getting more response information
var_dump($apiResponse->getStatusCode());
var_dump($apiResponse->getHeaders());
Adds a card on file to an existing merchant.
function createCard(CreateCardRequest $body): ApiResponse
Parameter | Type | Tags | Description |
---|---|---|---|
body |
CreateCardRequest |
Body, Required | An object containing the fields to POST for the request. See the corresponding object definition for field details. |
This method returns a Square\Utils\ApiResponse
instance. The getResult()
method on this instance returns the response data which is of type CreateCardResponse
.
$body = CreateCardRequestBuilder::init(
'4935a656-a929-4792-b97c-8848be85c27c',
'cnon:uIbfJXhXETSP197M3GB',
CardBuilder::init()
->cardholderName('Amelia Earhart')
->billingAddress(
AddressBuilder::init()
->addressLine1('500 Electric Ave')
->addressLine2('Suite 600')
->locality('New York')
->administrativeDistrictLevel1('NY')
->postalCode('10003')
->country(Country::US)
->build()
)
->customerId('VDKXEEKPJN48QDG3BGGFAK05P8')
->referenceId('user-id-1')
->build()
)->build();
$apiResponse = $cardsApi->createCard($body);
if ($apiResponse->isSuccess()) {
$createCardResponse = $apiResponse->getResult();
} else {
$errors = $apiResponse->getErrors();
}
// Getting more response information
var_dump($apiResponse->getStatusCode());
var_dump($apiResponse->getHeaders());
Retrieves details for a specific Card.
function retrieveCard(string $cardId): ApiResponse
Parameter | Type | Tags | Description |
---|---|---|---|
cardId |
string |
Template, Required | Unique ID for the desired Card. |
This method returns a Square\Utils\ApiResponse
instance. The getResult()
method on this instance returns the response data which is of type RetrieveCardResponse
.
$cardId = 'card_id4';
$apiResponse = $cardsApi->retrieveCard($cardId);
if ($apiResponse->isSuccess()) {
$retrieveCardResponse = $apiResponse->getResult();
} else {
$errors = $apiResponse->getErrors();
}
// Getting more response information
var_dump($apiResponse->getStatusCode());
var_dump($apiResponse->getHeaders());
Disables the card, preventing any further updates or charges. Disabling an already disabled card is allowed but has no effect.
function disableCard(string $cardId): ApiResponse
Parameter | Type | Tags | Description |
---|---|---|---|
cardId |
string |
Template, Required | Unique ID for the desired Card. |
This method returns a Square\Utils\ApiResponse
instance. The getResult()
method on this instance returns the response data which is of type DisableCardResponse
.
$cardId = 'card_id4';
$apiResponse = $cardsApi->disableCard($cardId);
if ($apiResponse->isSuccess()) {
$disableCardResponse = $apiResponse->getResult();
} else {
$errors = $apiResponse->getErrors();
}
// Getting more response information
var_dump($apiResponse->getStatusCode());
var_dump($apiResponse->getHeaders());