Skip to content

Commit 8a09f8d

Browse files
author
yildiray.itisgen
committed
Fixed complete purchase.
1 parent 151dd39 commit 8a09f8d

File tree

3 files changed

+77
-27
lines changed

3 files changed

+77
-27
lines changed

src/Messages/AbstractRequest.php

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,18 @@ protected function getTransactionHash(): string
242242
$this->getSecurityHash())));
243243
}
244244

245+
/**
246+
* @return string
247+
*/
248+
protected function getCompletePurchaseTransactionHash(): string
249+
{
250+
return strtoupper(SHA1(sprintf('%s%s%s%s',
251+
$this->getOrderId(),
252+
$this->getTerminalId(),
253+
$this->getAmountInteger(),
254+
$this->getSecurityHash())));
255+
}
256+
245257
/**
246258
* @return string
247259
*/
@@ -259,10 +271,7 @@ protected function getRefundOrVoidHash(): string
259271
*/
260272
protected function getSalesRequestParams(): array
261273
{
262-
$data['Version'] = $this->version;
263-
$data['Mode'] = $this->getTestMode() ? 'TEST' : 'PROD';
264-
265-
274+
$data = $this->getInfo();
266275
$data['Card'] = array(
267276
'Number' => $this->getCard()->getNumber(),
268277
'ExpireDate' => $this->getCard()->getExpiryDate('my'),
@@ -298,13 +307,44 @@ protected function getSalesRequestParams(): array
298307
return $data;
299308
}
300309

310+
/**
311+
* @return array
312+
*/
313+
protected function getCompleteSalesRequestParams(): array
314+
{
315+
$data = $this->getInfo();
316+
$data['Order'] = array(
317+
'OrderID' => $this->getOrderId()
318+
);
319+
320+
$data['Customer'] = array(
321+
'IPAddress' => $this->getClientIp(),
322+
);
323+
324+
$data['Terminal'] = [
325+
'ProvUserID' => $this->getUserName(),
326+
'HashData' => $this->getCompletePurchaseTransactionHash(),
327+
'UserID' => $this->getUserName(),
328+
'ID' => $this->getTerminalId(),
329+
'MerchantID' => $this->getMerchantId()
330+
];
331+
332+
$data['Transaction'] = array(
333+
'Type' => 'sales',
334+
'Amount' => $this->getAmountInteger(),
335+
'CurrencyCode' => $this->currency_list[$this->getCurrency()],
336+
'MotoInd' => "N"
337+
);
338+
339+
return $data;
340+
}
341+
301342
/**
302343
* @return array
303344
*/
304345
protected function getAuthorizeRequestParams(): array
305346
{
306-
$data['Version'] = $this->version;
307-
$data['Mode'] = $this->getTestMode() ? 'TEST' : 'PROD';
347+
$data = $this->getInfo();
308348
$data['Terminal'] = [
309349
'ProvUserID' => $this->getUserName(),
310350
'HashData' => $this->getTransactionHash(),
@@ -377,4 +417,15 @@ private function getSecurityHash(): string
377417

378418
return strtoupper(SHA1(sprintf('%s%s', $this->getPassword(), $terminalId)));
379419
}
420+
421+
/**
422+
* @return array
423+
*/
424+
private function getInfo(): array
425+
{
426+
$data['Version'] = $this->version;
427+
$data['Mode'] = $this->getTestMode() ? 'TEST' : 'PROD';
428+
429+
return $data;
430+
}
380431
}

src/Messages/CompletePurchaseRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function getData()
2020
throw new RuntimeException('3DSecure verification error');
2121
}
2222

23-
$data = $this->getSalesRequestParams();
23+
$data = $this->getCompleteSalesRequestParams();
2424
$data['Transaction']['CardholderPresentCode'] = "13";
2525
$secure3d = [
2626
"AuthenticationCode" => $this->getCavv(),

tests/GatewayTest.php

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,25 @@ public function setUp()
3232
}
3333

3434

35+
public function testCompletePurchase()
36+
{
37+
$this->options = [
38+
'orderId' => '234567',
39+
'amount' => "300",
40+
'currency' => 'TRY',
41+
'cavv' => 'jCm0m+u/0hUfAREHBAMBcfN+pSo=',
42+
'eci' => '02',
43+
'xid' => 'RszfrwEYe/8xb7rnrPuh6C9pZSQ=',
44+
'md' => 'SbEsOKX7ObDWDySsIxdAWk+S+OBRqtO9JhbzBb2vwcwcMfMi8VJcrKYBp01awsE1igb80xCyNEI/BNFWrX8oWwIKPyiRfx+dQIiKnFFIkyv1ZIVKeQ27LLFEx62qjVpSI31fondWTP98n7pChG/Jmg==',
45+
'mdStatus' => '1',
46+
'clientIp' => '172.18.0.1'
47+
];
48+
49+
/** @var CompletePurchaseResponse $response */
50+
$response = $this->gateway->completePurchase($this->options)->send();
51+
$this->assertTrue($response->isSuccessful());
52+
}
53+
3554
public function testCapture()
3655
{
3756
$this->options = [
@@ -84,26 +103,6 @@ public function testPurchase()
84103
$this->assertTrue($response->isSuccessful());
85104
}
86105

87-
public function testCompletePurchase()
88-
{
89-
$this->options = [
90-
'card' => $this->getCardInfo(),
91-
'orderId' => '234567',
92-
'amount' => "300",
93-
'currency' => 'TRY',
94-
'installment' => "",
95-
'cavv' => 'jCm0m+u/0hUfAREHBAMBcfN+pSo=',
96-
'eci' => '02',
97-
'xid' => 'RszfrwEYe/8xb7rnrPuh6C9pZSQ=',
98-
'md' => '1',
99-
'mdStatus' => '1',
100-
'clientIp' => '172.18.0.1'
101-
];
102-
103-
/** @var CompletePurchaseResponse $response */
104-
$response = $this->gateway->completePurchase($this->options)->send();
105-
$this->assertTrue($response->isSuccessful());
106-
}
107106

108107
public function testVoid()
109108
{

0 commit comments

Comments
 (0)