Skip to content

Commit bc5157a

Browse files
Merge pull request #3 from maksimEgo/feat_new_taxes
Feat new taxes
2 parents f60da98 + 6991f2a commit bc5157a

4 files changed

Lines changed: 62 additions & 0 deletions

File tree

composer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
"authors": [
1212
{
1313
"name": "Igor Fedorov",
14+
"role": "Original Developer"
15+
},
16+
{
17+
"name": "Maksim Ego",
1418
"role": "Developer"
1519
}
1620
],

src/Options/InvoiceOptions.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,14 @@ class InvoiceOptions
109109
* Если параметр не передан, то используются региональные настройки браузера покупателя.
110110
* Для значений отличных от ru или en используется английский язык.
111111
* @param string|null $signatureValue
112+
* @param int|null $previousInvoiceId - айди прошлого платежа, для проведения рекуррентных оплат
113+
* доступна только при подверждение такого типа оплат в робокассе
112114
*/
113115
public function __construct(
114116
float|string $outSum,
115117
public readonly int|null $invId,
116118
public readonly string $description,
119+
public readonly int|null $previousInvoiceId = null,
117120
public readonly Receipt|string|null $receipt = null,
118121
DateTimeInterface|string|null $expirationDate = null,
119122
public readonly ?string $email = null,

src/Params/Receipt/Tax.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,22 @@ enum Tax: string
3434
* – НДС чека по расчетной ставке 20/120
3535
*/
3636
case vat120 = 'vat120';
37+
/**
38+
* – НДС по ставке 5%
39+
*/
40+
case vat5 = 'vat5';
41+
/**
42+
* – НДС по ставке 7%
43+
*/
44+
case vat7 = 'vat7';
45+
/**
46+
* – НДС чека по расчетной ставке 5/105
47+
*/
48+
case vat105 = 'vat105';
49+
/**
50+
* – НДС чека по расчетной ставке 7/107
51+
*/
52+
case vat107 = 'vat107';
3753

3854
public function getTaxSumFromItemSum(string $sum): string
3955
{
@@ -48,6 +64,10 @@ private function getTaxMultiplier(): float|int
4864
self::vat110 => 10 / 110,
4965
self::vat20 => 0.2,
5066
self::vat120 => 20 / 120,
67+
self::vat5 => 0.05,
68+
self::vat7 => 0.07,
69+
self::vat105 => 5 / 105,
70+
self::vat107 => 7 / 107,
5171
};
5272
}
5373
}

src/RobokassaApi.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,47 @@ public function getPaymentUrl(InvoiceOptions $invoiceOptions): string
109109
return $this->paymentUrl . '?' . http_build_query($this->getPaymentParameters($invoiceOptions));
110110
}
111111

112+
/**
113+
* Sends a recurring payment request to the Robokassa API.
114+
*
115+
* This method constructs and sends a POST request to the Robokassa recurring payment URL.
116+
* The request includes the necessary parameters in the request body, encoded as `application/x-www-form-urlencoded`.
117+
*
118+
* @param array $params The parameters to include in the recurring payment request. These should include all necessary fields
119+
* such as `MerchantLogin`, `InvoiceID`, `PreviousInvoiceID`, `OutSum`, `Description`, and others required by Robokassa.
120+
*
121+
* @return \Psr\Http\Message\ResponseInterface The HTTP response returned by the Robokassa API. The response contains the status
122+
* and any other relevant information returned by the API.
123+
*
124+
* @throws \RuntimeException If the returned response does not implement the expected `Psr\Http\Message\ResponseInterface`.
125+
*/
126+
public function sendRecurringPayment(array $params): ResponseInterface
127+
{
128+
$psr18Client = $this->getPsr18Client();
129+
130+
$bodyStream = $psr18Client->createStream(http_build_query($params));
131+
132+
$request = $psr18Client
133+
->createRequest('POST', $this->recurringUrl)
134+
->withHeader('Content-Type', 'application/x-www-form-urlencoded')
135+
->withBody($bodyStream);
136+
137+
$response = $psr18Client->sendRequest($request);
138+
139+
if (!$response instanceof ResponseInterface) {
140+
throw new \RuntimeException('Returned response does not implement Psr\Http\Message\ResponseInterface');
141+
}
142+
143+
return $response;
144+
}
145+
112146
public function getPaymentParameters(InvoiceOptions $invoiceOptions): array
113147
{
114148
return [
115149
'MerchantLogin' => $this->merchantLogin,
116150
'OutSum' => $invoiceOptions->outSum,
117151
'Description' => $invoiceOptions->description,
152+
'PreviousInvoiceID' => $invoiceOptions->previousInvoiceId ?? null,
118153
'SignatureValue' => $invoiceOptions->signatureValue ?? $this->generateSignatureForPayment($invoiceOptions),
119154
'IncCurrLabel' => $invoiceOptions->incCurrLabel,
120155
'InvId' => isset($invoiceOptions->invId) ? (string)$invoiceOptions->invId : null,

0 commit comments

Comments
 (0)