Skip to content

Commit 3b59bf2

Browse files
Added support for POST /api/v5/orders/loyalty/cancel-bonus-operations method
2 parents 3c316cf + 0e8a972 commit 3b59bf2

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

lib/RetailCrm/Methods/V5/Orders.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,35 @@ public function ordersLinksCreate(array $links, $site = null)
225225
)
226226
);
227227
}
228+
229+
/**
230+
* Cancellation of bonus operations on the Loyalty Program
231+
*
232+
* @param array $order order data
233+
* @param string|null $site (default: null)
234+
*
235+
* @throws \RetailCrm\Exception\InvalidJsonException
236+
* @throws \RetailCrm\Exception\CurlException
237+
* @throws \InvalidArgumentException
238+
*
239+
* @return \RetailCrm\Response\ApiResponse
240+
*/
241+
public function cancelBonusOperations(array $order, $site = null)
242+
{
243+
if (!isset($order['id']) && !isset($order['externalId']) && !isset($order['number'])) {
244+
throw new \InvalidArgumentException(
245+
'Parameters `order` must contains a identifying data'
246+
);
247+
}
248+
249+
/* @noinspection PhpUndefinedMethodInspection */
250+
return $this->client->makeRequest(
251+
'/orders/loyalty/cancel-bonus-operations',
252+
'POST',
253+
$this->fillSite(
254+
$site,
255+
['order' => json_encode($order)]
256+
)
257+
);
258+
}
228259
}

tests/RetailCrm/Tests/Methods/Version5/ApiClientOrdersTest.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,33 @@ public function testOrdersLoyaltyApply(array $order, float $bonuses, string $sit
443443
}
444444
}
445445

446+
/**
447+
* @dataProvider ordersLoyaltyCancelBonus
448+
*
449+
* @group orders_v5
450+
*
451+
* @param array $order
452+
* @param string $site
453+
* @param string|null $exceptionClass
454+
*
455+
* @return void
456+
*/
457+
public function testCancelBonusOperations(array $order, string $site, $exceptionClass)
458+
{
459+
$client = static::getApiClient();
460+
461+
if (isset($exceptionClass)) {
462+
$this->expectException($exceptionClass);
463+
}
464+
465+
$response = $client->request->cancelBonusOperations($order, $site);
466+
467+
if (!isset($exceptionClass)) {
468+
static::assertContains($response->getStatusCode(), [200, 201]);
469+
static::assertTrue($response->isSuccessful());
470+
}
471+
}
472+
446473
/**
447474
* @return array[]
448475
*/
@@ -497,4 +524,39 @@ public function ordersLoyaltyApplyProvider(): array
497524
],
498525
];
499526
}
527+
528+
/**
529+
* @return array
530+
*/
531+
public function ordersLoyaltyCancelBonus(): array
532+
{
533+
return [
534+
'success_id' => [
535+
[
536+
'id' => 111111111,
537+
],
538+
'site',
539+
null,
540+
],
541+
'success_externalId' => [
542+
[
543+
'externalId' => 111111111,
544+
],
545+
'site',
546+
null,
547+
],
548+
'success_number' => [
549+
[
550+
'number' => '111C'
551+
],
552+
'site',
553+
null,
554+
],
555+
'error' => [
556+
[],
557+
'site',
558+
'InvalidArgumentException',
559+
]
560+
];
561+
}
500562
}

0 commit comments

Comments
 (0)