1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Ebanx Authorize Request |
4
|
|
|
*/ |
5
|
|
|
namespace Omnipay\Ebanx\Message; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Ebanx Authorize Request |
9
|
|
|
* |
10
|
|
|
* An Authorize request is similar to a purchase request but the |
11
|
|
|
* charge issues an authorization (or pre-authorization), and no money |
12
|
|
|
* is transferred. The transaction will need to be captured later |
13
|
|
|
* in order to effect payment. |
14
|
|
|
* |
15
|
|
|
* The card object is required by default to get all the customer information, |
16
|
|
|
* even if you want to use boleto payment method. If you want you can pass the |
17
|
|
|
* cardReference paramenter |
18
|
|
|
* |
19
|
|
|
* Ebanx gateway supports only two types of "paymentMethod": |
20
|
|
|
* |
21
|
|
|
* * creditcard |
22
|
|
|
* * boleto |
23
|
|
|
* |
24
|
|
|
* |
25
|
|
|
* You must provide aditional customer details to process the request at Ebanx API |
26
|
|
|
* These details is passed using the following attributes |
27
|
|
|
* |
28
|
|
|
* * documentNumber (CPF or CNPJ) |
29
|
|
|
* |
30
|
|
|
* Example: |
31
|
|
|
* |
32
|
|
|
* <code> |
33
|
|
|
* // Create a gateway for the Ebanx Gateway |
34
|
|
|
* // (routes to GatewayFactory::create) |
35
|
|
|
* $gateway = Omnipay::create('Ebanx'); |
36
|
|
|
* |
37
|
|
|
* // Initialise the gateway |
38
|
|
|
* $gateway->initialize(array( |
39
|
|
|
* 'integration_key' => 'MyApiKey', |
40
|
|
|
* )); |
41
|
|
|
* |
42
|
|
|
* // Create a credit card object |
43
|
|
|
* // This card can be used for testing. |
44
|
|
|
* $card = new CreditCard(array( |
45
|
|
|
* 'firstName' => 'Example', |
46
|
|
|
* 'lastName' => 'Customer', |
47
|
|
|
* 'number' => '4242424242424242', |
48
|
|
|
* 'expiryMonth' => '01', |
49
|
|
|
* 'expiryYear' => '2020', |
50
|
|
|
* 'cvv' => '123', |
51
|
|
|
* 'email' => '[email protected]', |
52
|
|
|
* 'address1' => 'Street name, Street number, Complement', |
53
|
|
|
* 'address2' => 'Neighborhood', |
54
|
|
|
* 'city' => 'City', |
55
|
|
|
* 'state' => 'sp', |
56
|
|
|
* 'country' => 'BR', |
57
|
|
|
* 'postcode' => '05443100', |
58
|
|
|
* 'phone' => '19 3242 8855', |
59
|
|
|
* )); |
60
|
|
|
* |
61
|
|
|
* // Do an authorize transaction on the gateway |
62
|
|
|
* $transaction = $gateway->authorize(array( |
63
|
|
|
* 'amount' => '10.00', |
64
|
|
|
* 'documentNumber' => '214.278.589-40', |
65
|
|
|
* 'note' => 'test', |
66
|
|
|
* 'paymentMethod' => 'creditcard', |
67
|
|
|
* 'card' => $card, |
68
|
|
|
* 'currency' => 'BRL', |
69
|
|
|
* )); |
70
|
|
|
* |
71
|
|
|
* $response = $transaction->send(); |
72
|
|
|
* if ($response->isRedirect()) { |
73
|
|
|
* // redirect to offsite payment gateway |
74
|
|
|
* $response->redirect(); |
75
|
|
|
* } elseif ($response->isSuccessful()) { |
76
|
|
|
* echo "Authorize transaction was successful!\n"; |
77
|
|
|
* echo "Transaction reference = " . $response->getTransactionReference() . "\n"; |
78
|
|
|
* } else { |
79
|
|
|
* // payment failed: display message to customer |
80
|
|
|
* exit($response->getMessage()); |
81
|
|
|
* } |
82
|
|
|
* </code> |
83
|
|
|
* |
84
|
|
|
* @see \Omnipay\Ebanx\Gateway |
85
|
|
|
* @see \Omnipay\Ebanx\Message\CaptureRequest |
86
|
|
|
* @link https://developers.ebanxpagamentos.com/api-reference/ebanx-payment-api/ebanx-payment-guide/guide-create-a-payment/brazil/ |
87
|
|
|
*/ |
88
|
|
|
|
89
|
|
|
class AuthorizeRequest extends AbstractRequest |
90
|
|
|
{ |
91
|
21 |
|
public function getData() |
92
|
|
|
{ |
93
|
21 |
|
$this->validate('card', 'amount', 'currency', 'transactionId', 'documentNumber'); |
94
|
|
|
|
95
|
18 |
|
$data = $this->getDefaultParameters(); |
96
|
18 |
|
$data['operation'] = 'request'; |
97
|
18 |
|
$data['description'] = $this->getDescription(); |
98
|
|
|
|
99
|
18 |
|
switch ($this->getPaymentMethod()) { |
100
|
18 |
|
case 'creditcard': |
101
|
9 |
|
$paymentData = $this->getPaymentData($this->getCardData()); |
102
|
|
|
// As this is only the Autorize Request, we overwrite the auto capture to false |
103
|
9 |
|
$paymentData['payment']['creditcard']['auto_capture'] = false; |
104
|
9 |
|
break; |
105
|
9 |
|
case 'boleto': |
106
|
3 |
|
$paymentData = $this->getPaymentData($this->getBoletoData()); |
107
|
3 |
|
break; |
108
|
|
|
default: |
109
|
6 |
|
$paymentData = $this->getPaymentData(); |
110
|
6 |
|
break; |
111
|
|
|
} |
112
|
|
|
|
113
|
18 |
|
$data = array_merge($data, $paymentData); |
114
|
|
|
|
115
|
18 |
|
return $data; |
116
|
|
|
} |
117
|
|
|
|
118
|
9 |
|
public function getEndpoint() |
119
|
|
|
{ |
120
|
9 |
|
return parent::getEndpoint() . '/direct'; |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|