-
Notifications
You must be signed in to change notification settings - Fork 17
/
RapidDirectCreateCardRequest.php
108 lines (96 loc) · 3.37 KB
/
RapidDirectCreateCardRequest.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
<?php
/**
* eWAY Rapid Direct Create Card Request
*/
namespace Omnipay\Eway\Message;
use Omnipay\Omnipay;
/**
* eWAY Rapid Direct Create Card Request
*
* Securely stores card details with eWAY as tokens.
* Once submitted, a TokenCustomerID is provided which can be
* used in future transactions instead of the card details.
*
* 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',
* 'billingAddress1' => '1 Scrubby Creek Road',
* 'billingCountry' => 'AU',
* 'billingCity' => 'Scrubby Creek',
* 'billingPostcode' => '4999',
* 'billingState' => 'QLD',
* ));
*
* // Do a create card transaction on the gateway
* $request = $gateway->createCard(array(
* 'card' => $card,
* ));
*
* $response = $request->send();
* if ($response->isSuccessful()) {
* $cardReference = $response->getCardReference();
* }
* </code>
*
* @link https://eway.io/api-v3/#direct-connection
* @link https://eway.io/api-v3/#token-payments
*/
class RapidDirectCreateCardRequest extends RapidDirectAbstractRequest
{
public function getData()
{
$data = $this->getBaseData();
$data['Payment'] = [];
$data['Payment']['TotalAmount'] = 0;
$data['Method'] = 'CreateTokenCustomer';
return $data;
}
protected function getEndpoint()
{
return $this->getEndpointBase() . '/DirectPayment.json';
}
public function sendData($data)
{
$headers = [
'Authorization' => 'Basic ' . base64_encode($this->getApiKey() . ':' . $this->getPassword())
];
$httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, json_encode($data));
$this->response = new RapidDirectCreateCardResponse(
$this,
json_decode((string) $httpResponse->getBody(), true)
);
if ($this->getAction() === 'Purchase' && $this->response->isSuccessful()) {
$purchaseGateway = Omnipay::create('Eway_RapidDirect');
$purchaseGateway->setApiKey($this->getApiKey());
$purchaseGateway->setPassword($this->getPassword());
$purchaseGateway->setTestMode($this->getTestMode());
$purchaseResponse = $purchaseGateway->purchase([
'amount' => $this->getAmount(),
'currency' => $this->getCurrency(),
'description' => $this->getDescription(),
'transactionId' => $this->getTransactionId(),
'card' => $this->getCard(),
'cardReference' => $this->response->getCardReference(),
])->send();
$this->response->setPurchaseResponse($purchaseResponse);
}
return $this->response;
}
}