|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Ebanx Purchase Request. |
|
4
|
|
|
*/ |
|
5
|
|
|
namespace Omnipay\Ebanx\Message; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Ebanx Purchase Request. |
|
9
|
|
|
* |
|
10
|
|
|
* To charge a credit card or generate a boleto, you create a new charge object. |
|
11
|
|
|
* If your gateway is in test mode, the supplied card won't actually be charged, though |
|
12
|
|
|
* everything else will occur as if in live mode. (Ebanx assumes that the |
|
13
|
|
|
* charge would have completed successfully). |
|
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. |
|
17
|
|
|
* If you want you can pass the cardReference paramenter |
|
18
|
|
|
* in case you are making a credit card payment |
|
19
|
|
|
* |
|
20
|
|
|
* Ebanx gateway supports only two types of "paymentMethod": |
|
21
|
|
|
* |
|
22
|
|
|
* * creditcard |
|
23
|
|
|
* * boleto |
|
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 purchase transaction on the gateway |
|
62
|
|
|
* $transaction = $gateway->purchase(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
|
|
|
* </code> |
|
85
|
|
|
* |
|
86
|
|
|
* Because a purchase request in Ebanx looks similar to an |
|
87
|
|
|
* Authorize request, this class simply extends the AuthorizeRequest |
|
88
|
|
|
* class and over-rides the getData method setting auto_capture = true. |
|
89
|
|
|
* |
|
90
|
|
|
* @see \Omnipay\Ebanx\Gateway |
|
91
|
|
|
* @link https://developers.ebanxpagamentos.com/api-reference/ebanx-payment-api/ebanx-payment-guide/guide-capture-a-payment/ |
|
92
|
|
|
*/ |
|
93
|
|
|
class PurchaseRequest extends AuthorizeRequest |
|
94
|
|
|
{ |
|
95
|
|
|
|
|
96
|
3 |
|
public function getData() |
|
97
|
|
|
{ |
|
98
|
3 |
|
$data = parent::getData(); |
|
99
|
3 |
|
$data['payment']['creditcard']['auto_capture'] = true; |
|
100
|
|
|
|
|
101
|
3 |
|
return $data; |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|