square/connect
最新稳定版本:3.20200528.1
Composer 安装命令:
composer require square/connect
包简介
This Package is deprecated, it is replaced by https://packagist.org/packages/square/square.
README 文档
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
SquareConnectmodels with the newSquareequivalents - 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!
square/connect 适用场景与选型建议
square/connect 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.24M 次下载、GitHub Stars 达 114, 最近一次更新时间为 2026 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「api」 「sdk」 「swagger」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 square/connect 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 square/connect 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 square/connect 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
Alfabank REST API integration
Zero-dependency raw PHP DNS resolver, domain-ownership verification, and intoDNS/MxToolbox-style diagnostics. Queries authoritative nameservers directly over sockets — never trusts the recursive cache for ownership checks.
A lightweight plain-PHP framework for database-backed CRUD APIs.
bughq error tracking - PHP SDK
ABsurge PHP SDK for feature flags and A/B testing
统计信息
- 总下载量: 1.24M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 116
- 点击次数: 29
- 依赖项目数: 8
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2026-01-04