-
Notifications
You must be signed in to change notification settings - Fork 17
/
RapidDirectGateway.php
232 lines (216 loc) · 7.48 KB
/
RapidDirectGateway.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<?php
/**
* eWAY Rapid Direct Connection Gateway
*/
namespace Omnipay\Eway;
use Omnipay\Common\AbstractGateway;
/**
* eWAY Rapid Direct Gateway
*
* This class forms the gateway class for eWAY Rapid Direct Connection requests.
*
* The eWAY Rapid gateways use an API Key and Password for authentication.
*
* Before gaining access to this connection type eWAY must be provided with proof
* of a PCI-DSS compliant environment with a current and valid PCI-DSS certificate.
* Note that transactions not involving credit card data (such as a recurring token
* payment) may be processed without proof of compliance.
*
* There is also a test sandbox environment, which uses a separate endpoint and
* API key and password. To access the eWAY Sandbox requires an eWAY Partner account.
* https://myeway.force.com/success/partner-registration
*
* If you're getting the response "Unauthorised API Access, Account Not PCI Certified"
* when testing with the sandbox, this means you're integrating Rapid Direct. If you're
* not using client side encryption then you will need to provide proof of PCI compliance
* when moving to the live endpoint.
*
* For testing in sandbox, it's a simple process to enable direct payments.
*
* * Log into your Sandbox Account
* * Hover the mouse over the Settings tab, then click on Sandbox.
* * Tick the box under Direct Payment Method (Next to PCI) and click on Save Sandbox Settings.
*
* You're now set up to test direct payments.
*
* ### Example
*
* <code>
* // Create a gateway for the eWAY Direct Gateway
* $gateway = Omnipay::create('Eway_RapidDirect');
*
* // Initialise the gateway
* $gateway->initialize(array(
* 'apiKey' => 'Rapid API Key',
* 'password' => 'Rapid API Password',
* 'testMode' => true, // Or false when you are ready for live transactions
* ));
*
* // Create a credit card object
* $card = new CreditCard(array(
* 'firstName' => 'Example',
* 'lastName' => 'User',
* 'number' => '4444333322221111',
* 'expiryMonth' => '01',
* 'expiryYear' => '2020',
* 'cvv' => '321',
* 'billingAddress1' => '1 Scrubby Creek Road',
* 'billingCountry' => 'AU',
* 'billingCity' => 'Scrubby Creek',
* 'billingPostcode' => '4999',
* 'billingState' => 'QLD',
* ));
*
* // Do a purchase transaction on the gateway
* $request = $gateway->purchase(array(
* 'amount' => '10.00',
* 'currency' => 'AUD',
* 'transactionType' => 'Purchase',
* 'card' => $card,
* ));
*
* $response = $request->send();
* if ($response->isSuccessful()) {
* echo "Purchase transaction was successful!\n";
* $txn_id = $response->getTransactionReference();
* echo "Transaction ID = " . $txn_id . "\n";
* }
* </code>
*
* @link https://eway.io/api-v3/#direct-connection
* @link https://eway.io/api-v3/#authentication
* @link https://go.eway.io/s/article/How-do-I-setup-my-Live-eWAY-API-Key-and-Password
*/
class RapidDirectGateway extends AbstractGateway
{
public $transparentRedirect = false;
public function getName()
{
return 'eWAY Rapid Direct';
}
public function getDefaultParameters()
{
return [
'apiKey' => '',
'password' => '',
'testMode' => false,
];
}
public function getApiKey()
{
return $this->getParameter('apiKey');
}
public function setApiKey($value)
{
return $this->setParameter('apiKey', $value);
}
public function getPassword()
{
return $this->getParameter('password');
}
public function setPassword($value)
{
return $this->setParameter('password', $value);
}
/**
* Create a purchase request.
*
* Used for initiating a purchase transaction.
* This resource accepts plain card details, an eWAY Token (as a cardReference)
* or encrypted card details from eWAY's client side encryption.
*
* @link https://eway.io/api-v3/#direct-connection
* @param array $parameters
* @return \Omnipay\Eway\Message\RapidDirectPurchaseRequest
*/
public function purchase(array $parameters = [])
{
return $this->createRequest('\Omnipay\Eway\Message\RapidDirectPurchaseRequest', $parameters);
}
/**
* Create an authorisation request.
*
* To collect payment at a later time, a pre-auth can be made on a card.
* You can then capture the payment to complete the sale and collect payment.
*
* Only available for Australian eWAY merchants
*
* @link https://eway.io/api-v3/#pre-auth
* @param array $parameters
* @return \Omnipay\Eway\Message\RapidDirectAuthorizeRequest
*/
public function authorize(array $parameters = [])
{
return $this->createRequest('\Omnipay\Eway\Message\RapidDirectAuthorizeRequest', $parameters);
}
/**
* Capture an authorisation.
*
* Use this resource to capture and process a previously created authorisation.
* To use this resource requires the transaction reference from the authorisation.
*
* @link https://eway.io/api-v3/#capture-a-payment
* @param array $parameters
* @return \Omnipay\Eway\Message\RapidCaptureRequest
*/
public function capture(array $parameters = [])
{
return $this->createRequest('\Omnipay\Eway\Message\RapidCaptureRequest', $parameters);
}
/**
* Refund a Transaction
*
* Use this resource to refund a complete payment. To use this resource requires the transaction
* reference from the purchase or capture.
*
* @link https://eway.io/api-v3/#refunds
* @param array $parameters
* @return \Omnipay\Eway\Message\RefundRequest
*/
public function refund(array $parameters = [])
{
return $this->createRequest('\Omnipay\Eway\Message\RefundRequest', $parameters);
}
/**
* Void a Transaction
*
* @link https://eway.io/api-v3/#pre-auth
* @param array $parameters
* @return \Omnipay\Eway\Message\RapidDirectVoidRequest
*/
public function void(array $parameters = [])
{
return $this->createRequest('\Omnipay\Eway\Message\RapidDirectVoidRequest', $parameters);
}
/**
* Store a credit card as a Token
*
* You can currently securely store card details with eWAY for future
* charging using eWAY's Tokens.
* After storing the card, pass the cardReference instead of the card
* details to complete a payment.
*
* @link https://eway.io/api-v3/#create-token-customer
* @param array $parameters
* @return \Omnipay\Eway\Message\RapidDirectCreateCardRequest
*/
public function createCard(array $parameters = [])
{
return $this->createRequest('\Omnipay\Eway\Message\RapidDirectCreateCardRequest', $parameters);
}
/**
* Update a credit card stored as a Token
*
* You can currently securely store card details with eWAY for future
* charging using eWAY's Tokens.
* This resource requires the cardReference for the card to be updated.
*
* @link https://eway.io/api-v3/#update-token-customer
* @param array $parameters
* @return \Omnipay\Eway\Message\RapidDirectUpdateCardRequest
*/
public function updateCard(array $parameters = [])
{
return $this->createRequest('\Omnipay\Eway\Message\RapidDirectUpdateCardRequest', $parameters);
}
}