cashier-provider / tinkoff-qr
Driver for payment with QR codes via Tinkoff (see cashier-provider/core)
Fund package maintenance!
TheDragonCode
Open Collective
Boosty
Yoomoney
Installs: 4 430
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^7.3 || ^8.0
- cashier-provider/core: ^3.0
- cashier-provider/tinkoff-auth: ^3.0
- psr/http-message: ^1.0
Requires (Dev)
- ext-json: *
- dragon-code/support: ^5.0
- illuminate/database: ^6.0 || ^7.0 || ^8.0 || ^9.0
- orchestra/testbench: ^4.0 || ^5.0 || ^6.0 || ^7.0
- phpunit/phpunit: ^9.0
- symfony/var-dumper: ^4.0 || ^5.0 || ^6.0
- dev-main
- v3.0.0
- 2.x-dev
- v2.1.0
- v2.0.1
- v2.0.0
- 1.x-dev
- v1.6.0
- v1.5.2
- v1.5.1
- v1.5.0
- v1.4.0
- v1.3.0
- v1.2.0
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.0
- v1.0-RC7
- v1.0-RC6
- v1.0-RC5
- v1.0-RC4
- v1.0-RC3
- v1.0-RC2
- v1.0-RC1
- v1.0-BETA5
- v1.0-BETA4
- v1.0-BETA3
- v1.0-BETA2
- v1.0-BETA1
- dev-dependabot/github_actions/TheDragonCode/codestyler-3.0.4
This package is auto-updated.
Last update: 2023-06-05 11:12:53 UTC
README
Installation
To get the latest version of Tinkoff QR Cashier Driver
, simply require the project using Composer:
$ composer require cashier-provider/tinkoff-qr
Or manually update require
block of composer.json
and run composer update
.
{ "require": { "cashier-provider/tinkoff-qr": "^2.0" } }
Using
Note:
This project is the driver for Cashier.
Terminal Key and Secret must be provided by the bank manager in response to the agreement concluded with the bank.
Configuration
Add your driver information to the config/cashier.php
file:
use App\Models\Payment; use App\Payments\Tinkoff as TinkoffQrDetails; use CashierProvider\Core\Constants\Driver; use CashierProvider\Tinkoff\QrCode\Driver as TinkoffQrDriver; return [ 'payment' => [ 'map' => [ Payment::TYPE_TINKOFF => 'tinkoff_qr' ] ], 'drivers' => [ 'tinkoff_qr' => [ Driver::DRIVER => TinkoffQrDriver::class, Driver::DETAILS => TinkoffQrDetails::class, Driver::CLIENT_ID => env('CASHIER_TINKOFF_QR_CLIENT_ID'), Driver::CLIENT_SECRET => env('CASHIER_TINKOFF_QR_CLIENT_SECRET'), ] ] ];
Resource
Create a model resource class inheriting from CashierProvider\Core\Resources\Model
in your application.
Use the $this->model
link to refer to the payment model. When executed, the $model
parameter will contain the payment instance.
namespace App\Payments; use CashierProvider\Core\Resources\Model; class Tinkoff extends Model { protected function paymentId(): string { return (string) $this->model->id; } protected function sum(): float { return (float) $this->model->sum; } protected function currency(): int { return $this->model->currency; } protected function createdAt(): Carbon { return $this->model->created_at; } }
Custom Authentication
In some cases, the application can send requests to the bank from different terminals. For example, when one application serves payments of several companies.
In order for the payment to be authorized with the required authorization data, you can override the clientId
and clientSecret
methods:
namespace App\Payments; use App\Models\Payment; use CashierProvider\Core\Resources\Model; use Illuminate\Database\Eloquent\Builder; class Tinkoff extends Model { protected $bank; protected function clientId(): string { return $this->bank()->client_id; } protected function clientSecret(): string { return $this->bank()->client_secret; } protected function paymentId(): string { return (string) $this->model->id; } protected function sum(): float { return (float) $this->model->sum; } protected function currency(): int { return $this->model->currency; } protected function createdAt(): Carbon { return $this->model->created_at; } protected function bank() { if (! empty($this->bank)) { return $this->bank; } return $this->bank = $this->model->types() ->where('type', Payment::TYPE_TINKOFF) ->firstOrFail() ->bank; } }
Response
All requests to the bank and processing of responses are carried out by the Cashier
project.
To get a link, contact him through the cast:
use App\Models\Payment; public function getQrCode(Payment $payment): string { return $payment->cashier->details->getUrl(); }
Available Methods And Details Data
$payment->cashier->external_id // Returns the bank's transaction ID for this operation $payment->cashier->details->getStatus(): ?string // Returns the text status from the bank // For example, `NEW`. $payment->cashier->details->getUrl(): ?string // If the request to get the link was successful, it will return the URL // For example, `https://qr.nspk.ru/<hash>?<params>` $payment->cashier->details->toArray(): array // Returns an array of status and URL. // For example, // // [ // 'url' => 'https://qr.nspk.ru/<hash>?<params>', // 'status' => 'NEW' // ]