|
17 | 17 | use RetailCrm\Api\Model\Response\Payments\PaymentCheckResponse; |
18 | 18 | use RetailCrm\Api\Model\Response\Payments\PaymentCreateInvoiceResponse; |
19 | 19 | use RetailCrm\Api\Model\Response\Payments\PaymentGetInvoiceResponse; |
| 20 | +use RetailCrm\Api\Model\Response\Payments\PaymentImportInvoiceResponse; |
20 | 21 | use RetailCrm\Api\Model\Response\SuccessResponse; |
21 | 22 |
|
22 | 23 | /** |
@@ -259,14 +260,67 @@ public function getInvoice(string $invoiceUuid): PaymentGetInvoiceResponse |
259 | 260 | return $response; |
260 | 261 | } |
261 | 262 |
|
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 |
263 | 317 | { |
264 | | - /** @var SuccessResponse $response */ |
| 318 | + /** @var PaymentImportInvoiceResponse $response */ |
265 | 319 | $response = $this->sendRequest( |
266 | 320 | RequestMethod::POST, |
267 | 321 | 'payment/invoice/import', |
268 | 322 | $request, |
269 | | - SuccessResponse::class |
| 323 | + PaymentImportInvoiceResponse::class |
270 | 324 | ); |
271 | 325 |
|
272 | 326 | return $response; |
|
0 commit comments