kassacom/php-sdk
Composer 安装命令:
composer require kassacom/php-sdk
包简介
Kassa.com PHP SDK
README 文档
README
Documentation: https://kassa.com/help/
Requirements
PHP 5.5 and later.
Dependencies
The bindings require the following extensions in order to work properly:
curl, although you can use your own non-cURL client if you prefer.jsonmbstring(Multibyte String)php-fig/logguzzlehttp/psr7
Optionally
guzzlehttp/guzzlefor use guzzle instead of cURL.
Composer
You can install the lib via Composer. Run the following command:
composer require kassacom/php-sdk
To use the bindings, use Composer's autoload:
require_once('vendor/autoload.php');
If you use Composer, these dependencies should be handled automatically.
Getting Started
We recommend using the GuzzleHttp Client
Init client
$guzzleClient = new GuzzleHttp\Client(); $transport = new KassaCom\SDK\Transport\GuzzleApiTransport($guzzleClient); $client = new KassaCom\SDK\Client($transport); $client->setAuth('login', 'secret'); // or for basic authorization $client->setAuth('login', 'password', KassaCom\SDK\Transport\Authorization\BasicAuthorization::class);
All requests are processed in similar steps:
- Create request instance of
KassaCom\SDK\Model\Request\AbstractRequest - Request serialization
- Sending a request to the server
- You have a response object instance of
KassaCom\SDK\Model\Response\AbstractResponseor throws exception if request fail
All requests are creating by suitable objects or can be created on the basis of arrays, integers and strings
Create payment
Creating request with object
// Create a request object $createPaymentRequest = new KassaCom\SDK\Model\Request\Payment\CreatePaymentRequest(); // Set up $createPaymentRequest with required params try { /** @var KassaCom\SDK\Model\Response\Payment\CreatePaymentResponse $createPaymentResponse */ $createPaymentResponse = $client->createPayment($createPaymentRequest); } catch (\Exception $e) { // ... }
or you can create request with array
$requestArray = [ 'order' => [/*...*/], 'settings' => [/*...*/], 'custom_parameters' => [/*...*/], 'receipt' => [/*...*/], ]; try { /** @var KassaCom\SDK\Model\Response\Payment\CreatePaymentResponse $createPaymentResponse */ $createPaymentResponse = $client->createPayment($requestArray); } catch (\Exception $e) { // ... }
Process payment
Creating request with object
// Create a request object $processPayment = new KassaCom\SDK\Model\Request\Payment\ProcessPaymentRequest(); // Set up $processPayment with required params try { /** @var KassaCom\SDK\Model\Response\Payment\ProcessPaymentResponse $processPaymentResponse */ $processPaymentResponse = $client->processPayment($processPayment); } catch (\Exception $e) { // ... }
or you can create request with array
$requestArray = [ 'token' => 'token', 'ip' => '127.0.0.1', 'payment_method_data' => [/*...*/], ]; try { /** @var KassaCom\SDK\Model\Response\Payment\ProcessPaymentResponse $processPaymentResponse */ $processPaymentResponse = $client->processPayment($requestArray); } catch (\Exception $e) { // ... }
Capture payment
Creating request with object
// Create a request object $capturePaymentRequest = new KassaCom\SDK\Model\Request\Payment\CapturePaymentRequest('token-string-from-create-payment-step'); try { /** @var KassaCom\SDK\Model\Response\Payment\CapturePaymentResponse $capturePaymentResponse */ $capturePaymentResponse = $client->capturePayment($capturePaymentRequest); } catch (\Exception $e) { // ... }
or you can create request with token
try { /** @var KassaCom\SDK\Model\Response\Payment\CapturePaymentResponse $capturePaymentResponse */ $processPaymentResponse = $client->processPayment('token-string-from-create-payment-step'); } catch (\Exception $e) { // ... }
Get payment info
Creating request with object
// Create a request object $getPaymentRequest = new KassaCom\SDK\Model\Request\Payment\GetPaymentRequest('token-string-from-create-payment-step'); try { /** @var KassaCom\SDK\Model\Response\Payment\GetPaymentResponse $getPaymentResponse */ $getPaymentResponse = $client->getPayment($getPaymentRequest); } catch (\Exception $e) { // ... }
or you can create request with token
try { /** @var KassaCom\SDK\Model\Response\Payment\GetPaymentResponse $getPaymentResponse */ $getPaymentResponse = $client->getPayment('token-string-from-create-payment-step'); } catch (\Exception $e) { // ... }
Cancel payment
Creating request with object
// Create a request object $cancelPaymentRequest = new KassaCom\SDK\Model\Request\Payment\CancelPaymentRequest('token-string-from-create-payment-step'); try { /** @var KassaCom\SDK\Model\Response\Payment\CancelPaymentResponse $cancelPaymentResponse */ $cancelPaymentResponse = $client->cancelPayment($cancelPaymentRequest); } catch (\Exception $e) { // ... }
or you can create request with token
try { /** @var KassaCom\SDK\Model\Response\Payment\CancelPaymentResponse $cancelPaymentResponse */ $cancelPaymentResponse = $client->cancelPayment('token-string-from-create-payment-step'); } catch (\Exception $e) { // ... }
Create payout
Creating request with object
// Create a request object $createPayoutRequest = new KassaCom\SDK\Model\Request\Payout\CreatePayoutRequest(); // Set up $createPayoutRequest with required params try { /** @var KassaCom\SDK\Model\Response\Payout\CreatePayoutResponse $createPayoutResponse */ $createPayoutResponse = $client->createPayout($createPayoutRequest); } catch (\Exception $e) { // ... }
or you can create request with array
$requestArray = [ 'transaction_id' => 'transaction_id', 'wallet_id' => 123, 'fee_type' => 'fee_type', 'payout_method_data' => [/*...*/], 'order' => [/*...*/], ]; try { /** @var KassaCom\SDK\Model\Response\Payout\CreatePayoutResponse $createPayoutResponse */ $createPayoutResponse = $client->createPayout($requestArray); } catch (\Exception $e) { // ... }
Get payout info
Creating request with object
// Create a request object $getPayoutRequest = new KassaCom\SDK\Model\Request\Payout\GetPayoutRequest(); // Set up $getPayoutRequest with required params try { /** @var KassaCom\SDK\Model\Response\Payout\GetPayoutResponse $getPayoutResponse */ $getPayoutResponse = $client->getPayout($getPayoutRequest); } catch (\Exception $e) { // ... }
or you can create request with array
$requestArray = [ 'transaction_id' => 'transaction_id', 'wallet_id' => 123, ]; try { /** @var KassaCom\SDK\Model\Response\Payout\GetPayoutResponse $getPayoutResponse */ $getPayoutResponse = $client->getPayout($requestArray); } catch (\Exception $e) { // ... }
or create by id
try { /** @var KassaCom\SDK\Model\Response\Payout\GetPayoutResponse $getPayoutResponse */ $getPayoutResponse = $client->getPayout(123); } catch (\Exception $e) { // ... }
Payments report
Download report file
$paymentsReport = new KassaCom\SDK\Model\Request\Reports\PaymentsReportRequest(); $paymentsReport->setDatetimeFrom(new \DateTime('2 weeks ago')) ->setDatetimeTo(new \DateTime()); $response = $client->getPaymentsReport($paymentsReport); http_response_code($response->getStatusCode()); $stream = $response->getBody(); foreach ($response->getHeaders() as $key => $header) { header($key . ': ' . join(',', $header)); } echo $stream->getContents();
Payouts report
Download report file
$payoutsReportRequest = new KassaCom\SDK\Model\Request\Reports\PayoutsReportRequest(); $payoutsReportRequest->setDatetimeFrom(new \DateTime('2 weeks ago')) ->setDatetimeTo(new \DateTime()); $response = $client->getPayoutsReport($payoutsReportRequest); http_response_code($response->getStatusCode()); $stream = $response->getBody(); foreach ($response->getHeaders() as $key => $header) { header($key . ': ' . join(',', $header)); } echo $stream->getContents();
Exceptions
KassaCom\SDK\Exception\TransportException- throws in the case of an api transport error. For example, when authorization data is not provided.KassaCom\SDK\Exception\JsonParseException- the server response doesn't contain a valid json.KassaCom\SDK\Exception\ServerResponse\ResponseException- 4xx and 5xx server errors.KassaCom\SDK\Exception\Response\ResponseParseException- create response errors.KassaCom\SDK\Exception\Request\RequestParseException- create request errors.
Processing notification from server
This code is responsible for processing the payment result. You need to create handler, make it available on URL in your application and specify the URL in the project settings in kassa.com. This handler will be called after the user makes a payment using the form on kassa.com
$notification = new Notification(); $notification->setApiKey('api-key'); $notification->process();
You can use manual response to server:
$notification->process(false); // if success $notification->successResponse(); // if error $notification->errorResponse('Error message');
If you use a proxy server, you can skip the IP check
$notification->setSkipIpCheck();
Custom Api Transport
You can create your own api transport by extending KassaCom\SDK\Transport\AbstractApiTransport
class MyApiTransport extends AbstractApiTransport { protected function sendRequest(Psr7\Request $request) { // Implementing the sendRequest() method } }
kassacom/php-sdk 适用场景与选型建议
kassacom/php-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 40.7k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 06 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「payment」 「money」 「payments」 「pay」 「sdk」 「cards」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kassacom/php-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kassacom/php-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kassacom/php-sdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Beyonic PHP Library
Dealing with payments through the Egyptian payment gateway PayMob
Librería para la gestión sencilla de pagos mediante TPV Redsys y Paypal
The Payum Yandex Money gateway
Handles currency for Laravel 5.8
Yii 2 package for sprintpay gateway
统计信息
- 总下载量: 40.7k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 23
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-06-07