1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Ebanx Refund Request. |
4
|
|
|
*/ |
5
|
|
|
namespace Omnipay\Ebanx\Message; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Ebanx Refund Request. |
9
|
|
|
* |
10
|
|
|
* To refund a payment, you must call the API method refund. One payment can be refunded if, |
11
|
|
|
* and only if, its status confirmed (CO). |
12
|
|
|
* |
13
|
|
|
* Pay attention, because open (OP) or pending (PE) payments cannot be refunded. |
14
|
|
|
* |
15
|
|
|
* The merchant requests the refund through the Dashboard or the API. |
16
|
|
|
* This refund request gets directly into EBANX refund queue, marked as Requested. |
17
|
|
|
* EBANX then acknowledges the refund and the refund is marked as Pending. |
18
|
|
|
* |
19
|
|
|
* When the customer receives the money back (in his bank account or through his credit card), |
20
|
|
|
* the refund transitions its state to Confirmed. When the refund is Requested or Pending, |
21
|
|
|
* it can be cancelled by the merchant. |
22
|
|
|
* |
23
|
|
|
* Look at these remarks about refunds in EBANX: |
24
|
|
|
* |
25
|
|
|
* Each payment can have many refunds, given that the sum of their amounts does not exceed |
26
|
|
|
* the original payment amount. Cancelled refunds do not count toward this sum. |
27
|
|
|
* |
28
|
|
|
* Only confirmed payments (CO) can be refunded. |
29
|
|
|
* |
30
|
|
|
* The currency of the refund is the same as the original payment. |
31
|
|
|
* |
32
|
|
|
* Refunds are notified when the refund is pending and an email is sent to the customer |
33
|
|
|
* asking for bank information and when the refund is confirmed. |
34
|
|
|
* |
35
|
|
|
* Example: |
36
|
|
|
* |
37
|
|
|
* <code> |
38
|
|
|
* // Create a gateway for the Ebanx Gateway |
39
|
|
|
* // (routes to GatewayFactory::create) |
40
|
|
|
* $gateway = Omnipay::create('Ebanx'); |
41
|
|
|
* |
42
|
|
|
* // Initialise the gateway |
43
|
|
|
* $gateway->initialize(array( |
44
|
|
|
* 'integration_key' => 'MyApiKey', |
45
|
|
|
* )); |
46
|
|
|
* |
47
|
|
|
* // Do an refund transaction on the gateway |
48
|
|
|
* $transaction = $gateway->refund(array( |
49
|
|
|
* 'transactionReference' => '5d5eb3389d1bce23d265b8d2376688b09a0fafc56d453252', |
50
|
|
|
* 'amount' => '10.00', |
51
|
|
|
* 'currency' => 'BRL', |
52
|
|
|
* 'description' => 'Description', |
53
|
|
|
* 'transactionId' => '32432432', |
54
|
|
|
* )); |
55
|
|
|
* |
56
|
|
|
* $response = $transaction->send(); |
57
|
|
|
* if ($response->isSuccessful()) { |
58
|
|
|
* echo $response->getData(); |
59
|
|
|
* } else { |
60
|
|
|
* // payment failed: display message to customer |
61
|
|
|
* exit($response->getMessage()); |
62
|
|
|
* } |
63
|
|
|
* </code> |
64
|
|
|
* |
65
|
|
|
* @see \Omnipay\Ebanx\Gateway |
66
|
|
|
* @link https://developers.ebanxpagamentos.com/api-reference/ebanx-payment-api/ebanx-payment-guide/guide-refund-a-payment/ |
67
|
|
|
*/ |
68
|
|
|
class RefundRequest extends AbstractRequest |
69
|
|
|
{ |
70
|
3 |
|
public function getData() |
71
|
|
|
{ |
72
|
|
|
/* |
73
|
|
|
* As the refund request the params should be passed in the query |
74
|
|
|
* not in the body, we return an empty array for the body, and |
75
|
|
|
* change the params at the getEndpoint method. |
76
|
|
|
*/ |
77
|
3 |
|
return []; |
78
|
|
|
} |
79
|
|
|
|
80
|
3 |
|
public function getEndpoint() |
81
|
|
|
{ |
82
|
3 |
|
$this->validate('amount', 'transactionReference', 'transactionId', 'description'); |
83
|
3 |
|
$data = array_merge($this->getDefaultParameters(), $this->getSplitData()); |
84
|
3 |
|
$data['operation'] = 'request'; |
85
|
3 |
|
$data['hash'] = $this->getTransactionReference(); |
86
|
3 |
|
$data['merchant_refund_code'] = $this->getTransactionId(); |
87
|
3 |
|
$data['amount'] = $this->getAmount(); |
88
|
3 |
|
$data['description'] = $this->getDescription(); |
89
|
|
|
|
90
|
|
|
|
91
|
3 |
|
return parent::getEndpoint() . '/refund?' . http_build_query($data, '', '&'); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|