|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace MusahMusah\LaravelMultipaymentGateways\Services; |
| 4 | + |
| 5 | +use MusahMusah\LaravelMultipaymentGateways\Contracts\HttpClientWrapperContract; |
| 6 | +use MusahMusah\LaravelMultipaymentGateways\Traits\ConsumesExternalServices; |
| 7 | + |
| 8 | +class HttpClientWrapper implements HttpClientWrapperContract |
| 9 | +{ |
| 10 | + use ConsumesExternalServices; |
| 11 | + |
| 12 | + public function __construct(protected $baseUri) |
| 13 | + {} |
| 14 | + |
| 15 | + /** |
| 16 | + * Send a GET request to the payment gateway |
| 17 | + */ |
| 18 | + public function get(string $url, array $headers = [], array $query = [], bool $isJsonRequest = true): mixed |
| 19 | + { |
| 20 | + return $this->makeRequest( |
| 21 | + method: 'GET', |
| 22 | + requestUrl: $url, |
| 23 | + isJsonRequest: $isJsonRequest, |
| 24 | + queryParams: $query, |
| 25 | + headers: $headers |
| 26 | + ); |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * Send a POST request to the payment gateway |
| 31 | + */ |
| 32 | + public function post(string $url, array $headers = [], array $formParams = [], array $query = [], bool $isJsonRequest = true): mixed |
| 33 | + { |
| 34 | + return $this->makeRequest( |
| 35 | + method: 'POST', |
| 36 | + requestUrl: $url, |
| 37 | + formParams: $formParams, |
| 38 | + isJsonRequest: $isJsonRequest, |
| 39 | + queryParams: $query, |
| 40 | + headers: $headers |
| 41 | + ); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * Send a PUT request to the payment gateway |
| 46 | + */ |
| 47 | + public function put(string $url, array $formParams = [], array $query = [], array $headers = [], bool $isJsonRequest = true): mixed |
| 48 | + { |
| 49 | + return $this->makeRequest( |
| 50 | + method: 'PUT', |
| 51 | + requestUrl: $url, |
| 52 | + formParams: $formParams, |
| 53 | + isJsonRequest: $isJsonRequest, |
| 54 | + queryParams: $query, |
| 55 | + headers: $headers |
| 56 | + ); |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * Send a PATCH request to the payment gateway |
| 61 | + */ |
| 62 | + public function patch(string $url, array $formParams = [], array $query = [], array $headers = [], bool $isJsonRequest = true): mixed |
| 63 | + { |
| 64 | + return $this->makeRequest( |
| 65 | + method: 'PATCH', |
| 66 | + requestUrl: $url, |
| 67 | + formParams: $formParams, |
| 68 | + isJsonRequest: $isJsonRequest, |
| 69 | + headers: $headers |
| 70 | + ); |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * Send a DELETE request to the payment gateway |
| 75 | + */ |
| 76 | + public function delete(string $url, array $formParams = [], array $query = [], array $headers = [], bool $isJsonRequest = true): mixed |
| 77 | + { |
| 78 | + return $this->makeRequest( |
| 79 | + method: 'DELETE', |
| 80 | + requestUrl: $url, |
| 81 | + formParams: $formParams, |
| 82 | + isJsonRequest: $isJsonRequest, |
| 83 | + queryParams: $query, |
| 84 | + headers: $headers |
| 85 | + ); |
| 86 | + } |
| 87 | + |
| 88 | + public function decodeResponse(): array |
| 89 | + { |
| 90 | + return json_decode($this->response, true); |
| 91 | + } |
| 92 | +} |
0 commit comments