1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Ebanx fetchTransaction Request. |
4
|
|
|
*/ |
5
|
|
|
namespace Omnipay\Ebanx\Message; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Ebanx fetchTransaction Request. |
9
|
|
|
* |
10
|
|
|
* To query a payment and fetch its details, you must call the API method query. |
11
|
|
|
* You can either use the 'transactionReference' or the 'transactionId' to fetch the transaction: |
12
|
|
|
* |
13
|
|
|
* Example: |
14
|
|
|
* |
15
|
|
|
* <code> |
16
|
|
|
* // Create a gateway for the Ebanx Gateway |
17
|
|
|
* // (routes to GatewayFactory::create) |
18
|
|
|
* $gateway = Omnipay::create('Ebanx'); |
19
|
|
|
* |
20
|
|
|
* // Initialise the gateway |
21
|
|
|
* $gateway->initialize(array( |
22
|
|
|
* 'integration_key' => 'MyApiKey', |
23
|
|
|
* )); |
24
|
|
|
* |
25
|
|
|
* // Do an authorize transaction on the gateway |
26
|
|
|
* $transaction = $gateway->fetchTransaction(array( |
27
|
|
|
* 'transactionReference' => '5d5eb3389d1bce23d265b8d2376688b09a0fafc56d453252', |
28
|
|
|
* // 'transactionId' => '28937128947231897', |
29
|
|
|
* )); |
30
|
|
|
* |
31
|
|
|
* $response = $transaction->send(); |
32
|
|
|
* if ($response->isSuccessful()) { |
33
|
|
|
* echo $response->getData(); |
34
|
|
|
* } else { |
35
|
|
|
* // payment failed: display message to customer |
36
|
|
|
* exit($response->getMessage()); |
37
|
|
|
* } |
38
|
|
|
* </code> |
39
|
|
|
* |
40
|
|
|
* @see \Omnipay\Ebanx\Gateway |
41
|
|
|
* @link https://developers.ebanxpagamentos.com/api-reference/ebanx-payment-api/ebanx-payment-guide/guide-capture-a-payment/ |
42
|
|
|
*/ |
43
|
|
View Code Duplication |
class FetchTransactionRequest extends AbstractRequest |
|
|
|
|
44
|
|
|
{ |
45
|
3 |
|
public function getData() |
46
|
|
|
{ |
47
|
|
|
/* |
48
|
|
|
* As the query request the params should be passed in the query |
49
|
|
|
* not in the body, we return an empty array for the body, and |
50
|
|
|
* change the params at the getEndpoint method. |
51
|
|
|
*/ |
52
|
3 |
|
return []; |
53
|
|
|
} |
54
|
|
|
|
55
|
6 |
|
public function getEndpoint() |
56
|
|
|
{ |
57
|
6 |
|
$data = $this->getDefaultParameters(); |
58
|
6 |
|
$data['hash'] = $this->getTransactionReference(); |
59
|
6 |
|
$data['merchant_payment_code'] = $this->getTransactionId(); |
60
|
|
|
|
61
|
|
|
// Remove empty values to only send hash or merchant payment code |
62
|
6 |
|
$data = array_filter($data); |
63
|
|
|
|
64
|
6 |
|
return parent::getEndpoint() . '/query?' . http_build_query($data, '', '&'); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.