Skip to content

ClanMax/tinkoff-autopay

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Tinkoff Autopay

Small library which help you to use methods from Tinkoff API Documentation.

It was made for Laravel 7.0, but basically it working on Laravel 11 and almost all others PHP applications.

It use some of Laravel-Tinkoff functions inside.

What it's doing

Just basic things. For example, we can:

  • Add customer
  • Get customer data
  • Remove customer
  • Get card list of customer
  • Remove customer cards
  • Charge money

You have to be sure you already have permission to use this kind of function. You could ask your own manager in Tinkoff bank.

Which methods supported

To be more clear it's work with:

  • Init
  • AddCustomer
  • GetCustomer
  • RemoveCustomer
  • GetCardList
  • RemoveCard
  • Charge

This library not implement Init method in version 0.01. But it's implemented in 0.02.

Probably in some close future I will add FinishAuthorize method, but not sure right now.

What in plans

  1. FinishAuthorize probably will work
  2. Right now library not return additional values of users (email, IP, etc). Will fix it.

How does it work

Install library from composer

composer require clanmax/tinkoff-autopay

Connect library with you controller by using use

use ClanMax\TinkoffAutopay;

Logic

Step by step how to use Charge

Preparing

  1. Add customer (it will be added automatically in Init method, btw)
  2. Request Init (not included in 0.01) with CustomerKey and Recurrent parameters
  3. Redirect user to payment form from PaymentURL value

Charging

  1. Request Init without CustomerKey and Recurrent parameters
  2. Save PaymentID
  3. Request GetCardList and take from card which you want to use RebillId
  4. Request Charge with PaymentID, RebillId, and OperationInitiatorType

In this case user will be charged automatically and payment will be approved instantly.

How to use

Make sure you already have Terminal Key and Terminal Password from you bank account. For using FinishAuthorize method you can get public key when switch you terminal working mode to Mobile application.

$terminalKey = "16009807012222DEMO"; // demo may help to deploy
$terminal_password = "password";
$terminalurl = "https://securepay.tinkoff.ru/v2/";

$bank = new TinkoffAutopay($terminalurl,$terminalKey,$terminal_password);

Initial payment

Make POST request to Init with two additional parameters:

{
"Recurrent": "Y",
"CustomerKey": "clanmax",
"OperationInitiatorType": "2" // just example. check https://www.tinkoff.ru/kassa/dev/payments/#section/Peredacha-priznaka-iniciatora-operacii
}

Where CustomerKey name of already added client and Recurrent just with Y

For example:

$payment = [
  'OrderId'       => '2223',
  'Amount'        => '1000',
  'Language'      => 'ru',
  'Reccurent'     => 'Y',
  'CustomerKey'   => "clanmax",
  'Description'   => 'One month pay',
  'Email'         => 'me@email.com',
  'Phone'         => '+79517474837',
  'Name'          => 'Vlad',
  'Taxation'      => 'usn_income'
];

$items[] = [
  'Name'  => 'Something you gonna pay',
  'Price' => '1000',    
  'Tax'   => 'none',
];

$bank->Init($payment,$items);

Return will look like this:

{
	'Success' = '1',
	'Status' = 'NEW',
	'PaymentURL' = "https://securepay.tinkoff.ru/new/58NbcI0s",
	'PaymentId' = '360127329'
}

Just to be sure Tax in Items could be:

  • osn — общая
  • usn_income — упрощенная (доходы)
  • usn_income_outcome — упрощенная (доходы минус расходы)
  • patent — патентная
  • envd — единый налог на вмененный доход
  • esn — единый сельскохозяйственный налог

Charge money

Few steps:

  1. Make POST request to Init, but without Recurrent and CustomerKey
  2. Grab PaymentId from there
$charge = $bank->Charge($PaymentId,$RebillId);

Add customer

You have to make customer always before he did pay. One customer may have lots of connected cards by Init method.

$customer = $bank->AddCustomer($CustomerKey);

Get customer

Return existing customers. You have to have his name which you used before.

$customer = $bank->GetCustomer($CustomerKey);

Remove customer

Just removing all data of user. Be sure you won't use RebillId of this user anymore.

$customer = $bank->RemoveCustomer($CustomerKey);

Get card list

You will use this method for get RebillId. Return bunch of cards which user saved by Init method.

$cards = $bank->GetCardList($CustomerKey);

Remove card

If your client have tons of cards but you are not ready to use them instead of delete user you may just delete card. Just get card number from GetCardList

$cards = $bank->RemoveCard($CardId, $CustomerKey);

Find errors

I would recommend always check all request for errors by this way

$bank->error ?:  

Error keep some information and you may use it for show to user (but be aware).

Get token

In some moment you probably will need token for testing. You may use methods in TinkoffKey class.

How does it work:

  • Connect class
  • Change your data (or send you own)
  • Get data
use ClanMax\TinkoffKey;

$test = new TinkoffKey;

return $test;

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages