Added support for POST /api/v5/store/products/api/v5/customers/{externalId}/subscriptions
This commit is contained in:
commit
3c316cfae9
@ -141,4 +141,45 @@ trait Customers
|
|||||||
"POST"
|
"POST"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update subscriptions a customer
|
||||||
|
*
|
||||||
|
* @param array $subscriptions subscriptions data
|
||||||
|
* @param integer $customerId identifier customer
|
||||||
|
* @param string $by (default: 'externalId')
|
||||||
|
* @param string|null $site (default: null)
|
||||||
|
*
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
|
* @throws \RetailCrm\Exception\InvalidJsonException
|
||||||
|
* @throws \RetailCrm\Exception\CurlException
|
||||||
|
*
|
||||||
|
* @return \RetailCrm\Response\ApiResponse
|
||||||
|
*/
|
||||||
|
public function customerSubscriptionsUpdate(array $subscriptions, $customerId, $by = 'externalId', $site = null)
|
||||||
|
{
|
||||||
|
if (!count($subscriptions)) {
|
||||||
|
throw new \InvalidArgumentException(
|
||||||
|
'Parameter `subscriptions` must contains a data'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($customerId === null || $customerId === '') {
|
||||||
|
throw new \InvalidArgumentException(
|
||||||
|
'Parameter `customerId` is empty'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->checkIdParameter($by);
|
||||||
|
|
||||||
|
/* @noinspection PhpUndefinedMethodInspection */
|
||||||
|
return $this->client->makeRequest(
|
||||||
|
sprintf('/customers/%s/subscriptions', $customerId),
|
||||||
|
'POST',
|
||||||
|
$this->fillSite(
|
||||||
|
$site,
|
||||||
|
['subscriptions' => json_encode($subscriptions), 'by' => $by]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace RetailCrm\Tests\Methods\Version5;
|
namespace RetailCrm\Tests\Methods\Version5;
|
||||||
|
|
||||||
|
use RetailCrm\Response\ApiResponse;
|
||||||
use RetailCrm\Test\TestCase;
|
use RetailCrm\Test\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -441,4 +442,45 @@ class ApiClientCustomersTest extends TestCase
|
|||||||
static::assertTrue($responseDelete->isSuccessful(), 'Note deleted');
|
static::assertTrue($responseDelete->isSuccessful(), 'Note deleted');
|
||||||
static::assertEquals(200, $responseDelete->getStatusCode());
|
static::assertEquals(200, $responseDelete->getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCustomerSubscriptionsUpdate()
|
||||||
|
{
|
||||||
|
$clientMock = $this->getMockBuilder(\RetailCrm\Http\Client::class)
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->setMethods(['makeRequest'])
|
||||||
|
->getMock()
|
||||||
|
;
|
||||||
|
|
||||||
|
$parameters = [
|
||||||
|
'subscriptions' => [
|
||||||
|
[
|
||||||
|
'channel' => 'email',
|
||||||
|
'active' => false
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'by' => 'externalId',
|
||||||
|
'site' => 'test'
|
||||||
|
];
|
||||||
|
|
||||||
|
$clientMock->expects(self::once())->method('makeRequest')->with(
|
||||||
|
'/customers/123/subscriptions',
|
||||||
|
'POST',
|
||||||
|
[
|
||||||
|
'subscriptions' => json_encode($parameters['subscriptions']),
|
||||||
|
'by' => $parameters['by'],
|
||||||
|
'site' => $parameters['site']
|
||||||
|
]
|
||||||
|
)->willReturn((new ApiResponse(200, json_encode(['success' => true])))->asJsonResponse());
|
||||||
|
|
||||||
|
$client = static::getMockedApiClient($clientMock);
|
||||||
|
|
||||||
|
$response = $client->request->customerSubscriptionsUpdate(
|
||||||
|
$parameters['subscriptions'],
|
||||||
|
123,
|
||||||
|
$parameters['by'],
|
||||||
|
$parameters['site']
|
||||||
|
);
|
||||||
|
|
||||||
|
static::assertTrue($response->isSuccessful());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user