Skip to content

Commit 6463ad2

Browse files
authored
Merge pull request #11 from TransactPRO/merchant_transaction_id_response
Add merchant-transaction-id to payment response parsing
2 parents 54696f4 + b676914 commit 6463ad2

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

src/Gateway/Http/Transport/Curl.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,20 @@ public function execute(string $method, string $url, string $authorizationHeader
136136
->setOption(CURLOPT_POSTFIELDS, $body)
137137
->setOption(CURLOPT_HTTPHEADER, $headers)
138138
->setOption(CURLOPT_URL, $url)
139+
->setOption(CURLOPT_RETURNTRANSFER, 1)
140+
->setOption(CURLOPT_HEADER, 1)
139141
->applyOptions();
140142

141143
$result = curl_exec($this->ch);
142144
if (!$result) {
143145
return false;
144146
}
145147

146-
list($header, $body) = explode("\r\n\r\n", $result, 2);
147-
$this->body = $body;
148+
$headerSize = curl_getinfo($this->ch, CURLINFO_HEADER_SIZE);
149+
$header = substr($result, 0, $headerSize);
148150

149151
$this->status = (int) curl_getinfo($this->ch, CURLINFO_HTTP_CODE);
152+
$this->body = substr($result, $headerSize);
150153
$this->headers = $this->headersToArray($header);
151154

152155
return true;
@@ -174,7 +177,7 @@ private function headersToArray(string $header): array
174177
$headers = [];
175178

176179
foreach (explode("\r\n", $header) as $i => $line) {
177-
if ($i === 0) {
180+
if (strlen($line) === 0 || stripos($line, 'HTTP') === 0) {
178181
continue;
179182
}
180183

src/Gateway/Responses/Parts/Payment/GW.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
class GW
1515
{
1616
public $gatewayTransactionId;
17+
public $merchantTransactionId;
1718
public $originalGatewayTransactionId;
1819
public $parentGatewayTransactionId;
1920
public $redirectUrl;
@@ -23,6 +24,7 @@ class GW
2324
public function __construct(array $rawDecoded = null)
2425
{
2526
$this->gatewayTransactionId = strval($rawDecoded['gateway-transaction-id'] ?? null);
27+
$this->merchantTransactionId = strval($rawDecoded['merchant-transaction-id'] ?? null);
2628
$this->originalGatewayTransactionId = strval($rawDecoded['original-gateway-transaction-id'] ?? null);
2729
$this->parentGatewayTransactionId = strval($rawDecoded['parent-gateway-transaction-id'] ?? null);
2830
$this->redirectUrl = strval($rawDecoded['redirect-url'] ?? null);

tests/Gateway/Operations/Transactions/SmsTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ public function testParsePaymentResponseSuccessfulAPI()
9292
{
9393
$body = "{\"acquirer-details\":{\"dynamic-descriptor\":\"test\",\"eci-sli\":\"648\",\"result-code\":\"000\",\"status-description\":\"Approved\"," .
9494
"\"status-text\":\"Approved\",\"terminal-mid\":\"5800978\",\"transaction-id\":\"1899493845214315\"},\"error\":{}," .
95-
"\"gw\":{\"gateway-transaction-id\":\"8a9bed66-8412-494f-9866-2c26b5ceee62\",\"status-code\":7,\"status-text\":\"SUCCESS\"," .
96-
"\"original-gateway-transaction-id\":\"orig-aaa\",\"parent-gateway-transaction-id\":\"parent-aaa\"}," .
95+
"\"gw\":{\"gateway-transaction-id\":\"8a9bed66-8412-494f-9866-2c26b5ceee62\",\"merchant-transaction-id\":\"87d53472ba27fde33ec03e2f5ca6137a\",".
96+
"\"status-code\":7,\"status-text\":\"SUCCESS\",\"original-gateway-transaction-id\":\"orig-aaa\",\"parent-gateway-transaction-id\":\"parent-aaa\"}," .
9797
"\"warnings\":[\"Soon counters will be exceeded for the merchant\",\"Soon counters will be exceeded for the account\"," .
9898
"\"Soon counters will be exceeded for the terminal group\",\"Soon counters will be exceeded for the terminal\"]}\n";
9999

@@ -111,6 +111,7 @@ public function testParsePaymentResponseSuccessfulAPI()
111111

112112
$this->assertNotNull($parsedResponse->gw);
113113
$this->assertEquals("8a9bed66-8412-494f-9866-2c26b5ceee62", $parsedResponse->gw->gatewayTransactionId);
114+
$this->assertEquals("87d53472ba27fde33ec03e2f5ca6137a", $parsedResponse->gw->merchantTransactionId);
114115
$this->assertEquals("orig-aaa", $parsedResponse->gw->originalGatewayTransactionId);
115116
$this->assertEquals("parent-aaa", $parsedResponse->gw->parentGatewayTransactionId);
116117
$this->assertEquals(Status::SUCCESS, $parsedResponse->gw->statusCode);

0 commit comments

Comments
 (0)