@@ -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