mirror of
https://github.com/opdavies/glassboxx-sdk-php.git
synced 2025-02-17 22:50:48 +00:00
parent
7162438837
commit
0650795d60
9 changed files with 265 additions and 33 deletions
62
src/Glassboxx/Request/CustomerRequest.php
Normal file
62
src/Glassboxx/Request/CustomerRequest.php
Normal file
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Opdavies\Glassboxx\Request;
|
||||
|
||||
use Opdavies\Glassboxx\Config;
|
||||
use Opdavies\Glassboxx\ValueObject\Customer;
|
||||
use Opdavies\Glassboxx\ValueObject\CustomerInterface;
|
||||
use Symfony\Component\HttpClient\HttpClient;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
final class CustomerRequest extends AbstractRequest
|
||||
{
|
||||
public const ENDPOINT = '/glassboxxorder/customCustomer';
|
||||
|
||||
/** @var string */
|
||||
protected $authToken;
|
||||
|
||||
/** @var CustomerInterface */
|
||||
protected $customer;
|
||||
|
||||
public function forCustomer(CustomerInterface $customer): self
|
||||
{
|
||||
$this->customer = $customer;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withAuthToken(string $authToken): self
|
||||
{
|
||||
$this->authToken = $authToken;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(): string
|
||||
{
|
||||
$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::BASE_URL . 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