-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathRapidDirectPurchaseRequest.php
114 lines (105 loc) · 3.71 KB
/
RapidDirectPurchaseRequest.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
<?php
/**
* eWAY Rapid Direct Purchase Request
*/
namespace Omnipay\Eway\Message;
/**
* eWAY Rapid Direct Purchase Request
*
* Completes a transaction using eWAY's Rapid Direct Connection API.
* This request can process a purchase with card details or with an
* eWAY Token (passed as the cardReference).
*
* Using Direct Connection to pass card details in the clear requires
* proof of PCI compliance to eWAY. Alternatively they can be
* encrypted using Client Side Encryption - in which case the card
* number and CVN should be passed using the encryptedCardNumber and
* encryptedCardCvv respectively (these are not in the CreditCard
* object).
*
* Simple 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/#client-side-encryption
* @see RapidDirectAbstractRequest
*/
class RapidDirectPurchaseRequest extends RapidDirectAbstractRequest
{
public function getData()
{
$data = $this->getBaseData();
$this->validate('amount');
$data['Payment'] = array();
$data['Payment']['TotalAmount'] = $this->getAmountInteger();
$data['Payment']['InvoiceNumber'] = $this->getTransactionId();
$data['Payment']['InvoiceDescription'] = $this->getDescription();
$data['Payment']['CurrencyCode'] = $this->getCurrency();
$data['Payment']['InvoiceReference'] = $this->getInvoiceReference();
if (empty($data['Customer']['CardDetails']['CVN']) && $this->getCardReference()) {
// We have a token and card is not present so treat as MOTO.
$data['TransactionType'] = 'MOTO';
}
if ($this->getCardReference()) {
$data['Method'] = 'TokenPayment';
} else {
$data['Method'] = 'ProcessPayment';
}
if (isset($data['Customer']['TokenCustomerID'])) {
// If we are paying using token, remove the card details
// otherwise the displayed data will be overwritten on eWay dashboard
unset($data['Customer']['CardDetails']);
}
return $data;
}
/**
* Get transaction endpoint.
*
* @return string
*/
protected function getEndpoint()
{
return $this->getEndpointBase().'/DirectPayment.json';
}
}