SquareConnect\PaymentsApi

March 25, 2020 · View on GitHub

All URIs are relative to https://connect.squareup.com

MethodHTTP requestDescription
cancelPaymentPOST /v2/payments/{payment_id}/cancelCancelPayment
cancelPaymentByIdempotencyKeyPOST /v2/payments/cancelCancelPaymentByIdempotencyKey
completePaymentPOST /v2/payments/{payment_id}/completeCompletePayment
createPaymentPOST /v2/paymentsCreatePayment
getPaymentGET /v2/payments/{payment_id}GetPayment
listPaymentsGET /v2/paymentsListPayments

cancelPayment

\SquareConnect\Model\CancelPaymentResponse cancelPayment($payment_id)

CancelPayment

Cancels (voids) a payment. If you set autocomplete to false when creating a payment, you can cancel the payment using this endpoint. For more information, see Delayed Payments.

Example

<?php
require_once(__DIR__ . '/vendor/autoload.php');

// Configure OAuth2 access token for authorization: oauth2
SquareConnect\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');

$apiInstance = new SquareConnect\Api\PaymentsApi();
$payment_id = "payment_id_example"; // string | `payment_id` identifying the payment to be canceled.

try {
    $result = $apiInstance->cancelPayment($payment_id);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling PaymentsApi->cancelPayment: ', $e->getMessage(), PHP_EOL;
}
?>

Parameters

NameTypeDescriptionNotes
payment_idstring`payment_id` identifying the payment to be canceled.

Return type

\SquareConnect\Model\CancelPaymentResponse

Authorization

oauth2

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json

[Back to top] [Back to API list] [Back to Model list] [Back to README]

cancelPaymentByIdempotencyKey

\SquareConnect\Model\CancelPaymentByIdempotencyKeyResponse cancelPaymentByIdempotencyKey($body)

CancelPaymentByIdempotencyKey

Cancels (voids) a payment identified by the idempotency key that is specified in the request. Use this method when status of a CreatePayment request is unknown. For example, after you send a CreatePayment request a network error occurs and you don't get a response. In this case, you can direct Square to cancel the payment using this endpoint. In the request, you provide the same idempotency key that you provided in your CreatePayment request you want to cancel. After cancelling the payment, you can submit your CreatePayment request again. Note that if no payment with the specified idempotency key is found, no action is taken, the end point returns successfully.

Example

<?php
require_once(__DIR__ . '/vendor/autoload.php');

// Configure OAuth2 access token for authorization: oauth2
SquareConnect\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');

$apiInstance = new SquareConnect\Api\PaymentsApi();
$body = new \SquareConnect\Model\CancelPaymentByIdempotencyKeyRequest(); // \SquareConnect\Model\CancelPaymentByIdempotencyKeyRequest | An object containing the fields to POST for the request.  See the corresponding object definition for field details.

try {
    $result = $apiInstance->cancelPaymentByIdempotencyKey($body);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling PaymentsApi->cancelPaymentByIdempotencyKey: ', $e->getMessage(), PHP_EOL;
}
?>

Parameters

NameTypeDescriptionNotes
body\SquareConnect\Model\CancelPaymentByIdempotencyKeyRequestAn object containing the fields to POST for the request. See the corresponding object definition for field details.

Return type

\SquareConnect\Model\CancelPaymentByIdempotencyKeyResponse

Authorization

oauth2

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json

[Back to top] [Back to API list] [Back to Model list] [Back to README]

completePayment

\SquareConnect\Model\CompletePaymentResponse completePayment(paymentid,payment_id, body)

CompletePayment

Completes (captures) a payment. By default, payments are set to complete immediately after they are created. If you set autocomplete to false when creating a payment, you can complete (capture) the payment using this endpoint. For more information, see Delayed Payments.

Example

<?php
require_once(__DIR__ . '/vendor/autoload.php');

// Configure OAuth2 access token for authorization: oauth2
SquareConnect\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');

$apiInstance = new SquareConnect\Api\PaymentsApi();
$payment_id = "payment_id_example"; // string | Unique ID identifying the payment to be completed.
$body = new \SquareConnect\Model\CompletePaymentRequest(); // \SquareConnect\Model\CompletePaymentRequest | An object containing the fields to POST for the request.  See the corresponding object definition for field details.

try {
    $result = $apiInstance->completePayment($payment_id, $body);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling PaymentsApi->completePayment: ', $e->getMessage(), PHP_EOL;
}
?>

Parameters

NameTypeDescriptionNotes
payment_idstringUnique ID identifying the payment to be completed.
body\SquareConnect\Model\CompletePaymentRequestAn object containing the fields to POST for the request. See the corresponding object definition for field details.

Return type

\SquareConnect\Model\CompletePaymentResponse

Authorization

oauth2

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json

[Back to top] [Back to API list] [Back to Model list] [Back to README]

createPayment

\SquareConnect\Model\CreatePaymentResponse createPayment($body)

CreatePayment

Charges a payment source, for example, a card represented by customer's card on file or a card nonce. In addition to the payment source, the request must also include the amount to accept for the payment. There are several optional parameters that you can include in the request. For example, tip money, whether to autocomplete the payment, or a reference ID to correlate this payment with another system. For more information about these payment options, see Take Payments. The PAYMENTS_WRITE_ADDITIONAL_RECIPIENTS OAuth permission is required to enable application fees.

Example

<?php
require_once(__DIR__ . '/vendor/autoload.php');

// Configure OAuth2 access token for authorization: oauth2
SquareConnect\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');

$apiInstance = new SquareConnect\Api\PaymentsApi();
$body = new \SquareConnect\Model\CreatePaymentRequest(); // \SquareConnect\Model\CreatePaymentRequest | An object containing the fields to POST for the request.  See the corresponding object definition for field details.

try {
    $result = $apiInstance->createPayment($body);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling PaymentsApi->createPayment: ', $e->getMessage(), PHP_EOL;
}
?>

Parameters

NameTypeDescriptionNotes
body\SquareConnect\Model\CreatePaymentRequestAn object containing the fields to POST for the request. See the corresponding object definition for field details.

Return type

\SquareConnect\Model\CreatePaymentResponse

Authorization

oauth2

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json

[Back to top] [Back to API list] [Back to Model list] [Back to README]

getPayment

\SquareConnect\Model\GetPaymentResponse getPayment($payment_id)

GetPayment

Retrieves details for a specific Payment.

Example

<?php
require_once(__DIR__ . '/vendor/autoload.php');

// Configure OAuth2 access token for authorization: oauth2
SquareConnect\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');

$apiInstance = new SquareConnect\Api\PaymentsApi();
$payment_id = "payment_id_example"; // string | Unique ID for the desired `Payment`.

try {
    $result = $apiInstance->getPayment($payment_id);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling PaymentsApi->getPayment: ', $e->getMessage(), PHP_EOL;
}
?>

Parameters

NameTypeDescriptionNotes
payment_idstringUnique ID for the desired `Payment`.

Return type

\SquareConnect\Model\GetPaymentResponse

Authorization

oauth2

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json

[Back to top] [Back to API list] [Back to Model list] [Back to README]

listPayments

\SquareConnect\Model\ListPaymentsResponse listPayments(begintime,begin_time, end_time, sortorder,sort_order, cursor, locationid,location_id, total, last4,last_4, card_brand)

ListPayments

Retrieves a list of payments taken by the account making the request. Max results per page: 100

Example

<?php
require_once(__DIR__ . '/vendor/autoload.php');

// Configure OAuth2 access token for authorization: oauth2
SquareConnect\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');

$apiInstance = new SquareConnect\Api\PaymentsApi();
$begin_time = "begin_time_example"; // string | Timestamp for the beginning of the reporting period, in RFC 3339 format. Inclusive. Default: The current time minus one year.
$end_time = "end_time_example"; // string | Timestamp for the end of the requested reporting period, in RFC 3339 format.  Default: The current time.
$sort_order = "sort_order_example"; // string | The order in which results are listed. - `ASC` - oldest to newest - `DESC` - newest to oldest (default).
$cursor = "cursor_example"; // string | A pagination cursor returned by a previous call to this endpoint. Provide this to retrieve the next set of results for the original query.  See [Pagination](https://developer.squareup.com/docs/basics/api101/pagination) for more information.
$location_id = "location_id_example"; // string | Limit results to the location supplied. By default, results are returned for all locations associated with the merchant.
$total = 789; // int | The exact amount in the total_money for a `Payment`.
$last_4 = "last_4_example"; // string | The last 4 digits of `Payment` card.
$card_brand = "card_brand_example"; // string | The brand of `Payment` card. For example, `VISA`

try {
    $result = $apiInstance->listPayments($begin_time, $end_time, $sort_order, $cursor, $location_id, $total, $last_4, $card_brand);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling PaymentsApi->listPayments: ', $e->getMessage(), PHP_EOL;
}
?>

Parameters

NameTypeDescriptionNotes
begin_timestringTimestamp for the beginning of the reporting period, in RFC 3339 format. Inclusive. Default: The current time minus one year.[optional]
end_timestringTimestamp for the end of the requested reporting period, in RFC 3339 format. Default: The current time.[optional]
sort_orderstringThe order in which results are listed. - `ASC` - oldest to newest - `DESC` - newest to oldest (default).[optional]
cursorstringA pagination cursor returned by a previous call to this endpoint. Provide this to retrieve the next set of results for the original query. See Pagination for more information.[optional]
location_idstringLimit results to the location supplied. By default, results are returned for all locations associated with the merchant.[optional]
totalintThe exact amount in the total_money for a `Payment`.[optional]
last_4stringThe last 4 digits of `Payment` card.[optional]
card_brandstringThe brand of `Payment` card. For example, `VISA`[optional]

Return type

\SquareConnect\Model\ListPaymentsResponse

Authorization

oauth2

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json

[Back to top] [Back to API list] [Back to Model list] [Back to README]