1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Larium\Pay\Gateway; |
4
|
|
|
|
5
|
|
|
use Larium\Pay\Client\RestClient; |
6
|
|
|
|
7
|
|
|
abstract class RestGateway extends Gateway |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Get the base uri for gateway to make the requests. |
11
|
|
|
* |
12
|
|
|
* @return string |
13
|
|
|
*/ |
14
|
|
|
abstract protected function getBaseUri(); |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Authenticate gateway. |
18
|
|
|
* It is common for rest gateways to authenticate with basic auth, bearer |
19
|
|
|
* or custom header authentication. |
20
|
|
|
* So here we can add directly to client the appropriate authentication |
21
|
|
|
* info. |
22
|
|
|
* |
23
|
|
|
* @param Larium\Pay\Client\Client $client |
24
|
|
|
* @return void |
25
|
|
|
*/ |
26
|
|
|
abstract protected function authenticate(RestClient $client); |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Returns the RestClient for given resource name. |
30
|
|
|
* |
31
|
|
|
* Resource name is usually the uri path for the resource to call. |
32
|
|
|
* In conjuction with base uri will create the full endpoint uri of |
33
|
|
|
* gateway to request. |
34
|
|
|
* |
35
|
|
|
* @param string $resource |
36
|
|
|
* @return Larium\Pay\Client\RestClient. |
|
|
|
|
37
|
|
|
*/ |
38
|
1 |
|
protected function getRestClient($resource) |
39
|
|
|
{ |
40
|
|
|
$client = $this->createClient($this->getBaseUri(), $resource); |
41
|
|
|
$this->authenticate($client); |
42
|
|
|
|
43
|
1 |
|
return $client; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Factory method for creating the rest client. |
48
|
|
|
* |
49
|
|
|
* @param string $uri The base uri path of gateway. |
50
|
|
|
* @param string $resource The resource path to request. |
51
|
|
|
* @return Larium\Pay\Client\RestClient. |
|
|
|
|
52
|
|
|
*/ |
53
|
|
|
protected function createClient($uri, $resource) |
54
|
|
|
{ |
55
|
|
|
return new RestClient($uri, $resource); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Returns the final Response object |
60
|
|
|
* |
61
|
|
|
* @param array $response The response returned from RestClient @see |
62
|
|
|
* RestClient::resolveResponse method |
63
|
|
|
* @return Larium\Pay\Response |
64
|
|
|
*/ |
65
|
1 |
|
protected function getResponse(array $response) |
66
|
|
|
{ |
67
|
1 |
|
return $this->createResponse( |
68
|
1 |
|
$this->success($response), |
69
|
1 |
|
$this->message($response), |
70
|
1 |
|
$this->transactionId($response), |
71
|
1 |
|
$this->errorCode($response), |
72
|
1 |
|
$this->responseCode($response), |
73
|
1 |
|
$response['body'], |
74
|
1 |
|
$response['raw_response'], |
75
|
1 |
|
$response['raw_request'] |
76
|
|
|
); |
77
|
1 |
|
} |
78
|
|
|
} |
79
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.