square / connect
This Package is deprecated, it is replaced by https://packagist.org/packages/square/square.
Installs: 1 040 616
Dependents: 8
Suggesters: 0
Security: 0
Stars: 114
Watchers: 45
Forks: 51
Open Issues: 8
Requires
- php: >=5.3.3
- ext-curl: *
- ext-json: *
- ext-mbstring: *
Requires (Dev)
- phpunit/phpunit: ~4.0
- satooshi/php-coveralls: ~0.6.1
- squizlabs/php_codesniffer: ~2.0
- dev-master
- 3.20200528.1
- 3.20200528.0
- 3.20200422.2
- 3.20200422.1
- 3.20200422.0
- 3.20200325.0
- 3.20200226.0
- 2.20200122.2
- 2.20200122.1
- 2.20200122.0
- 2.20191217.1
- 2.20191217.0
- 2.20191120.0
- 2.20190925.0
- 2.20190814.2
- 2.20190814.0
- 2.20190710.0
- 2.20190612.1
- 2.20190612.0
- 2.20190508.0
- 2.20190410.1
- 2.20190410.0
- 2.20190327.1
- 2.20190327.0
- 2.20190313.1
- 2.20190313.0
- 2.20190213.0
- 2.20181212.0
- 2.20181205.0
- 2.20180918.1
- 2.20180918.0
- 2.20180712.2
- 2.20180712.1
- 2.20180712.0
- 2.9.0
- 2.8.0
- 2.7.0
- 2.6.1
- 2.6.0
- 2.5.1
- 2.5.0
- 2.4.0
- 2.3.1
- 2.3.0.20191217
- 2.3.0
- 2.2.1
- 2.2.0
- 2.1.0
- 2.0.2
- 2.0.1
- 2.0.0.1
- 2.0.0
- dev-jessiedlcs/Issue-143
- dev-jessdelacruzsantos/UpdateMigrationGuide
- dev-jessdelacruzsantos/Release
- dev-release/3.20200528.0
- dev-jessdelacruzsantos/UpdateToUseHTTPS
- dev-dina
- dev-jff/fix-readme
- dev-release/3.20200422.2
- dev-release/3.20200422.1
- dev-release/3.20200422.0
- dev-release/3.20200325.0
- dev-release/3.20200226.0
- dev-release/3.2020226.0
- dev-release/2.20200122.1
- dev-gkchestertron-patch-1
- dev-jessiedlcs/BatchHttpHeaderBug
- dev-release/2.20200122.0
- dev-release/2.20191217.1
- dev-jessiedlcs/AddVersionBadge
- dev-ssung/2.20191217.0
- dev-release/2.3.0.20191217
- dev-jessiedlcs/AddSlackAndEmailNotifications
- dev-ssung/2.20191120.0
- dev-release/2.20191120.0
- dev-release/2.20191023.0
- dev-release/2.20190925.0
- dev-release/2.20190814.2
- dev-release/2.20190814.1
- dev-release/2.20190814.0
- dev-release/2.20190724.0
- dev-release/2.20190710.0
- dev-release/2.20190612.1
- dev-release/2.20190612.0
- dev-release/2.20190508.0
- dev-release/2.20190410.1
- dev-release/2.20190410.0
- dev-test_packagist
- dev-release/2.20190327.1
- dev-release/2.20190327.0
- dev-release/2.20190313.1
- dev-release/2.20190313.0
- dev-release/2.20190213.0
- dev-release/2.20181212.0
- dev-ssung/adding_test
- dev-release/2.20181205.0
- dev-release/2.20180918.2
- dev-release/2.20180918.1
- dev-release/2.20180918.0
- dev-release/2.20180712.2
- dev-ssung/test_php_7.1
- dev-release/2.20180712.1
- dev-release/2.20180712.0
- dev-ssung/2.20180712.0
- dev-release/2.9.0
- dev-release/2.8.0
- dev-ssung/update_travis_credentials
- dev-release/2.7.0
- dev-update-composer-license-id
This package is auto-updated.
Last update: 2021-04-29 00:43:38 UTC
README
NOTICE: Square Connect PHP SDK retired
The Square Connect PHP SDK is retired (EOL) as of 2020-06-10 and will no longer receive bug fixes or product updates. To continue receiving API and SDK improvements, please follow the instructions below to migrate to the new Square PHP SDK.
The old Connect SDK documentation is available under the
/docs
folder.
Migrate to the Square PHP SDK
Follow the instructions below to migrate your apps from the deprecated
square/connect
sdk to the new library.
You need to update your app to use the Square PHP SDK instead of the Connect PHP SDK
The Square PHP SDK uses the square/square
identifier.
- On the command line, run:
$ php composer.phar require square/square
-or-
- Update your composer.json:
"require": {
...
"square/square": "^5.0.0",
...
}
Update your code
- Change all instances of
use SquareConnect\...
touse Square\...
. - Replace
SquareConnect
models with the newSquare
equivalents - Update client instantiation to follow the method outlined below.
- Update code for accessing response data to follow the method outlined below.
- Check
$apiResponse->isSuccess()
or$apiResponse->isError()
to determine if the call was a success.
To simplify your code, we also recommend that you use method chaining to access APIs instead of explicitly instantiating multiple clients.
Client instantiation
Connect SDK
require 'vendor/autoload.php'; use SquareConnect\Configuration; use SquareConnect\ApiClient; $access_token = 'YOUR_ACCESS_TOKEN'; # setup authorization $api_config = new Configuration(); $api_config->setHost("https://connect.squareup.com"); $api_config->setAccessToken($access_token); $api_client = new ApiClient($api_config);
Square SDK
require 'vendor/autoload.php'; use Square\SquareClient; use Square\Environment; // Initialize the Square client. $api_client = new SquareClient([ 'accessToken' => "YOUR_ACCESS_TOKEN", 'environment' => Environment::SANDBOX ]); // In production, the environment arg is 'production'
Example code migration
As a specific example, consider the following code for creating a new payment from the following nonce:
# Fail if the card form didn't send a value for `nonce` to the server $nonce = $_POST['nonce']; if (is_null($nonce)) { echo "Invalid card data"; http_response_code(422); return; }
With the deprecated square/connect
library, this is how you instantiate a client
for the Payments API, format the request, and call the endpoint:
use SquareConnect\Api\PaymentsApi; use SquareConnect\ApiException; $payments_api = new PaymentsApi($api_client); $request_body = array ( "source_id" => $nonce, "amount_money" => array ( "amount" => 100, "currency" => "USD" ), "idempotency_key" => uniqid() ); try { $result = $payments_api->createPayment($request_body); echo "<pre>"; print_r($result); echo "</pre>"; } catch (ApiException $e) { echo "Caught exception!<br/>"; print_r("<strong>Response body:</strong><br/>"); echo "<pre>"; var_dump($e->getResponseBody()); echo "</pre>"; echo "<br/><strong>Response headers:</strong><br/>"; echo "<pre>"; var_dump($e->getResponseHeaders()); echo "</pre>"; }
Now consider equivalent code using the new square/square
library:
require 'vendor/autoload.php'; use Square\Environment; use Square\Exceptions\ApiException; use Square\SquareClient; use Square\Models\CreatePaymentRequest; use Square\Models\Money; $payments_api = $api_client->getPaymentsApi(); $money = new Money(); $money->setAmount(100); $money->setCurrency('USD'); $create_payment_request = new CreatePaymentRequest($nonce, uniqid(), $money); try { $response = $payments_api->createPayment($create_payment_request); if ($response->isError()) { echo 'Api response has Errors'; $errors = $response->getErrors(); exit(); } echo '<pre>'; print_r($response); echo '</pre>'; } catch (ApiException $e) { echo 'Caught exception!<br/>'; exit(); }
That's it!
Ask the community
Please join us in our Square developer community if you have any questions!