|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tamara; |
| 4 | + |
| 5 | +use Tamara\HttpClient\HttpClient; |
| 6 | +use Tamara\Request\Order\AuthoriseOrderRequest; |
| 7 | +use Tamara\Request\Checkout\CreateCheckoutRequest; |
| 8 | +use Tamara\Request\Checkout\GetPaymentTypesRequest; |
| 9 | +use Tamara\Request\Order\CancelOrderRequest; |
| 10 | +use Tamara\Request\Payment\CaptureRequest; |
| 11 | +use Tamara\Request\Payment\RefundRequest; |
| 12 | +use Tamara\Request\RequestDispatcher; |
| 13 | +use Tamara\Response\ClientResponse; |
| 14 | +use Tamara\Response\Order\AuthoriseOrderResponse; |
| 15 | +use Tamara\Response\Checkout\GetPaymentTypesResponse; |
| 16 | +use Tamara\Response\Checkout\CreateCheckoutResponse; |
| 17 | +use Tamara\Response\Payment\CancelResponse; |
| 18 | +use Tamara\Response\Payment\CaptureResponse; |
| 19 | +use Tamara\Response\Payment\RefundResponse; |
| 20 | + |
| 21 | +class Client |
| 22 | +{ |
| 23 | + /** |
| 24 | + * @var string |
| 25 | + */ |
| 26 | + public const VERSION = '1.0.0'; |
| 27 | + |
| 28 | + /** |
| 29 | + * @var HttpClient |
| 30 | + */ |
| 31 | + protected $httpClient; |
| 32 | + |
| 33 | + /** |
| 34 | + * @var RequestDispatcher |
| 35 | + */ |
| 36 | + private $requestDispatcher; |
| 37 | + |
| 38 | + /** |
| 39 | + * @param Configuration $configuration |
| 40 | + * |
| 41 | + * @return Client |
| 42 | + */ |
| 43 | + public static function create(Configuration $configuration): Client |
| 44 | + { |
| 45 | + return new static($configuration->createHttpClient()); |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * @param HttpClient $httpClient |
| 50 | + */ |
| 51 | + public function __construct(HttpClient $httpClient) |
| 52 | + { |
| 53 | + $this->httpClient = $httpClient; |
| 54 | + $this->requestDispatcher = new RequestDispatcher($httpClient); |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * @param string $countryCode |
| 59 | + * |
| 60 | + * @return GetPaymentTypesResponse |
| 61 | + * |
| 62 | + * @throws Exception\RequestDispatcherException |
| 63 | + */ |
| 64 | + public function getPaymentTypes(string $countryCode): GetPaymentTypesResponse |
| 65 | + { |
| 66 | + return $this->requestDispatcher->dispatch(new GetPaymentTypesRequest($countryCode)); |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * @param CreateCheckoutRequest $createCheckoutRequest |
| 71 | + * |
| 72 | + * @return CreateCheckoutResponse |
| 73 | + * |
| 74 | + * @throws Exception\RequestDispatcherException |
| 75 | + */ |
| 76 | + public function createCheckout(CreateCheckoutRequest $createCheckoutRequest): CreateCheckoutResponse |
| 77 | + { |
| 78 | + return $this->requestDispatcher->dispatch($createCheckoutRequest); |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * @param AuthoriseOrderRequest $authoriseOrderRequest |
| 83 | + * |
| 84 | + * @return AuthoriseOrderResponse |
| 85 | + * |
| 86 | + * @throws Exception\RequestDispatcherException |
| 87 | + */ |
| 88 | + public function authoriseOrder(AuthoriseOrderRequest $authoriseOrderRequest): AuthoriseOrderResponse |
| 89 | + { |
| 90 | + return $this->requestDispatcher->dispatch($authoriseOrderRequest); |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * @param CancelOrderRequest $cancelOrderRequest |
| 95 | + * |
| 96 | + * @return CancelResponse |
| 97 | + * |
| 98 | + * @throws Exception\RequestDispatcherException |
| 99 | + */ |
| 100 | + public function cancelOrder(CancelOrderRequest $cancelOrderRequest): CancelResponse |
| 101 | + { |
| 102 | + return $this->requestDispatcher->dispatch($cancelOrderRequest); |
| 103 | + } |
| 104 | + |
| 105 | + /** |
| 106 | + * @param CaptureRequest $captureRequest |
| 107 | + * |
| 108 | + * @return CaptureResponse |
| 109 | + * |
| 110 | + * @throws Exception\RequestDispatcherException |
| 111 | + */ |
| 112 | + public function capture(CaptureRequest $captureRequest): CaptureResponse |
| 113 | + { |
| 114 | + return $this->requestDispatcher->dispatch($captureRequest); |
| 115 | + } |
| 116 | + |
| 117 | + /** |
| 118 | + * @param RefundRequest $refundRequest |
| 119 | + * |
| 120 | + * @return RefundResponse |
| 121 | + * |
| 122 | + * @throws Exception\RequestDispatcherException |
| 123 | + */ |
| 124 | + public function refund(RefundRequest $refundRequest): RefundResponse |
| 125 | + { |
| 126 | + return $this->requestDispatcher->dispatch($refundRequest); |
| 127 | + } |
| 128 | +} |
0 commit comments