Skip to content

Commit 9696697

Browse files
Upstream anet fixes
1 parent 87b1e49 commit 9696697

15 files changed

+259
-44
lines changed

vendor/omnipay/authorizenet/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,46 @@ The following gateways are provided by this package:
3636
* AuthorizeNet_SIM
3737
* AuthorizeNet_DPM
3838

39+
In addition, `Accept.JS` is supported by the AIM driver. More details are provided below.
40+
3941
For general usage instructions, please see the main [Omnipay](https://github.com/thephpleague/omnipay)
4042
repository.
4143

44+
## Accept.JS
45+
46+
This gateway uses a JacaScript script to tokenize credit card details at the front end,
47+
i.e. in the payment form.
48+
Just the tokenized version of the credit card is then sent back to the merchant site,
49+
where it is used as a proxy for the credit card.
50+
51+
The card is tokenized into two values returned in `opaqueData` object from Accept.JS:
52+
53+
* dataDescriptor - the type of opaque data, e.g. "COMMON.ACCEPT.INAPP.PAYMENT"
54+
* dataValue - the value for the opaque data, e.g. "eyJjb2RlIjoiNT... {256 characters} ...idiI6IjEuMSJ9"
55+
56+
These two values must be POSTed back to the merchant application, usually as a part of the payment form.
57+
Make sure the raw credit card details are NOT posted back to your site.
58+
How this is handled is beyond this short note, but examples are always welcome in the documentation.
59+
60+
On the server, the tokenized detailt are passed into the `payment` or `authorize` request object.
61+
You will still need to pass in the `CreditCard` object, as that contains details of the payee and
62+
recipient, but just leave the credit card details of that object blank. For example:
63+
64+
```php
65+
// $gateway is an instantiation of the AIM driver.
66+
// $dataDescriptor and $dataValue come from the paymentr form at the front end.
67+
68+
$request = $gateway->purchase(
69+
[
70+
'notifyUrl' => '...',
71+
'amount' => $amount,
72+
'opaqueDataDescriptor' => $dataDescriptor,
73+
'opaqueDataValue' => $dataValue,
74+
...
75+
]
76+
);
77+
```
78+
4279
## Support
4380

4481
If you are having general issues with Omnipay, we suggest posting on

vendor/omnipay/authorizenet/src/AIMGateway.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Omnipay\AuthorizeNet\Message\AIMCaptureRequest;
77
use Omnipay\AuthorizeNet\Message\AIMPaymentPlanQueryResponse;
88
use Omnipay\AuthorizeNet\Message\AIMPurchaseRequest;
9+
use Omnipay\AuthorizeNet\Message\QueryRequest;
910
use Omnipay\AuthorizeNet\Message\AIMRefundRequest;
1011
use Omnipay\AuthorizeNet\Message\AIMVoidRequest;
1112
use Omnipay\Common\AbstractGateway;
@@ -27,6 +28,7 @@ public function getDefaultParameters()
2728
'transactionKey' => '',
2829
'testMode' => false,
2930
'developerMode' => false,
31+
'hashSecret' => '',
3032
'liveEndpoint' => 'https://api2.authorize.net/xml/v1/request.api',
3133
'developerEndpoint' => 'https://apitest.authorize.net/xml/v1/request.api',
3234
);
@@ -155,7 +157,7 @@ public function refund(array $parameters = array())
155157

156158
/**
157159
* @param array $parameters
158-
* @return AIMPaymentPlansQueryResponse
160+
* @return AIMPaymentPlansQueryRequest
159161
*/
160162
public function paymentPlansQuery(array $parameters = array())
161163
{

vendor/omnipay/authorizenet/src/Message/AIMAbstractRequest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,44 @@ public function setInvoiceNumber($value)
163163
return $this->setParameter('invoiceNumber', $value);
164164
}
165165

166+
/**
167+
* @link http://developer.authorize.net/api/reference/features/acceptjs.html Documentation on opaque data
168+
* @return string
169+
*/
170+
public function getOpaqueDataDescriptor()
171+
{
172+
return $this->getParameter('opaqueDataDescriptor');
173+
}
174+
175+
/**
176+
* @link http://developer.authorize.net/api/reference/features/acceptjs.html Documentation on opaque data
177+
* @return string
178+
*/
179+
public function getOpaqueDataValue()
180+
{
181+
return $this->getParameter('opaqueDataValue');
182+
}
183+
184+
/**
185+
* @link http://developer.authorize.net/api/reference/features/acceptjs.html Documentation on opaque data
186+
* @param string
187+
* @return string
188+
*/
189+
public function setOpaqueDataDescriptor($value)
190+
{
191+
return $this->setParameter('opaqueDataDescriptor', $value);
192+
}
193+
194+
/**
195+
* @link http://developer.authorize.net/api/reference/features/acceptjs.html Documentation on opaque data
196+
* @param string
197+
* @return string
198+
*/
199+
public function setOpaqueDataValue($value)
200+
{
201+
return $this->setParameter('opaqueDataValue', $value);
202+
}
203+
166204
public function sendData($data)
167205
{
168206
$headers = array('Content-Type' => 'text/xml; charset=utf-8');

vendor/omnipay/authorizenet/src/Message/AIMAuthorizeRequest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ public function getData()
2626

2727
protected function addPayment(\SimpleXMLElement $data)
2828
{
29+
/**
30+
* @link http://developer.authorize.net/api/reference/features/acceptjs.html Documentation on opaque data
31+
*/
32+
if ($this->getOpaqueDataDescriptor() && $this->getOpaqueDataValue()) {
33+
$data->transactionRequest->payment->opaqueData->dataDescriptor = $this->getOpaqueDataDescriptor();
34+
$data->transactionRequest->payment->opaqueData->dataValue = $this->getOpaqueDataValue();
35+
return;
36+
}
37+
2938
$this->validate('card');
3039
/** @var CreditCard $card */
3140
$card = $this->getCard();

vendor/omnipay/authorizenet/src/Message/AIMResponse.php

Lines changed: 68 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ class AIMResponse extends AbstractResponse
1818
*/
1919
const ERROR_RESPONSE_CODE_CANNOT_ISSUE_CREDIT = 54;
2020

21+
/**
22+
* The overall transaction result code.
23+
*/
24+
const TRANSACTION_RESULT_CODE_APPROVED = 1;
25+
const TRANSACTION_RESULT_CODE_DECLINED = 2;
26+
const TRANSACTION_RESULT_CODE_ERROR = 3;
27+
const TRANSACTION_RESULT_CODE_REVIEW = 4;
28+
2129
public function __construct(AbstractRequest $request, $data)
2230
{
2331
// Strip out the xmlns junk so that PHP can parse the XML
@@ -38,17 +46,25 @@ public function __construct(AbstractRequest $request, $data)
3846

3947
public function isSuccessful()
4048
{
41-
return 1 === $this->getResultCode();
49+
return static::TRANSACTION_RESULT_CODE_APPROVED === $this->getResultCode();
4250
}
4351

4452
/**
45-
* Overall status of the transaction. This field is also known as "Response Code" in Authorize.NET terminology.
53+
* Status of the transaction. This field is also known as "Response Code" in Authorize.NET terminology.
54+
* A result of 0 is returned if there is no transaction response returned, e.g. a validation error in
55+
* some data, or invalid login credentials.
4656
*
4757
* @return int 1 = Approved, 2 = Declined, 3 = Error, 4 = Held for Review
4858
*/
4959
public function getResultCode()
5060
{
51-
return intval((string)$this->data->transactionResponse[0]->responseCode);
61+
// If there is a transaction response, then we get the code from that.
62+
if (isset($this->data->transactionResponse[0])) {
63+
return intval((string)$this->data->transactionResponse[0]->responseCode);
64+
}
65+
66+
// No transaction response, so return 3 aka "error".
67+
return static::TRANSACTION_RESULT_CODE_ERROR;
5268
}
5369

5470
/**
@@ -62,11 +78,15 @@ public function getReasonCode()
6278

6379
if (isset($this->data->transactionResponse[0]->messages)) {
6480
// In case of a successful transaction, a "messages" element is present
65-
$code = intval((string)$this->data->transactionResponse[0]->messages[0]->message[0]->code);
81+
$code = intval((string)$this->data->transactionResponse[0]->messages[0]->message->code);
6682

6783
} elseif (isset($this->data->transactionResponse[0]->errors)) {
6884
// In case of an unsuccessful transaction, an "errors" element is present
69-
$code = intval((string)$this->data->transactionResponse[0]->errors[0]->error[0]->errorCode);
85+
$code = intval((string)$this->data->transactionResponse[0]->errors[0]->error->errorCode);
86+
87+
} elseif (isset($this->data->messages[0]->message)) {
88+
// In case of invalid request, the top-level message provides details.
89+
$code = (string)$this->data->messages[0]->message->code;
7090
}
7191

7292
return $code;
@@ -83,19 +103,27 @@ public function getMessage()
83103

84104
if (isset($this->data->transactionResponse[0]->messages)) {
85105
// In case of a successful transaction, a "messages" element is present
86-
$message = (string)$this->data->transactionResponse[0]->messages[0]->message[0]->description;
106+
$message = (string)$this->data->transactionResponse[0]->messages[0]->message->description;
87107

88108
} elseif (isset($this->data->transactionResponse[0]->errors)) {
89109
// In case of an unsuccessful transaction, an "errors" element is present
90-
$message = (string)$this->data->transactionResponse[0]->errors[0]->error[0]->errorText;
110+
$message = (string)$this->data->transactionResponse[0]->errors[0]->error->errorText;
111+
112+
} elseif (isset($this->data->messages[0]->message)) {
113+
// In case of invalid request, the top-level message provides details.
114+
$message = (string)$this->data->messages[0]->message->text;
91115
}
92116

93117
return $message;
94118
}
95119

96120
public function getAuthorizationCode()
97121
{
98-
return (string)$this->data->transactionResponse[0]->authCode;
122+
if (isset($this->data->transactionResponse[0])) {
123+
return (string)$this->data->transactionResponse[0]->authCode;
124+
} else {
125+
return '';
126+
}
99127
}
100128

101129
/**
@@ -105,36 +133,48 @@ public function getAuthorizationCode()
105133
*/
106134
public function getAVSCode()
107135
{
108-
return (string)$this->data->transactionResponse[0]->avsResultCode;
136+
if (isset($this->data->transactionResponse[0])) {
137+
return (string)$this->data->transactionResponse[0]->avsResultCode;
138+
} else {
139+
return '';
140+
}
109141
}
110142

111143
/**
112-
* A composite key containing the gateway provided transaction reference as well as other data points that may be
113-
* required for subsequent transactions that may need to modify this one.
144+
* A composite key containing the gateway provided transaction reference as
145+
* well as other data points that may be required for subsequent transactions
146+
* that may need to modify this one.
114147
*
115148
* @param bool $serialize Determines whether a string or object is returned
116149
* @return TransactionReference|string
117150
*/
118151
public function getTransactionReference($serialize = true)
119152
{
120-
$body = $this->data->transactionResponse[0];
121-
$transactionRef = new TransactionReference();
122-
$transactionRef->setApprovalCode((string)$body->authCode);
123-
$transactionRef->setTransId((string)$body->transId);
124-
125-
try {
126-
// Need to store card details in the transaction reference since it is required when doing a refund
127-
if ($card = $this->request->getCard()) {
128-
$transactionRef->setCard(array(
129-
'number' => $card->getNumberLastFour(),
130-
'expiry' => $card->getExpiryDate('mY')
131-
));
132-
} elseif ($cardReference = $this->request->getCardReference()) {
133-
$transactionRef->setCardReference(new CardReference($cardReference));
153+
// The transactionResponse is only returned if succesful or declined
154+
// for some reason, so don't assume it will always be there.
155+
156+
if (isset($this->data->transactionResponse[0])) {
157+
$body = $this->data->transactionResponse[0];
158+
$transactionRef = new TransactionReference();
159+
$transactionRef->setApprovalCode((string)$body->authCode);
160+
$transactionRef->setTransId((string)$body->transId);
161+
162+
try {
163+
// Need to store card details in the transaction reference since it is required when doing a refund
164+
if ($card = $this->request->getCard()) {
165+
$transactionRef->setCard(array(
166+
'number' => $card->getNumberLastFour(),
167+
'expiry' => $card->getExpiryDate('mY')
168+
));
169+
} elseif ($cardReference = $this->request->getCardReference()) {
170+
$transactionRef->setCardReference(new CardReference($cardReference));
171+
}
172+
} catch (\Exception $e) {
134173
}
135-
} catch (\Exception $e) {
174+
175+
return $serialize ? (string)$transactionRef : $transactionRef;
136176
}
137-
return (string)$body->transId;
138-
return $serialize ? (string)$transactionRef : $transactionRef;
177+
178+
return '';
139179
}
140180
}

vendor/omnipay/authorizenet/src/Message/CIMAbstractResponse.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
*/
1313
abstract class CIMAbstractResponse extends AbstractResponse
1414
{
15+
/**
16+
* The overall transaction result code.
17+
*/
18+
const TRANSACTION_RESULT_CODE_APPROVED = 1;
19+
const TRANSACTION_RESULT_CODE_DECLINED = 2;
20+
const TRANSACTION_RESULT_CODE_ERROR = 3;
21+
const TRANSACTION_RESULT_CODE_REVIEW = 4;
22+
1523
protected $responseType = null;
1624

1725
public function __construct(RequestInterface $request, $data)
@@ -40,7 +48,7 @@ public function __construct(RequestInterface $request, $data)
4048

4149
public function isSuccessful()
4250
{
43-
return 1 === $this->getResultCode();
51+
return $this->getResultCode() === static::TRANSACTION_RESULT_CODE_APPROVED;
4452
}
4553

4654
/**
@@ -51,11 +59,12 @@ public function isSuccessful()
5159
public function getResultCode()
5260
{
5361
$result = (string)$this->data['messages'][0]['resultCode'];
62+
5463
switch ($result) {
5564
case 'Ok':
56-
return 1;
65+
return static::TRANSACTION_RESULT_CODE_APPROVED;
5766
case 'Error':
58-
return 3;
67+
return static::TRANSACTION_RESULT_CODE_ERROR;
5968
default:
6069
return null;
6170

@@ -112,24 +121,33 @@ public function getMessage()
112121
return $message;
113122
}
114123

124+
/**
125+
* Get the reusable card reference from the response.
126+
* Used in conjuction with CIMGateway::createCard()
127+
*
128+
* @return string|null
129+
*/
115130
public function getCardReference()
116131
{
117132
$cardRef = null;
133+
118134
if ($this->isSuccessful()) {
119135
$data['customerProfileId'] = $this->getCustomerProfileId();
120136
$data['customerPaymentProfileId'] = $this->getCustomerPaymentProfileId();
137+
121138
if (!empty($data['customerProfileId']) && !empty($data['customerPaymentProfileId'])) {
122139
// For card reference both profileId and payment profileId should exist
123140
$cardRef = json_encode($data);
124141
}
125142
}
143+
126144
return $cardRef;
127145
}
128146

129147
/**
130148
* http://bookofzeus.com/articles/convert-simplexml-object-into-php-array/
131149
*
132-
* Convert a simpleXMLElement in to an array
150+
* Convert a simpleXMLElement into an array
133151
*
134152
* @param \SimpleXMLElement $xml
135153
*
@@ -138,9 +156,11 @@ public function getCardReference()
138156
public function xml2array(\SimpleXMLElement $xml)
139157
{
140158
$arr = array();
159+
141160
foreach ($xml as $element) {
142161
$tag = $element->getName();
143162
$e = get_object_vars($element);
163+
144164
if (!empty($e)) {
145165
$arr[$tag][] = $element instanceof \SimpleXMLElement ? $this->xml2array($element) : $e;
146166
} else {
@@ -173,8 +193,10 @@ public function augmentResponse()
173193

174194
/** @var CreditCard $card */
175195
$card = $this->request->getCard();
196+
176197
if ($card) {
177198
$ccString = $card->getNumber() . $card->getExpiryMonth() . $card->getExpiryYear();
199+
178200
$this->data['hash'] = md5($ccString);
179201
$this->data['brand'] = $card->getBrand();
180202
$this->data['expiryYear'] = $card->getExpiryYear();

0 commit comments

Comments
 (0)