1 | <?php |
||
20 | abstract class Gateway |
||
21 | { |
||
22 | protected $sandbox; |
||
23 | |||
24 | protected $options; |
||
25 | |||
26 | private $responseCallback; |
||
27 | |||
28 | private $transactionToMethod = [ |
||
29 | Query::class => 'query', |
||
30 | Cancel::class => 'cancel', |
||
31 | Refund::class => 'refund', |
||
32 | Capture::class => 'capture', |
||
33 | Initial::class => 'initiate', |
||
34 | Transfer::class => 'transfer', |
||
35 | Purchase::class => 'purchase', |
||
36 | Retrieve::class => 'retrieve', |
||
37 | Authorize::class => 'authorize', |
||
38 | Transaction::class => 'transaction', |
||
39 | ThreedSecureAuthenticate::class => 'threedSecureAuthenticate', |
||
40 | ]; |
||
41 | |||
42 | /** |
||
43 | * Return whether the response is success or not. |
||
44 | * |
||
45 | * $response param contains all the elements of gateway response, |
||
46 | * parsed as associative array, including http status and headers. |
||
47 | * |
||
48 | * @param array $response |
||
49 | * @return bool |
||
50 | */ |
||
51 | abstract protected function success(array $response); |
||
52 | |||
53 | /** |
||
54 | * Returns the message from gateway response. |
||
55 | * |
||
56 | * $response param contains all the elements of gateway response, |
||
57 | * parsed as associative array, including http status and headers. |
||
58 | * |
||
59 | * @param array $response |
||
60 | * @return string |
||
61 | */ |
||
62 | abstract protected function message(array $response); |
||
63 | |||
64 | /** |
||
65 | * Returns th unique transaction id from gateway response. |
||
66 | * |
||
67 | * $response param contains all the elements of gateway response, |
||
68 | * parsed as associative array, including http status and headers. |
||
69 | * |
||
70 | * @param array $response |
||
71 | * @return string |
||
72 | */ |
||
73 | abstract protected function transactionId(array $response); |
||
74 | |||
75 | /** |
||
76 | * Returns error code from gateway if exists. |
||
77 | * |
||
78 | * $response param contains all the elements of gateway response, |
||
79 | * parsed as associative array, including http status and headers. |
||
80 | * |
||
81 | * @param array $response |
||
82 | * @return string|null |
||
83 | */ |
||
84 | abstract protected function errorCode(array $response); |
||
85 | |||
86 | /** |
||
87 | * Returns response code from card processing, if exists. |
||
88 | * @link https://arch.developer.visa.com/vpp/documents/xml/Request_and_Response.html Example of response codes |
||
89 | * |
||
90 | * $response param contains all the elements of gateway response, |
||
91 | * parsed as associative array, including http status and headers. |
||
92 | * |
||
93 | * @param array $response |
||
94 | * @return string|null |
||
95 | */ |
||
96 | abstract protected function responseCode(array $response); |
||
97 | |||
98 | final public function __construct(array $options = []) |
||
104 | |||
105 | public function execute( |
||
123 | |||
124 | protected function purchase(Purchase $transaction) |
||
128 | |||
129 | protected function authorize(Authorize $transaction) |
||
133 | |||
134 | protected function capture(Capture $transaction) |
||
138 | |||
139 | protected function refund(Refund $transaction) |
||
143 | |||
144 | protected function cancel(Cancel $transaction) |
||
148 | |||
149 | protected function retrieve(Retrieve $transaction) |
||
153 | |||
154 | protected function initiate(Initial $transaction) |
||
158 | |||
159 | protected function query(Query $transaction) |
||
163 | |||
164 | protected function threedSecureAuthenticate(ThreedSecureAuthenticate $transaction) |
||
168 | |||
169 | protected function transfer(Transfer $transaction) |
||
173 | |||
174 | /** |
||
175 | * Creates and return the response from gateway. |
||
176 | * |
||
177 | * @param bool $success Whether response was success or not. |
||
178 | * @param string $message The message theat describe response status or |
||
179 | * reason. |
||
180 | * @param string $transactionId The unique identifier from transaction. |
||
181 | * @param string $errorCode The error code if transaction was failed. |
||
182 | * @param string $responsecCode The ISO 8583 response code. Not always |
||
183 | * available. |
||
184 | * @param array $payload An associative array of the response from |
||
185 | * gateway including http status and headers. |
||
186 | * @param string $rawResponse The raw response of gateway. |
||
187 | * @param string $rawRequest The raw request to gateway. |
||
188 | * |
||
189 | * @return Larium\Pay\Response|mixed Response may be a user response if $responseCallback |
||
190 | * param is used in execute method |
||
191 | */ |
||
192 | protected function createResponse( |
||
225 | } |
||
226 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.