Skip to content

Commit 721fc41

Browse files
committed
Added option to ignore start dates as advised by FAC as some cards were triggering an exception at the processor if a start date was passed.
Added extended logging if cache transactions are enabled.
1 parent e551747 commit 721fc41

File tree

3 files changed

+72
-25
lines changed

3 files changed

+72
-25
lines changed

src/ConfigArray.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
use Omnipay\FirstAtlanticCommerce\Constants;
88
use Omnipay\FirstAtlanticCommerce\Message\AbstractRequest;
9+
use Omnipay\FirstAtlanticCommerce\Message\Authorize;
910

1011
return [
1112
/*
@@ -23,6 +24,7 @@
2324
*/
2425

2526
'testMode' => false,
27+
Authorize::PARAM_IGNORE_START_DATE => true, // remove "StartDate" from FAC request
2628
Constants::AUTHORIZE_OPTION_3DS => true, // Default 3DS transactions
2729
Constants::CONFIG_KEY_FACID => '', // First Atlantic Commerce ID
2830
Constants::CONFIG_KEY_FACPWD => '', // First Atlantic Commerce Processing Password

src/Message/AbstractRequest.php

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Omnipay\FirstAtlanticCommerce\Constants;
99
use Omnipay\FirstAtlanticCommerce\Support\TransactionCode;
1010
use Omnipay\FirstAtlanticCommerce\Exception\GatewayHTTPException;
11+
use Psr\Http\Message\ResponseInterface;
1112

1213
abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest
1314
implements \Omnipay\FirstAtlanticCommerce\Support\FACParametersInterface
@@ -16,6 +17,7 @@ abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest
1617

1718
const PARAM_CACHE_TRANSACTION = 'cacheTransaction';
1819
const PARAM_CACHE_REQUEST = 'cacheRequest';
20+
const EXCEPTION_LOG = 'exception.log';
1921

2022
protected $data = [];
2123
protected $XMLDoc;
@@ -95,34 +97,64 @@ public function sendData($data)
9597
$this->XMLDoc->asXML($this->TransactionCacheDir.$this->getMessageClassName().'Request_'.$this->getTransactionId().'.xml');
9698
}
9799

98-
switch ($httpResponse->getStatusCode())
99-
{
100-
case "200":
101-
$responseContent = $httpResponse->getBody()->getContents();
102-
$responseClassName = __NAMESPACE__."\\".$this->FACServices[$this->getMessageClassName()]["response"];
100+
if ($httpResponse instanceof ResponseInterface) {
103101

104-
$responseXML = new \SimpleXMLElement($responseContent);
105-
$responseXML->registerXPathNamespace("fac", Constants::PLATFORM_XML_NS);
102+
switch ($httpResponse->getStatusCode()) {
103+
case "200":
104+
$responseContent = $httpResponse->getBody()->getContents();
105+
$responseClassName = __NAMESPACE__ . "\\" . $this->FACServices[$this->getMessageClassName()]["response"];
106106

107-
if($this->getCacheTransaction())
108-
{
109-
if (!is_dir($this->TransactionCacheDir))
110-
{
111-
$cacheDirExists = mkdir($this->TransactionCacheDir);
107+
if ($this->getCacheTransaction()) {
108+
if (!is_dir($this->TransactionCacheDir)) {
109+
$cacheDirExists = mkdir($this->TransactionCacheDir);
110+
} else {
111+
$cacheDirExists = true;
112+
}
113+
114+
if ($cacheDirExists) {
115+
file_put_contents($this->TransactionCacheDir . self::EXCEPTION_LOG, date("Y-m-d H:i:s") . " FAC Response String\n", FILE_APPEND);
116+
file_put_contents($this->TransactionCacheDir . self::EXCEPTION_LOG, "START\n" . $responseContent . "\nEND\n", FILE_APPEND);
117+
file_put_contents($this->TransactionCacheDir . self::EXCEPTION_LOG, "HEADERS START\n", FILE_APPEND);
118+
}
119+
120+
$headers = $httpResponse->getHeaders();
121+
foreach ($headers as $h => $header) {
122+
file_put_contents($this->TransactionCacheDir . self::EXCEPTION_LOG, strtoupper($h) . ": " . implode("\n", $header) . "\n\n", FILE_APPEND);
123+
}
124+
125+
file_put_contents($this->TransactionCacheDir . self::EXCEPTION_LOG, "HEADERS END\n", FILE_APPEND);
112126
}
113-
else
127+
128+
try {
129+
$responseXML = new \SimpleXMLElement($responseContent);
130+
} catch (\Exception $e)
114131
{
115-
$cacheDirExists = true;
132+
if ($this->getCacheTransaction() && $cacheDirExists)
133+
file_put_contents($this->TransactionCacheDir.self::EXCEPTION_LOG, "Exception: ".$e->getMessage()."\n", FILE_APPEND);
134+
135+
throw $e;
116136
}
117137

118-
if ($cacheDirExists)
119-
$responseXML->asXML($this->TransactionCacheDir.$this->getMessageClassName().'Response_'.$this->getTransactionId().'.xml');
120-
}
138+
$responseXML->registerXPathNamespace("fac", Constants::PLATFORM_XML_NS);
139+
140+
if ($this->getCacheTransaction()) {
141+
if (!is_dir($this->TransactionCacheDir)) {
142+
$cacheDirExists = mkdir($this->TransactionCacheDir);
143+
} else {
144+
$cacheDirExists = true;
145+
}
121146

122-
return $this->response = new $responseClassName($this, $responseXML);
147+
if ($cacheDirExists)
148+
$responseXML->asXML($this->TransactionCacheDir . $this->getMessageClassName() . 'Response_' . $this->getTransactionId() . '.xml');
149+
}
150+
151+
return $this->response = new $responseClassName($this, $responseXML);
123152

124-
default:
125-
throw new GatewayHTTPException($httpResponse->getReasonPhrase(), $httpResponse->getStatusCode());
153+
default:
154+
throw new GatewayHTTPException($httpResponse->getReasonPhrase(), $httpResponse->getStatusCode());
155+
}
156+
} else {
157+
throw new \Exception("Invalid HTTP Response.");
126158
}
127159
}
128160

src/Message/Authorize.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class Authorize extends AbstractRequest
3636
const PARAM_CARD_CVV2 = "CardCVV2";
3737
const PARAM_CARD_ISSUE_NUMBER = "IssueNumber";
3838
const PARAM_CARD_START_DATE = "StartDate";
39+
const PARAM_IGNORE_START_DATE = 'ignoreStartDate';
3940

4041
const PARAM_BILLING_FIRSTNAME = "BillToFirstName";
4142
const PARAM_BILLING_LASTNAME = "BillToLastName";
@@ -129,7 +130,10 @@ protected function validateTransactionDetails()
129130
foreach ($this->TransactionDetailsRequirement as $param => $requirement)
130131
{
131132
$field = $this->TransactionDetails[$param];
132-
$this->TransactionDetails[$param] = substr($field, $requirement[1], $requirement[2]);
133+
134+
if (!empty($field)) {
135+
$this->TransactionDetails[$param] = substr($field, $requirement[1], $requirement[2]);
136+
}
133137

134138
switch ($requirement[0])
135139
{
@@ -164,14 +168,20 @@ protected function setCardDetails()
164168
$CardDetails[self::PARAM_CARD_EXPIRY_DATE] = $CreditCard->getExpiryDate("my");
165169
$CardDetails[self::PARAM_CARD_CVV2] = $CreditCard->getCvv();
166170
$CardDetails[self::PARAM_CARD_ISSUE_NUMBER] = $CreditCard->getIssueNumber();
167-
$CardDetails[self::PARAM_CARD_START_DATE] = $CreditCard->getStartDate("my");
168171

169-
if ($CardDetails[self::PARAM_CARD_START_DATE] == "1299") unset($CardDetails[self::PARAM_CARD_START_DATE]);
172+
if ($this->getParameter(self::PARAM_IGNORE_START_DATE) === false) {
173+
$CardDetails[self::PARAM_CARD_START_DATE] = $CreditCard->getStartDate("my");
174+
175+
if ($CardDetails[self::PARAM_CARD_START_DATE] == "1299") unset($CardDetails[self::PARAM_CARD_START_DATE]);
176+
}
170177

171178
foreach ($this->CardDetailsRequirement as $param => $requirement)
172179
{
173180
$field = (isset($CardDetails[$param]))?$CardDetails[$param]:null;
174-
$CardDetails[$param] = substr($field, $requirement[1], $requirement[2]);
181+
182+
if (!empty($field)) {
183+
$CardDetails[$param] = substr($field, $requirement[1], $requirement[2]);
184+
}
175185

176186
switch ($requirement[0])
177187
{
@@ -227,7 +237,10 @@ protected function setBillingDetails()
227237
foreach ($this->BillingDetailsRequirement as $param => $requirement)
228238
{
229239
$field = (isset($BillingDetails[$param]))?$BillingDetails[$param]:null;
230-
$BillingDetails[$param] = substr($field, $requirement[1], $requirement[2]);
240+
241+
if (!empty($field)) {
242+
$BillingDetails[$param] = substr($field, $requirement[1], $requirement[2]);
243+
}
231244

232245
switch ($requirement[0])
233246
{

0 commit comments

Comments
 (0)