Skip to content

Commit

Permalink
XOL-4064 PHP7 (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
anush authored Apr 18, 2019
1 parent 29e2193 commit 647c187
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 25 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
language: php

php:
- 5.3
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2
- hhvm

matrix:
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
"psr-4": { "Omnipay\\AuthorizeNet\\" : "src/" }
},
"require": {
"omnipay/common": "~2.5"
"omnipay/common": "~2.5",
"ext-json": "*",
"ext-simplexml": "*"
},
"require-dev": {
"omnipay/tests": "~2.0"
Expand Down
21 changes: 4 additions & 17 deletions src/Message/CIMAbstractResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function isSuccessful()
*/
public function getResultCode()
{
$result = (string)$this->data['messages'][0]['resultCode'];
$result = (string)$this->data['messages']['resultCode'];
switch ($result) {
case 'Ok':
return 1;
Expand All @@ -73,9 +73,8 @@ public function getReasonCode()

if (isset($this->data['messages'])) {
// In case of a successful transaction, a "messages" element is present
$code = (string)$this->data['messages'][0]['message'][0]['code'];
$code = (string)$this->data['messages']['message']['code'];
}

return $code;
}

Expand Down Expand Up @@ -105,8 +104,7 @@ public function getMessage()

if (isset($this->data['messages'])) {
// In case of a successful transaction, a "messages" element is present
$message = (string)$this->data['messages'][0]['message'][0]['text'];

$message = (string)$this->data['messages']['message']['text'];
}

return $message;
Expand Down Expand Up @@ -137,18 +135,7 @@ public function getCardReference()
*/
public function xml2array(\SimpleXMLElement $xml)
{
$arr = array();
foreach ($xml as $element) {
$tag = $element->getName();
$e = get_object_vars($element);
if (!empty($e)) {
$arr[$tag][] = $element instanceof \SimpleXMLElement ? $this->xml2array($element) : $e;
} else {
$arr[$tag] = trim($element);
}
}

return $arr;
return json_decode(json_encode($xml), true);
}

public function getCustomerProfileId()
Expand Down
2 changes: 1 addition & 1 deletion src/Message/CIMCreateCardResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function getCustomerProfileId()
public function getCustomerPaymentProfileId()
{
if ($this->isSuccessful()) {
return $this->data['customerPaymentProfileIdList'][0]['numericString'];
return $this->data['customerPaymentProfileIdList']['numericString'];
}
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Message/CIMGetPaymentProfileResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CIMGetPaymentProfileResponse extends CIMCreatePaymentProfileResponse
public function getCustomerPaymentProfileId()
{
if ($this->isSuccessful()) {
return $this->data['paymentProfile'][0]['customerPaymentProfileId'];
return $this->data['paymentProfile']['customerPaymentProfileId'];
}
return null;
}
Expand Down
11 changes: 7 additions & 4 deletions src/Message/CIMGetProfileResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ public function getMatchingPaymentProfileId($last4)
return null;
}

foreach ($this->data['profile'][0]['paymentProfiles'] as $paymentProfile) {
foreach ($this->data['profile']['paymentProfiles'] as $paymentProfile) {
// For every payment profile check if the last4 matches the last4 of the card in request.
$cardLast4 = substr($paymentProfile['payment'][0]['creditCard'][0]['cardNumber'], -4);
if ($last4 == $cardLast4) {
return (string)$paymentProfile['customerPaymentProfileId'];
// TODO: In some situations payment attribute is not there. We need to investigate why. See #php7
if (isset($paymentProfile['payment']['creditCard']['cardNumber'])) {
$cardLast4 = substr($paymentProfile['payment']['creditCard']['cardNumber'], -4);
if ($last4 == $cardLast4) {
return (string)$paymentProfile['customerPaymentProfileId'];
}
}
}

Expand Down

0 comments on commit 647c187

Please sign in to comment.