1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Ebanx Capture Request. |
4
|
|
|
*/ |
5
|
|
|
namespace Omnipay\Ebanx\Message; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Ebanx Capture Request. |
9
|
|
|
* |
10
|
|
|
* To capture a payment, you must call the API method capture. |
11
|
|
|
* This method applies only to authorized credit card payments where auto_capture was set to false. |
12
|
|
|
* |
13
|
|
|
* You can either use the 'transactionReference' or the 'transactionId' to capture the payment: |
14
|
|
|
* |
15
|
|
|
* Example: |
16
|
|
|
* |
17
|
|
|
* <code> |
18
|
|
|
* // Create a gateway for the Ebanx Gateway |
19
|
|
|
* // (routes to GatewayFactory::create) |
20
|
|
|
* $gateway = Omnipay::create('Ebanx'); |
21
|
|
|
* |
22
|
|
|
* // Initialise the gateway |
23
|
|
|
* $gateway->initialize(array( |
24
|
|
|
* 'integration_key' => 'MyApiKey', |
25
|
|
|
* )); |
26
|
|
|
* |
27
|
|
|
* // Do an authorize transaction on the gateway |
28
|
|
|
* $transaction = $gateway->capture(array( |
29
|
|
|
* 'transactionReference' => '5d5eb3389d1bce23d265b8d2376688b09a0fafc56d453252', |
30
|
|
|
* // 'transactionId' => '28937128947231897', |
31
|
|
|
* )); |
32
|
|
|
* |
33
|
|
|
* $response = $transaction->send(); |
34
|
|
|
* if ($response->isRedirect()) { |
35
|
|
|
* // redirect to offsite payment gateway |
36
|
|
|
* $response->redirect(); |
37
|
|
|
* } elseif ($response->isSuccessful()) { |
38
|
|
|
* echo "Capture transaction was successful!\n"; |
39
|
|
|
* echo "Transaction reference = " . $response->getTransactionReference() . "\n"; |
40
|
|
|
* } else { |
41
|
|
|
* // payment failed: display message to customer |
42
|
|
|
* exit($response->getMessage()); |
43
|
|
|
* } |
44
|
|
|
* </code> |
45
|
|
|
* |
46
|
|
|
* @see \Omnipay\Ebanx\Gateway |
47
|
|
|
* @link https://developers.ebanxpagamentos.com/api-reference/ebanx-payment-api/ebanx-payment-guide/guide-capture-a-payment/ |
48
|
|
|
*/ |
49
|
|
View Code Duplication |
class CaptureRequest extends AbstractRequest |
|
|
|
|
50
|
|
|
{ |
51
|
6 |
|
public function getData() |
52
|
|
|
{ |
53
|
|
|
/* |
54
|
|
|
* As the capture request the params should be passed in the query |
55
|
|
|
* not in the body, we return an empty array for the body, and |
56
|
|
|
* change the params at the getEndpoint method. |
57
|
|
|
*/ |
58
|
6 |
|
return []; |
59
|
|
|
} |
60
|
|
|
|
61
|
12 |
|
public function getEndpoint() |
62
|
|
|
{ |
63
|
12 |
|
$data = $this->getDefaultParameters(); |
64
|
12 |
|
$data['hash'] = $this->getTransactionReference(); |
65
|
12 |
|
$data['merchant_payment_code'] = $this->getTransactionId(); |
66
|
|
|
|
67
|
|
|
// Remove empty values to only send hash or merchant payment code |
68
|
12 |
|
$data = array_filter($data); |
69
|
|
|
|
70
|
12 |
|
return parent::getEndpoint() . '/capture?' . http_build_query($data, '', '&'); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
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.