kassacom / php-sdk
Kassa.com PHP SDK
Installs: 30 212
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 6
Open Issues: 0
Requires
- php: >=5.5
- ext-curl: *
- ext-json: *
- ext-mbstring: *
- guzzlehttp/psr7: ^1.0|^2.0
- psr/log: ^1.0|^2.0|^3.0
Requires (Dev)
- guzzlehttp/guzzle: ^6.0.0
- phpunit/phpunit: ^4.8
Suggests
- guzzlehttp/guzzle: Guzzle Api Transport
- v1.9.3
- v1.9.2
- v1.9.1
- v1.9.0
- dev-master / 1.8.x-dev
- v1.8.4
- v1.8.3
- v1.8.2
- v1.8.1
- v1.8.0
- v1.7.7
- v1.7.6
- v1.7.5
- v1.7.3
- v1.7.2
- v1.7.1
- v1.7.0
- v1.6.0
- v1.5.19
- v1.5.18
- v1.5.17
- v1.5.16
- v1.5.15
- v1.5.14
- v1.5.13
- v1.5.12
- v1.5.11
- v1.5.10
- v1.5.9
- v1.5.8
- v1.5.7
- v1.5.6
- v1.5.5
- v1.5.4
- v1.5.3
- v1.5.2
- v1.5.1
- v1.5.0
- v1.4.5
- v1.4.4
- v1.4.3
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.1
- v1.3.0
- v1.2.0
- v1.1.0
- v1.0.0
This package is auto-updated.
Last update: 2024-12-17 13:56:06 UTC
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.json
mbstring
(Multibyte String)php-fig/log
guzzlehttp/psr7
Optionally
guzzlehttp/guzzle
for 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\AbstractResponse
or 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 } }