mirror of
https://github.com/opdavies/glassboxx-sdk-php.git
synced 2025-02-17 22:50:48 +00:00
Re-organise the src and tests directories
This commit is contained in:
parent
ae766763b2
commit
b238e6655a
26 changed files with 13 additions and 13 deletions
58
src/Request/CustomerRequest.php
Normal file
58
src/Request/CustomerRequest.php
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Opdavies\Glassboxx\Request;
|
||||
|
||||
use Opdavies\Glassboxx\Traits\UsesAuthTokenTrait;
|
||||
use Opdavies\Glassboxx\ValueObject\CustomerInterface;
|
||||
use RuntimeException;
|
||||
|
||||
final class CustomerRequest extends AbstractRequest implements CustomerRequestInterface
|
||||
{
|
||||
use UsesAuthTokenTrait;
|
||||
|
||||
/** @var CustomerInterface|null */
|
||||
protected $customer;
|
||||
|
||||
public function forCustomer(CustomerInterface $customer): AbstractRequest
|
||||
{
|
||||
$this->customer = $customer;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(): string
|
||||
{
|
||||
if (!$this->config) {
|
||||
throw new RuntimeException('There is no config');
|
||||
}
|
||||
|
||||
if (!$this->customer) {
|
||||
throw new RuntimeException('There is no customer');
|
||||
}
|
||||
|
||||
$body = [
|
||||
'customer' => [
|
||||
'created_in' => $this->config->getVendorId(),
|
||||
'email' => $this->customer->getEmailAddress(),
|
||||
'firstname' => $this->customer->getFirstName(),
|
||||
'lastname' => $this->customer->getLastName(),
|
||||
],
|
||||
];
|
||||
|
||||
$response = $this->client->request(
|
||||
'POST',
|
||||
self::ENDPOINT,
|
||||
[
|
||||
'auth_bearer' => $this->authToken,
|
||||
'headers' => [
|
||||
'Content-Type' => 'application/json',
|
||||
],
|
||||
'body' => json_encode($body),
|
||||
]
|
||||
);
|
||||
|
||||
return json_decode($response->getContent());
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue