Skip to content

Commit 56c49a4

Browse files
author
securesubmit-buildmaster
committed
20190618 deployment
1 parent cb6fabf commit 56c49a4

File tree

14 files changed

+275
-13
lines changed

14 files changed

+275
-13
lines changed

src/Gateways/RealexConnector.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -543,13 +543,14 @@ public function serializeRequest(AuthorizationBuilder $builder)
543543
$this->setSerializeData('HPP_LANG', $this->hostedPaymentConfig->language);
544544
$this->setSerializeData('MERCHANT_RESPONSE_URL', $this->hostedPaymentConfig->responseUrl);
545545
$this->setSerializeData('CARD_PAYMENT_BUTTON', $this->hostedPaymentConfig->paymentButtonText);
546-
$this->setSerializeData('HPP_CUSTOMER_EMAIL', $builder->hostedPaymentData->customerEmail);
547-
$this->setSerializeData('HPP_CUSTOMER_PHONENUMBER_MOBILE', $builder->hostedPaymentData->customerPhoneMobile);
548-
$this->setSerializeData('HPP_CHALLENGE_REQUEST_INDICATOR', $builder->hostedPaymentData->challengeRequest);
549-
if (isset($builder->hostedPaymentData->addressesMatch)) {
550-
$this->setSerializeData('HPP_ADDRESS_MATCH_INDICATOR', $builder->hostedPaymentData->addressesMatch ? 'TRUE' : 'FALSE');
546+
if (!empty($builder->hostedPaymentData)) {
547+
$this->setSerializeData('HPP_CUSTOMER_EMAIL', $builder->hostedPaymentData->customerEmail);
548+
$this->setSerializeData('HPP_CUSTOMER_PHONENUMBER_MOBILE', $builder->hostedPaymentData->customerPhoneMobile);
549+
$this->setSerializeData('HPP_CHALLENGE_REQUEST_INDICATOR', $builder->hostedPaymentData->challengeRequest);
550+
if (isset($builder->hostedPaymentData->addressesMatch)) {
551+
$this->setSerializeData('HPP_ADDRESS_MATCH_INDICATOR', $builder->hostedPaymentData->addressesMatch ? 'TRUE' : 'FALSE');
552+
}
551553
}
552-
553554
if (isset($this->hostedPaymentConfig->cardStorageEnabled)) {
554555
$this->setSerializeData('CARD_STORAGE_ENABLE', $this->hostedPaymentConfig->cardStorageEnabled ? '1' : '0');
555556
}

src/Services/HostedService.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,16 @@ public function void($transaction = null)
9090
public function parseResponse($response, $encoded = false)
9191
{
9292
$response = json_decode($response, true);
93-
93+
94+
if ($encoded) {
95+
$iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($response));
96+
foreach ($iterator as $key => $value) {
97+
$iterator->getInnerIterator()->offsetSet($key, base64_decode($value));
98+
}
99+
100+
$response = $iterator->getArrayCopy();
101+
}
102+
94103
$timestamp = $response["TIMESTAMP"];
95104
$merchantId = $response["MERCHANT_ID"];
96105
$orderId = $response["ORDER_ID"];
@@ -108,7 +117,7 @@ public function parseResponse($response, $encoded = false)
108117
$transactionId,
109118
$authCode
110119
]));
111-
120+
112121
if ($hash != $sha1Hash) {
113122
throw new ApiException("Incorrect hash. Please check your code and the Developers Documentation.");
114123
}

src/Terminals/Builders/TerminalAuthBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function execute()
5353
{
5454
parent::execute();
5555
return ConnectionContainer::instance()
56-
->ProcessTransaction($this);
56+
->processTransaction($this);
5757
}
5858

5959
public function withAddress($address)

src/Terminals/Builders/TerminalBuilder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ abstract class TerminalBuilder extends TransactionBuilder
1616
public $paymentMethodType;
1717

1818
/**
19-
* Request transaction Id
19+
* Request Id used by the POS to uniquely identify transactions.
20+
* Id is sent in the request and is then echoed back to the POS in the transaction response.
2021
*
2122
* @internal
2223
* @var int

src/Terminals/HPA/Entities/Enums/HpaMessageId.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ class HpaMessageId extends Enum
2727
const LINEITEM = "LineItem";
2828
const SENDSAF = "SendSAF";
2929
const STARTCARD = "StartCard";
30+
const GET_DIAGNOSTIC_REPORT = "GetDiagnosticReport";
3031
}

src/Terminals/HPA/Entities/HpaResponse.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class HpaResponse
1818
public $resultText;
1919
public $responseData;
2020
public $requestId;
21+
public $isStoredResponse;
2122

2223
// Internal
2324
public $status;

src/Terminals/HPA/HpaController.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class HpaController extends DeviceController
2222
{
2323

2424
public $device;
25+
private $builderData = null;
2526

2627
/*
2728
* Create interface based on connection mode TCP / HTTP
@@ -41,6 +42,7 @@ public function __construct(ConnectionConfig $config)
4142

4243
public function manageTransaction($builder)
4344
{
45+
$this->builderData = $builder;
4446
$xml = new \DOMDocument();
4547
$transactionType = $this->manageTransactionType($builder->transactionType);
4648
// Build Request
@@ -67,6 +69,7 @@ public function manageTransaction($builder)
6769

6870
public function processTransaction($builder)
6971
{
72+
$this->builderData = $builder;
7073
$xml = new \DOMDocument('1.0', 'utf-8');
7174
$transactionType = $this->manageTransactionType($builder->transactionType);
7275
$cardGroup = $this->manageCardGroup($builder->paymentMethodType);
@@ -114,7 +117,9 @@ public function processTransaction($builder)
114117
public function send($message, $requestType = null)
115118
{
116119
if (strpos($message, "<RequestId>%s</RequestId>") !== false) {
117-
$requestId = $this->requestIdProvider->getRequestId();
120+
$requestId = (!empty($this->builderData->requestId)) ?
121+
$this->builderData->requestId :
122+
$this->requestIdProvider->getRequestId();
118123
$message = sprintf($message, $requestId);
119124
}
120125

src/Terminals/HPA/HpaInterface.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,4 +362,22 @@ public function sendSaf()
362362
HpaMessageId::SENDSAF
363363
);
364364
}
365+
366+
public function getDiagnosticReport($totalFields)
367+
{
368+
return $this->hpaController->send(
369+
sprintf(
370+
"<SIP>"
371+
. "<Version>1.0</Version>"
372+
. "<ECRId>1004</ECRId>"
373+
. "<Request>GetDiagnosticReport</Request>"
374+
. "<RequestId>%s</RequestId>"
375+
. "<FieldCount>%s</FieldCount>"
376+
. "</SIP>",
377+
'%s',
378+
$totalFields
379+
),
380+
HpaMessageId::GET_DIAGNOSTIC_REPORT
381+
);
382+
}
365383
}

src/Terminals/HPA/HpaTcpInterface.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use GlobalPayments\Api\Terminals\HPA\Entities\Enums\HpaMessageId;
1212
use GlobalPayments\Api\Entities\Enums\PaymentMethodType;
1313
use GlobalPayments\Api\Terminals\HPA\Responses\HpaSendSafResponse;
14+
use GlobalPayments\Api\Terminals\HPA\Responses\HpaDiagnosticReportResponse;
1415

1516
/*
1617
* TCP interface for the device connection and parse response
@@ -160,6 +161,10 @@ private function filterResponseMessage($gatewayResponse)
160161
//process eod reponse by HpaEodResponse handler
161162
$responseHandler = new HpaSendSafResponse();
162163
$this->deviceResponse = $responseHandler->mapResponse($gatewayResponse);
164+
} elseif ($this->requestType == HpaMessageId::GET_DIAGNOSTIC_REPORT) {
165+
//process Diagnostic Report Response
166+
$responseHandler = new HpaDiagnosticReportResponse();
167+
$this->deviceResponse = $responseHandler->mapResponse($gatewayResponse);
163168
} elseif ($this->requestType == HpaMessageId::GET_INFO_REPORT) {
164169
$messageList = explode('</SIP>', $gatewayResponse);
165170
$this->deviceResponse = new HpaResponse();
@@ -284,6 +289,7 @@ private function setBasicResponse($responseData)
284289
$this->setValueInResponse('responseText', $responseData, 'ResponseText');
285290
$this->setValueInResponse('gatewayResponseMessage', $responseData, 'GatewayRspMsg');
286291
$this->setValueInResponse('balanceAmount', $responseData, 'BalanceDueAmount');
292+
$this->setValueInResponse('isStoredResponse', $responseData, 'StoredResponse');
287293

288294
//Gift Balance Enquiry
289295
$this->setValueInResponse('availableBalance', $responseData, 'AvailableBalance');
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
<?php
2+
3+
namespace GlobalPayments\Api\Terminals\HPA\Responses;
4+
5+
use GlobalPayments\Api\Terminals\HPA\Entities\HpaResponse;
6+
use GlobalPayments\Api\Terminals\TerminalUtils;
7+
use GlobalPayments\Api\Terminals\Interfaces\IDeviceResponseHandler;
8+
9+
class HpaDiagnosticReportResponse implements IDeviceResponseHandler
10+
{
11+
12+
private $deviceResponse;
13+
14+
public function mapResponse($gatewayMultipleResponse)
15+
{
16+
$this->deviceResponse = new HpaResponse();
17+
18+
//incase of muliple message needs to be splitted
19+
//convert the response as array using </SIP> keyword
20+
$messageList = explode('</SIP>', $gatewayMultipleResponse);
21+
22+
if (!empty($messageList)) {
23+
foreach ($messageList as $message) {
24+
if (!empty($message)) {
25+
//process individual <SIP> response
26+
if (strpos($message, '<SIP>') !== false && !strpos($message, '</SIP>')) {
27+
$message .= '</SIP>';
28+
$this->parseReportResponse($message);
29+
}
30+
}
31+
}
32+
}
33+
34+
return $this->deviceResponse;
35+
}
36+
37+
private function parseReportResponse($gatewayResponse)
38+
{
39+
$responseData = TerminalUtils::xmlParse($gatewayResponse);
40+
41+
if (!empty($responseData)) {
42+
$responseType = lcfirst($responseData['Response']);
43+
44+
$this->setValue('versionNumber', $responseData, 'Version');
45+
$this->setValue('ecrId', $responseData, 'ECRId');
46+
$this->setValue('sipId', $responseData, 'SIPId');
47+
$this->setValue('deviceId', $responseData, 'DeviceId');
48+
$this->setValue('response', $responseData, 'Response');
49+
$this->setValue('multipleMessage', $responseData, 'MultipleMessage');
50+
$this->setValue('resultCode', $responseData, 'Result');
51+
$this->setValue('responseCode', $responseData, 'ResponseCode');
52+
$this->setValue('resultText', $responseData, 'ResultText');
53+
$this->setValue('requestId', $responseData, 'RequestId');
54+
55+
if (!empty($responseData['Record'])) {
56+
//for GetDiagnosticReport
57+
$this->parseResponseRecord($responseData['Record'], $responseType);
58+
}
59+
}
60+
}
61+
62+
private function parseResponseRecord($gatewayRecord, $recordType)
63+
{
64+
if (!empty($gatewayRecord['Field'])) {
65+
$data = [];
66+
if (isset($gatewayRecord['Field']['Key']) && isset($gatewayRecord['Field']['Value'])) {
67+
$field = $gatewayRecord['Field'];
68+
$key = $this->formatKey($field['Key']);
69+
$data["$key"] = $field['Value'];
70+
} else {
71+
//incase of multi dimensional array
72+
foreach ($gatewayRecord['Field'] as $field) {
73+
if (isset($field['Key']) && isset($field['Value'])) {
74+
$key = $this->formatKey($field['Key']);
75+
76+
//convert the string as array when same key value pair repeated
77+
if (isset($data[$key])) {
78+
if (is_array($data[$key]) === false) {
79+
//convert string to array and assign last string as first element of array
80+
$prevValue = $data[$key];
81+
$data[$key] = [$prevValue];
82+
}
83+
84+
$data[$key][] = $field['Value'];
85+
} else {
86+
$data[$key] = $field['Value'];
87+
}
88+
}
89+
}
90+
}
91+
if ($recordType == 'getdiagnosticreport') {
92+
$tableCategory = $this->formatTableCategory($gatewayRecord);
93+
94+
$this->deviceResponse->responseData[$recordType]
95+
[$tableCategory] [] = $data;
96+
} elseif (!empty($this->deviceResponse->responseData[$recordType])) {
97+
$this->deviceResponse->responseData[$recordType][] = $data;
98+
} else {
99+
$this->deviceResponse->responseData[$recordType] = $data;
100+
}
101+
}
102+
}
103+
104+
/*
105+
* Set transaction based response in $deviceResponse
106+
*
107+
* @param string $propertyName $deviceResponse object property name
108+
* @param array $response
109+
* @param string $responseKey response key received from device
110+
*/
111+
112+
private function setValue($propertyName, $response, $responseKey)
113+
{
114+
if (isset($response[$responseKey])) {
115+
$this->deviceResponse->{$propertyName} = $response[$responseKey];
116+
}
117+
}
118+
119+
private function formatKey($key)
120+
{
121+
//convert "APPLICATION MODE" key as "applicationMode"
122+
$key = ucwords(strtolower($key));
123+
$key = str_replace(' ', '', $key);
124+
return $key;
125+
}
126+
127+
private function formatTableCategory($gatewayRecord)
128+
{
129+
$tableCategory = (!empty($gatewayRecord['TableCategory'])) ?
130+
lcfirst(ucwords(strtolower($gatewayRecord['TableCategory']))) : 'batchReport';
131+
132+
$tableCategory = str_replace(' ', '', $tableCategory);
133+
134+
return $tableCategory;
135+
}
136+
}

0 commit comments

Comments
 (0)