goldcarrot/tinkoff-cashier

Tinkoff merchant API

1.0 2021-10-28 17:57 UTC

This package is auto-updated.

Last update: 2024-05-29 00:02:38 UTC


README

PHP implementation of Tinkoff Merchant API v2.

Installation

composer require goldcarrot/tinkoff-cashier

How to use

use GuzzleHttp\Client;
use Goldcarrot\Cashiers\Tinkoff\Tinkoff;

$client = new Client();
$terminalKey = 'your-terminal-key';
$password = 'your-password';

$bankApi = new Tinkoff($client, $terminalKey, $password);

Creating a payment

use Goldcarrot\Cashiers\Tinkoff\Values\Init;

$orderId = 'your-order-id';
$data = new Init($orderId);
$data
    ->setAmount(1000)
    ->setSuccessURL("https://site.com/invoice/$orderId/success");
    
$response = $bankApi->init($data);

$paymentId = $response->getPaymentId();

redirect($response->getPaymentURL());

Checking payment

use Goldcarrot\Cashiers\Tinkoff\Values\GetState;
use Goldcarrot\Cashiers\Tinkoff\Enums\PaymentStatus;

$data = GetState::make($paymentId);
    
$response = $bankApi->getState($data);

if ($response->getStatus() === PaymentStatus::CONFIRMED) {
    // after success actions
} else {
    // after failure actions
}