Skip to content

Commit

Permalink
Merge pull request #23 from flowwow/FB-1722
Browse files Browse the repository at this point in the history
FB-1722 add sbp payment
  • Loading branch information
vatr666 authored Dec 24, 2024
2 parents 9e05f3b + d89b373 commit 806d044
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Enum/CloudMethodsEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ class CloudMethodsEnum extends Enum
/** Отмена оплаты */
public const PAYMENTS_VOID = 'payments/void';

/** Генерация платежной ссылки СБП */
public const PAYMENTS_SBP_LINK = 'payments/qr/sbp/link';

/** Генерация QR-кода СБП */
public const PAYMENTS_SBP_QR = 'payments/qr/sbp/image';

/** Старт сессии Applepay */
public const APPLEPAY_STARTSESSION = 'applepay/startsession';

Expand Down
26 changes: 26 additions & 0 deletions src/Library.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use Flowwow\Cloudpayments\Request\PaymentsList;
use Flowwow\Cloudpayments\Request\PaymentsListV2;
use Flowwow\Cloudpayments\Request\PaymentsRefund;
use Flowwow\Cloudpayments\Request\PaymentsSbpLink;
use Flowwow\Cloudpayments\Request\PaymentsSbpQr;
use Flowwow\Cloudpayments\Request\PaymentsVoid;
use Flowwow\Cloudpayments\Request\Post3DS;
use Flowwow\Cloudpayments\Request\Receipt\CorrectionReceiptData;
Expand Down Expand Up @@ -343,6 +345,30 @@ public function paymentsTokensList(?TokenList $data = null): TokenArrayResponse
return $this->request($method, $data === null ? [] : $data->asArray(), new TokenArrayResponse());
}

/**
* Создание оплаты СБП по ссылке
* @param PaymentsSbpLink $data
* @return TransactionResponse
*/
public function paymentsSbpLink(PaymentsSbpLink $data): TransactionResponse
{
$method = CloudMethodsEnum::PAYMENTS_SBP_LINK;

return $this->request($method, $data->asArray(), new TransactionResponse());
}

/**
* Создание оплаты СБП по QR-коду
* @param PaymentsSbpQr $data
* @return TransactionResponse
*/
public function paymentsSbpQr(PaymentsSbpQr $data): TransactionResponse
{
$method = CloudMethodsEnum::PAYMENTS_SBP_QR;

return $this->request($method, $data->asArray(), new TransactionResponse());
}

/**
* Метод создания подписки на рекуррентные платежи
* @param SubscriptionCreate $data
Expand Down
48 changes: 48 additions & 0 deletions src/Request/PaymentsSbp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Flowwow\Cloudpayments\Request;

use Flowwow\Cloudpayments\BaseRequest;
use Flowwow\Cloudpayments\Exceptions\BadTypeException;

/**
* Class PaymentsSbp
* @see https://developers.cloudpayments.ru/#sbp
*
*/
abstract class PaymentsSbp extends BaseRequest
{
/**
* @var int|float
*/
public $amount;
public string $currency;
public string $description;
public string $scheme;
public ?string $accountId;
public ?string $email;
public ?string $jsonData;
public ?string $invoiceId;
public ?string $ipAddress;
public ?string $successRedirectUrl;
public ?string $failRedirectUrl;
public ?int $ttlMinutes;

/**
* PaymentsSbpLink constructor.
* @param $amount
* @param string $currency
* @param string $description
* @throws BadTypeException
*/
public function __construct($amount, string $currency, string $description)
{
if (!is_numeric($amount)) {
throw new BadTypeException('Amount isn\'t numeric');
}
$this->amount = $amount;
$this->currency = $currency;
$this->description = $description;
$this->scheme = 'charge';
}
}
13 changes: 13 additions & 0 deletions src/Request/PaymentsSbpLink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Flowwow\Cloudpayments\Request;

/**
* Class PaymentsSbpLink
* @package Flowwow\Cloudpayments\CardPayment
* @see https://developers.cloudpayments.ru/#sbp-poluchenie-ssylki-dlya-oplaty
*
*/
class PaymentsSbpLink extends PaymentsSbp
{
}
13 changes: 13 additions & 0 deletions src/Request/PaymentsSbpQr.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Flowwow\Cloudpayments\Request;

/**
* Class PaymentsSbpQr
* @package Flowwow\Cloudpayments\CardPayment
* @see https://developers.cloudpayments.ru/#sbp-poluchenie-qr-koda-dlya-oplaty
*
*/
class PaymentsSbpQr extends PaymentsSbp
{
}
18 changes: 18 additions & 0 deletions src/Response/Models/SbpBankModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Flowwow\Cloudpayments\Response\Models;

/**
* Class SbpBankModel
* @package Flowwow\Cloudpayments\Response\Models
*/
class SbpBankModel extends BaseModel
{
public ?string $bankName = null;
public ?string $logoURL = null;
public ?string $schema = null;
public ?string $currency = null;
public ?string $package_name = null;
public ?string $webClientUrl = null;
public ?bool $isWebClientActive = null;
}
5 changes: 5 additions & 0 deletions src/Response/Models/TransactionModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class TransactionModel extends BaseModel
public ?string $confirmDateIso = null;
public ?string $authCode = null;
public ?bool $testMode = null;
public ?bool $isTest = null;
public ?string $rrn = null;
public ?int $originalTransactionId = null;
public ?int $fallBackScenarioDeclinedTransactionId = null;
Expand Down Expand Up @@ -72,6 +73,10 @@ class TransactionModel extends BaseModel
public ?bool $masterPass = null;
public ?float $totalFee = null;
public ?int $escrowAccumulationId = null;
public ?string $qrUrl = null;
public ?string $qrImage = null;
/** @var SbpBankModel[]|null */
public ?array $sbpBankModels = null;

/**
* Получение переведенного кода ошибки
Expand Down
10 changes: 10 additions & 0 deletions src/Response/TransactionResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Flowwow\Cloudpayments\Response;

use Flowwow\Cloudpayments\Response\Models\SbpBankModel;
use Flowwow\Cloudpayments\Response\Models\TransactionModel;
use stdClass;

Expand All @@ -22,6 +23,15 @@ public function fillModel($modelDate)
{
$model = new TransactionModel();
$model->fill($modelDate);
if (isset($modelDate->Banks->dictionary) && is_array($modelDate->Banks->dictionary)) {
$banks = [];
foreach ($modelDate->Banks->dictionary as $bankValue) {
$bank = new SbpBankModel();
$bank->fill($bankValue);
$banks[] = $bank;
}
$model->sbpBankModels = $banks;
}

$this->model = $model;
}
Expand Down

0 comments on commit 806d044

Please sign in to comment.