Skip to content

Commit 806d044

Browse files
authored
Merge pull request #23 from flowwow/FB-1722
FB-1722 add sbp payment
2 parents 9e05f3b + d89b373 commit 806d044

8 files changed

+139
-0
lines changed

src/Enum/CloudMethodsEnum.php

+6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ class CloudMethodsEnum extends Enum
4343
/** Отмена оплаты */
4444
public const PAYMENTS_VOID = 'payments/void';
4545

46+
/** Генерация платежной ссылки СБП */
47+
public const PAYMENTS_SBP_LINK = 'payments/qr/sbp/link';
48+
49+
/** Генерация QR-кода СБП */
50+
public const PAYMENTS_SBP_QR = 'payments/qr/sbp/image';
51+
4652
/** Старт сессии Applepay */
4753
public const APPLEPAY_STARTSESSION = 'applepay/startsession';
4854

src/Library.php

+26
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
use Flowwow\Cloudpayments\Request\PaymentsList;
1818
use Flowwow\Cloudpayments\Request\PaymentsListV2;
1919
use Flowwow\Cloudpayments\Request\PaymentsRefund;
20+
use Flowwow\Cloudpayments\Request\PaymentsSbpLink;
21+
use Flowwow\Cloudpayments\Request\PaymentsSbpQr;
2022
use Flowwow\Cloudpayments\Request\PaymentsVoid;
2123
use Flowwow\Cloudpayments\Request\Post3DS;
2224
use Flowwow\Cloudpayments\Request\Receipt\CorrectionReceiptData;
@@ -343,6 +345,30 @@ public function paymentsTokensList(?TokenList $data = null): TokenArrayResponse
343345
return $this->request($method, $data === null ? [] : $data->asArray(), new TokenArrayResponse());
344346
}
345347

348+
/**
349+
* Создание оплаты СБП по ссылке
350+
* @param PaymentsSbpLink $data
351+
* @return TransactionResponse
352+
*/
353+
public function paymentsSbpLink(PaymentsSbpLink $data): TransactionResponse
354+
{
355+
$method = CloudMethodsEnum::PAYMENTS_SBP_LINK;
356+
357+
return $this->request($method, $data->asArray(), new TransactionResponse());
358+
}
359+
360+
/**
361+
* Создание оплаты СБП по QR-коду
362+
* @param PaymentsSbpQr $data
363+
* @return TransactionResponse
364+
*/
365+
public function paymentsSbpQr(PaymentsSbpQr $data): TransactionResponse
366+
{
367+
$method = CloudMethodsEnum::PAYMENTS_SBP_QR;
368+
369+
return $this->request($method, $data->asArray(), new TransactionResponse());
370+
}
371+
346372
/**
347373
* Метод создания подписки на рекуррентные платежи
348374
* @param SubscriptionCreate $data

src/Request/PaymentsSbp.php

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace Flowwow\Cloudpayments\Request;
4+
5+
use Flowwow\Cloudpayments\BaseRequest;
6+
use Flowwow\Cloudpayments\Exceptions\BadTypeException;
7+
8+
/**
9+
* Class PaymentsSbp
10+
* @see https://developers.cloudpayments.ru/#sbp
11+
*
12+
*/
13+
abstract class PaymentsSbp extends BaseRequest
14+
{
15+
/**
16+
* @var int|float
17+
*/
18+
public $amount;
19+
public string $currency;
20+
public string $description;
21+
public string $scheme;
22+
public ?string $accountId;
23+
public ?string $email;
24+
public ?string $jsonData;
25+
public ?string $invoiceId;
26+
public ?string $ipAddress;
27+
public ?string $successRedirectUrl;
28+
public ?string $failRedirectUrl;
29+
public ?int $ttlMinutes;
30+
31+
/**
32+
* PaymentsSbpLink constructor.
33+
* @param $amount
34+
* @param string $currency
35+
* @param string $description
36+
* @throws BadTypeException
37+
*/
38+
public function __construct($amount, string $currency, string $description)
39+
{
40+
if (!is_numeric($amount)) {
41+
throw new BadTypeException('Amount isn\'t numeric');
42+
}
43+
$this->amount = $amount;
44+
$this->currency = $currency;
45+
$this->description = $description;
46+
$this->scheme = 'charge';
47+
}
48+
}

src/Request/PaymentsSbpLink.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Flowwow\Cloudpayments\Request;
4+
5+
/**
6+
* Class PaymentsSbpLink
7+
* @package Flowwow\Cloudpayments\CardPayment
8+
* @see https://developers.cloudpayments.ru/#sbp-poluchenie-ssylki-dlya-oplaty
9+
*
10+
*/
11+
class PaymentsSbpLink extends PaymentsSbp
12+
{
13+
}

src/Request/PaymentsSbpQr.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Flowwow\Cloudpayments\Request;
4+
5+
/**
6+
* Class PaymentsSbpQr
7+
* @package Flowwow\Cloudpayments\CardPayment
8+
* @see https://developers.cloudpayments.ru/#sbp-poluchenie-qr-koda-dlya-oplaty
9+
*
10+
*/
11+
class PaymentsSbpQr extends PaymentsSbp
12+
{
13+
}

src/Response/Models/SbpBankModel.php

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Flowwow\Cloudpayments\Response\Models;
4+
5+
/**
6+
* Class SbpBankModel
7+
* @package Flowwow\Cloudpayments\Response\Models
8+
*/
9+
class SbpBankModel extends BaseModel
10+
{
11+
public ?string $bankName = null;
12+
public ?string $logoURL = null;
13+
public ?string $schema = null;
14+
public ?string $currency = null;
15+
public ?string $package_name = null;
16+
public ?string $webClientUrl = null;
17+
public ?bool $isWebClientActive = null;
18+
}

src/Response/Models/TransactionModel.php

+5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class TransactionModel extends BaseModel
3333
public ?string $confirmDateIso = null;
3434
public ?string $authCode = null;
3535
public ?bool $testMode = null;
36+
public ?bool $isTest = null;
3637
public ?string $rrn = null;
3738
public ?int $originalTransactionId = null;
3839
public ?int $fallBackScenarioDeclinedTransactionId = null;
@@ -72,6 +73,10 @@ class TransactionModel extends BaseModel
7273
public ?bool $masterPass = null;
7374
public ?float $totalFee = null;
7475
public ?int $escrowAccumulationId = null;
76+
public ?string $qrUrl = null;
77+
public ?string $qrImage = null;
78+
/** @var SbpBankModel[]|null */
79+
public ?array $sbpBankModels = null;
7580

7681
/**
7782
* Получение переведенного кода ошибки

src/Response/TransactionResponse.php

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Flowwow\Cloudpayments\Response;
44

5+
use Flowwow\Cloudpayments\Response\Models\SbpBankModel;
56
use Flowwow\Cloudpayments\Response\Models\TransactionModel;
67
use stdClass;
78

@@ -22,6 +23,15 @@ public function fillModel($modelDate)
2223
{
2324
$model = new TransactionModel();
2425
$model->fill($modelDate);
26+
if (isset($modelDate->Banks->dictionary) && is_array($modelDate->Banks->dictionary)) {
27+
$banks = [];
28+
foreach ($modelDate->Banks->dictionary as $bankValue) {
29+
$bank = new SbpBankModel();
30+
$bank->fill($bankValue);
31+
$banks[] = $bank;
32+
}
33+
$model->sbpBankModels = $banks;
34+
}
2535

2636
$this->model = $model;
2737
}

0 commit comments

Comments
 (0)