|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file has been created by developers from BitBag. |
| 5 | + * Feel free to contact us once you face any issues or want to start |
| 6 | + * You can find more information about us on https://bitbag.io and write us |
| 7 | + * an email on hello@bitbag.io. |
| 8 | + */ |
| 9 | + |
| 10 | +declare(strict_types=1); |
| 11 | + |
| 12 | +namespace BitBag\SyliusUserComPlugin\Api; |
| 13 | + |
| 14 | +use BitBag\SyliusUserComPlugin\Trait\UserComApiAwareInterface; |
| 15 | +use Symfony\Component\HttpFoundation\Request; |
| 16 | + |
| 17 | +final class DealApi extends AbstractClient implements DealApiInterface |
| 18 | +{ |
| 19 | + public function updateDealByCustomId(UserComApiAwareInterface $resource, string $customId, array $data): ?array |
| 20 | + { |
| 21 | + $url = $this->getApiEndpointUrl($resource, sprintf(self::UPDATE_DEAL_ENDPOINT, $customId)); |
| 22 | + |
| 23 | + return $this->request( |
| 24 | + $url, |
| 25 | + Request::METHOD_PUT, |
| 26 | + $this->buildOptions($resource, ['json' => $data]), |
| 27 | + ); |
| 28 | + } |
| 29 | + |
| 30 | + public function createDeal(UserComApiAwareInterface $resource, array $data): ?array |
| 31 | + { |
| 32 | + return $this->request( |
| 33 | + $this->getApiEndpointUrl($resource, self::CREATE_DEAL_ENDPOINT), |
| 34 | + Request::METHOD_POST, |
| 35 | + $this->buildOptions($resource, [ |
| 36 | + 'json' => $data, |
| 37 | + 'headers' => [ |
| 38 | + 'Content-Type' => 'application/json', |
| 39 | + ], |
| 40 | + ]), |
| 41 | + ); |
| 42 | + } |
| 43 | + |
| 44 | + public function updateOrCreateDeal(UserComApiAwareInterface $resource, array $data): ?array |
| 45 | + { |
| 46 | + return $this->request( |
| 47 | + $this->getApiEndpointUrl($resource, self::CREATE_OR_UPDATE_DEAL_ENDPOINT), |
| 48 | + Request::METHOD_POST, |
| 49 | + $this->buildOptions($resource, [ |
| 50 | + 'json' => $data, |
| 51 | + 'headers' => [ |
| 52 | + 'Content-Type' => 'application/json', |
| 53 | + ], |
| 54 | + ]), |
| 55 | + ); |
| 56 | + } |
| 57 | +} |
0 commit comments