2017 © Pedro Peláez
 

library php-sdk

Kassa.com PHP SDK

image

kassacom/php-sdk

Kassa.com PHP SDK

  • Wednesday, June 20, 2018
  • by kassacom
  • Repository
  • 0 Watchers
  • 0 Stars
  • 32 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Kassa.com PHP SDK

Latest Stable Version Total Downloads Latest Unstable Version, (*1)

Documentation: https://kassa.com/help/, (*2)

Requirements

PHP 5.5 and later., (*3)

Dependencies

The bindings require the following extensions in order to work properly:, (*4)

Optionally - guzzlehttp/guzzle for use guzzle instead of cURL., (*5)

Composer

You can install the lib via Composer. Run the following command:, (*6)

composer require kassacom/php-sdk

To use the bindings, use Composer's autoload:, (*7)

require_once('vendor/autoload.php');

If you use Composer, these dependencies should be handled automatically., (*8)

Getting Started

We recommend using the GuzzleHttp Client, (*9)

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: 1. Create request instance of KassaCom\SDK\Model\Request\AbstractRequest 1. Request serialization 1. Sending a request to the server 1. You have a response object instance of KassaCom\SDK\Model\Response\AbstractResponse or throws exception if request fail, (*10)

All requests are creating by suitable objects or can be created on the basis of arrays, integers and strings, (*11)

Create payment

Creating request with object, (*12)

// 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, (*13)

$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, (*14)

// 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, (*15)

$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, (*16)

// 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, (*17)

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, (*18)

// 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, (*19)

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, (*20)

// 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, (*21)

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, (*22)

// 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, (*23)

$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, (*24)

// 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, (*25)

$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, (*26)

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

Payments report

Download report file, (*27)

$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, (*28)

$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, (*29)

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

You can use manual response to server:, (*30)

$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, (*31)

$notification->setSkipIpCheck();

Custom Api Transport

You can create your own api transport by extending KassaCom\SDK\Transport\AbstractApiTransport, (*32)

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

The Versions

20/06 2018

dev-master

9999999-dev

Kassa.com PHP SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

by Kassa.com Developers

payment pay sdk money cards payments kassa.com