PHP code example of kassacom / php-sdk

1. Go to this page and download the library: Download kassacom/php-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kassacom / php-sdk example snippets




$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);

// Create a request object
$createPaymentRequest = new KassaCom\SDK\Model\Request\Payment\CreatePaymentRequest();

// Set up $createPaymentRequest with ment($createPaymentRequest);
} catch (\Exception $e) {
    // ...
}

$requestArray = [
    'order' => [/*...*/],
    'settings' => [/*...*/],
    'custom_parameters' => [/*...*/],
    'receipt' => [/*...*/],
];

try {
    /** @var KassaCom\SDK\Model\Response\Payment\CreatePaymentResponse $createPaymentResponse */
    $createPaymentResponse = $client->createPayment($requestArray);
} catch (\Exception $e) {
    // ...
}

// Create a request object
$processPayment = new KassaCom\SDK\Model\Request\Payment\ProcessPaymentRequest();

// Set up $processPayment with ent->processPayment($processPayment);
} catch (\Exception $e) {
    // ...
}

$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) {
    // ...
}

// 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) {
    // ...
}

try {
    /** @var KassaCom\SDK\Model\Response\Payment\CapturePaymentResponse $capturePaymentResponse */
    $processPaymentResponse = $client->processPayment('token-string-from-create-payment-step');
} catch (\Exception $e) {
    // ...
}

// 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) {
    // ...
}

try {
    /** @var KassaCom\SDK\Model\Response\Payment\GetPaymentResponse $getPaymentResponse */
    $getPaymentResponse = $client->getPayment('token-string-from-create-payment-step');
} catch (\Exception $e) {
    // ...
}

// 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) {
    // ...
}

try {
    /** @var KassaCom\SDK\Model\Response\Payment\CancelPaymentResponse $cancelPaymentResponse */
    $cancelPaymentResponse = $client->cancelPayment('token-string-from-create-payment-step');
} catch (\Exception $e) {
    // ...
}

// Create a request object
$createPayoutRequest = new KassaCom\SDK\Model\Request\Payout\CreatePayoutRequest();

// Set up $createPayoutRequest with out($createPayoutRequest);
} catch (\Exception $e) {
    // ...
}

$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) {
    // ...
}

// Create a request object
$getPayoutRequest = new KassaCom\SDK\Model\Request\Payout\GetPayoutRequest();

// Set up $getPayoutRequest with ($getPayoutRequest);
} catch (\Exception $e) {
    // ...
}

$requestArray = [
    'transaction_id' => 'transaction_id',
    'wallet_id' => 123,
];

try {
    /** @var KassaCom\SDK\Model\Response\Payout\GetPayoutResponse $getPayoutResponse */
    $getPayoutResponse = $client->getPayout($requestArray);
} catch (\Exception $e) {
    // ...
}

try {
    /** @var KassaCom\SDK\Model\Response\Payout\GetPayoutResponse $getPayoutResponse */
    $getPayoutResponse = $client->getPayout(123);
} catch (\Exception $e) {
    // ...
}

$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();

$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();

$notification = new Notification();
$notification->setApiKey('api-key');
$notification->process();

$notification->process(false);

// if success
$notification->successResponse();
// if error
$notification->errorResponse('Error message');

$notification->setSkipIpCheck();

class MyApiTransport extends AbstractApiTransport {
    protected function sendRequest(Psr7\Request $request) {
        // Implementing the sendRequest() method
    }
}
bash
composer