Skip to content

Commit 96fe007

Browse files
committed
Fix importInvoice
1 parent f7bfc47 commit 96fe007

File tree

3 files changed

+116
-3
lines changed

3 files changed

+116
-3
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/**
4+
* PHP version 7.3
5+
*
6+
* @category ApiImportInvoiceResponse
7+
* @package RetailCrm\Api\Model\Entity\Payments
8+
*/
9+
10+
namespace RetailCrm\Api\Model\Entity\Payments;
11+
12+
use RetailCrm\Api\Component\Serializer\Annotation as JMS;
13+
14+
/**
15+
* Class ApiImportInvoiceResponse
16+
*
17+
* @category ApiImportInvoiceResponse
18+
* @package RetailCrm\Api\Model\Entity\Payments
19+
*/
20+
class ApiImportInvoiceResponse
21+
{
22+
/**
23+
* @var string
24+
*
25+
* @JMS\Type("string")
26+
* @JMS\SerializedName("invoiceUuid")
27+
*/
28+
public $invoiceUuid;
29+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/**
4+
* PHP version 7.3
5+
*
6+
* @category PaymentImportInvoiceResponse
7+
* @package RetailCrm\Api\Model\Response\Payments
8+
*/
9+
10+
namespace RetailCrm\Api\Model\Response\Payments;
11+
12+
use RetailCrm\Api\Component\Serializer\Annotation as JMS;
13+
use RetailCrm\Api\Model\Response\SuccessResponse;
14+
15+
/**
16+
* Class PaymentImportInvoiceResponse
17+
*
18+
* @category PaymentImportInvoiceResponse
19+
* @package RetailCrm\Api\Model\Response\Payments
20+
*/
21+
class PaymentImportInvoiceResponse extends SuccessResponse
22+
{
23+
/**
24+
* @var \RetailCrm\Api\Model\Entity\Payments\ApiImportInvoiceResponse
25+
*
26+
* @JMS\Type("RetailCrm\Api\Model\Entity\Payments\ApiImportInvoiceResponse")
27+
* @JMS\SerializedName("invoice")
28+
*/
29+
public $invoice;
30+
}

src/ResourceGroup/Payments.php

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use RetailCrm\Api\Model\Response\Payments\PaymentCheckResponse;
1818
use RetailCrm\Api\Model\Response\Payments\PaymentCreateInvoiceResponse;
1919
use RetailCrm\Api\Model\Response\Payments\PaymentGetInvoiceResponse;
20+
use RetailCrm\Api\Model\Response\Payments\PaymentImportInvoiceResponse;
2021
use RetailCrm\Api\Model\Response\SuccessResponse;
2122

2223
/**
@@ -259,14 +260,67 @@ public function getInvoice(string $invoiceUuid): PaymentGetInvoiceResponse
259260
return $response;
260261
}
261262

262-
public function importInvoice(PaymentImportInvoiceRequest $request)
263+
/**
264+
* Makes POST "/api/v5/payment/invoice/import" request.
265+
*
266+
* Example:
267+
* ```php
268+
* use RetailCrm\Api\Factory\SimpleClientFactory;
269+
* use RetailCrm\Api\Interfaces\ApiExceptionInterface;
270+
* use RetailCrm\Api\Model\Entity\Payments\ApiImportInvoiceRequest;
271+
* use RetailCrm\Api\Model\Request\Payments\PaymentImportInvoiceRequest;
272+
*
273+
* $client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
274+
*
275+
* $request = new PaymentImportInvoiceRequest();
276+
* $invoice = new ApiImportInvoiceRequest();
277+
*
278+
* $invoice->paymentId = 979;
279+
* $invoice->externalId = '979';
280+
* $invoice->status = 'succeeded';
281+
* $invoice->amount = 6697.0;
282+
* $invoice->currency = 'RUB';
283+
* $invoice->createdAt = '2025-07-08 00:00:00';
284+
* $invoice->paidAt = '2025-07-08 00:10:00';
285+
*
286+
* $request->invoice = $invoice;
287+
*
288+
* try {
289+
* $response = $client->payments->importInvoice($request);
290+
* } catch (ApiExceptionInterface $exception) {
291+
* echo sprintf(
292+
* 'Error from RetailCRM API (status code: %d): %s',
293+
* $exception->getStatusCode(),
294+
* $exception->getMessage()
295+
* );
296+
*
297+
* if (count($exception->getErrorResponse()->errors) > 0) {
298+
* echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors);
299+
* }
300+
* }
301+
* ```
302+
*
303+
* @param \RetailCrm\Api\Model\Request\Payments\PaymentImportInvoiceRequest $request
304+
*
305+
* @return \RetailCrm\Api\Model\Response\Payments\PaymentImportInvoiceResponse
306+
* @throws \RetailCrm\Api\Interfaces\ApiExceptionInterface
307+
* @throws \RetailCrm\Api\Interfaces\ClientExceptionInterface
308+
* @throws \RetailCrm\Api\Exception\Api\AccountDoesNotExistException
309+
* @throws \RetailCrm\Api\Exception\Api\ApiErrorException
310+
* @throws \RetailCrm\Api\Exception\Api\MissingCredentialsException
311+
* @throws \RetailCrm\Api\Exception\Api\MissingParameterException
312+
* @throws \RetailCrm\Api\Exception\Api\ValidationException
313+
* @throws \RetailCrm\Api\Exception\Client\HandlerException
314+
* @throws \RetailCrm\Api\Exception\Client\HttpClientException
315+
*/
316+
public function importInvoice(PaymentImportInvoiceRequest $request): PaymentImportInvoiceResponse
263317
{
264-
/** @var SuccessResponse $response */
318+
/** @var PaymentImportInvoiceResponse $response */
265319
$response = $this->sendRequest(
266320
RequestMethod::POST,
267321
'payment/invoice/import',
268322
$request,
269-
SuccessResponse::class
323+
PaymentImportInvoiceResponse::class
270324
);
271325

272326
return $response;

0 commit comments

Comments
 (0)