Skip to content

Commit e8bfac0

Browse files
author
Can Sözeri
committed
Huge refactor
1 parent 7e77ee0 commit e8bfac0

28 files changed

+167
-108
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"php": "^7.3",
1919
"omnipay/common": "^3",
2020
"ext-dom": "*",
21-
"ext-simplexml": "*"
21+
"ext-simplexml": "*",
22+
"ext-json": "*"
2223
},
2324
"require-dev": {
2425
"omnipay/tests": "^3",

phpunit.xml.dist

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
syntaxCheck="false">
12+
<testsuites>
13+
<testsuite name="Omnipay Garanti(Gvp) Test Suite">
14+
<directory>./tests/</directory>
15+
</testsuite>
16+
</testsuites>
17+
<filter>
18+
<whitelist>
19+
<directory>./src</directory>
20+
</whitelist>
21+
</filter>
22+
</phpunit>

src/Messages/AbstractRequest.php

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ public function sendData($data)
109109
{
110110
try {
111111
$processType = $this->getProcessType();
112-
if(!empty($processType))
113-
{
112+
if (!empty($processType)) {
114113
$data['Type'] = $processType;
115114
}
116115
$shipInfo = $data['ship'] ?? [];
@@ -214,7 +213,7 @@ protected function getHttpMethod(): string
214213
* @return array
215214
* @throws InvalidRequestException
216215
*/
217-
protected function getRequestParams(): array
216+
protected function getSalesRequestParams(): array
218217
{
219218
$gateway = $this->getBank();
220219

@@ -325,6 +324,47 @@ public function getPurchase3DData(): array
325324
return $data;
326325
}
327326

327+
public function getHash(array $data): string
328+
{
329+
return $data['clientid'] .
330+
$data['oid'] .
331+
$data['amount'] .
332+
$data['okUrl'] .
333+
$data['failUrl'] .
334+
$data['taksit'] .
335+
$this->getRnd() .
336+
$this->getStoreKey();
337+
}
338+
339+
/**
340+
* @return array
341+
*/
342+
protected function getRequestParams(): array
343+
{
344+
return [
345+
'url' => $this->getEndPoint(),
346+
'type' => $this->getProcessType(),
347+
'data' => $this->requestParams,
348+
'method' => $this->getHttpMethod()
349+
];
350+
}
351+
352+
protected function setRequestParams(array $data): void
353+
{
354+
array_walk_recursive($data, [$this, 'updateValue']);
355+
$this->requestParams = $data;
356+
}
357+
358+
protected function updateValue(&$data, $key): void
359+
{
360+
$sensitiveData = $this->getSensitiveData();
361+
362+
if (\in_array($key, $sensitiveData, true)) {
363+
$data = Mask::mask($data);
364+
}
365+
366+
}
367+
328368
/**
329369
* @param array $data
330370
* @return array
@@ -413,32 +453,4 @@ private function getShipTo(): array
413453
'Country' => ''
414454
];
415455
}
416-
417-
public function getHash(array $data): string
418-
{
419-
return $data['clientid'] .
420-
$data['oid'] .
421-
$data['amount'] .
422-
$data['okUrl'] .
423-
$data['failUrl'] .
424-
$data['taksit'].
425-
$this->getRnd() .
426-
$this->getStoreKey();
427-
}
428-
429-
protected function setRequestParams(array $data): void
430-
{
431-
array_walk_recursive($data, [$this, 'updateValue']);
432-
$this->requestParams = $data;
433-
}
434-
435-
protected function updateValue(&$data, $key): void
436-
{
437-
$sensitiveData = $this->getSensitiveData();
438-
439-
if (\in_array($key, $sensitiveData, true)) {
440-
$data = Mask::mask($data);
441-
}
442-
443-
}
444456
}

src/Messages/AbstractResponse.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,21 @@
1010

1111
abstract class AbstractResponse extends \Omnipay\Common\Message\AbstractResponse implements RedirectResponseInterface
1212
{
13+
/** @var array */
14+
public $serviceRequestParams;
1315

1416
/**
1517
* AbstractResponse constructor.
1618
* @param RequestInterface $request
1719
* @param $data
20+
* @throws \JsonException
1821
*/
1922
public function __construct(RequestInterface $request, $data)
2023
{
2124
parent::__construct($request, $data);
22-
$this->data = (is_string($data)) ? (array)simplexml_load_string($data) : $data;
25+
$this->data = (is_string($data)) ? json_decode(json_encode((array)simplexml_load_string($data),
26+
JSON_THROW_ON_ERROR), 1, 512,
27+
JSON_THROW_ON_ERROR) : $data;
2328
}
2429

2530
/**
@@ -36,7 +41,7 @@ public function getMessage(): ?string
3641
*/
3742
public function getCode(): ?string
3843
{
39-
$authCode = $this->data['AuthCode'] ?? $this->data['EXTRA']['AUTH_CODE'] ?? null;
44+
$authCode = $this->data['AuthCode'] ?? $this->data['Extra']['AUTH_CODE'] ?? null;
4045
return $this->isSuccessful() ? $authCode : parent::getCode();
4146
}
4247

@@ -56,4 +61,20 @@ public function getTransactionReference(): ?string
5661
{
5762
return $this->isSuccessful() ? $this->data['TransId'] : parent::getTransactionReference();
5863
}
64+
65+
/**
66+
* @return array
67+
*/
68+
public function getServiceRequestParams(): array
69+
{
70+
return $this->serviceRequestParams;
71+
}
72+
73+
/**
74+
* @param array $serviceRequestParams
75+
*/
76+
public function setServiceRequestParams(array $serviceRequestParams): void
77+
{
78+
$this->serviceRequestParams = $serviceRequestParams;
79+
}
5980
}

src/Messages/AuthorizeRequest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,23 @@ class AuthorizeRequest extends AbstractRequest
1616
*/
1717
public function getData(): array
1818
{
19-
$data = $this->getRequestParams();
19+
$data = $this->getSalesRequestParams();
2020
$this->setRequestParams($data);
2121
return $data;
2222
}
2323

2424
/**
2525
* @param $data
2626
* @return AuthorizeResponse
27+
* @throws \JsonException
2728
*/
2829
protected function createResponse($data): AuthorizeResponse
2930
{
30-
return new AuthorizeResponse($this, $data);
31+
$response = new AuthorizeResponse($this, $data);
32+
$requestParams = $this->getRequestParams();
33+
$response->setServiceRequestParams($requestParams);
34+
35+
return $response;
3136
}
3237

3338
/**

src/Messages/CaptureRequest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,23 @@ class CaptureRequest extends AbstractRequest
1515
*/
1616
public function getData(): array
1717
{
18-
$data = $this->getRequestParams();
18+
$data = $this->getSalesRequestParams();
1919
$this->setRequestParams($data);
2020
return $data;
2121
}
2222

2323
/**
2424
* @param $data
2525
* @return CaptureResponse
26+
* @throws \JsonException
2627
*/
2728
protected function createResponse($data): CaptureResponse
2829
{
29-
return new CaptureResponse($this, $data);
30+
$response = new CaptureResponse($this, $data);
31+
$requestParams = $this->getRequestParams();
32+
$response->setServiceRequestParams($requestParams);
33+
34+
return $response;
3035
}
3136

3237
/**

src/Messages/CompletePurchaseRequest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,15 @@ public function getData()
3636
/**
3737
* @param $data
3838
* @return CompletePurchaseResponse
39+
* @throws \JsonException
3940
*/
4041
protected function createResponse($data): CompletePurchaseResponse
4142
{
42-
return new CompletePurchaseResponse($this, $data);
43+
$response = new CompletePurchaseResponse($this, $data);
44+
$requestParams = $this->getRequestParams();
45+
$response->setServiceRequestParams($requestParams);
46+
47+
return $response;
4348
}
4449

4550
private function getThreeDResponse(): ThreeDResponse
@@ -88,6 +93,7 @@ private function getGeneratedHash(): string
8893
$signature = $hashParamsVal . $storeKey;
8994
return base64_encode(sha1($signature, true));
9095
}
96+
9197
/**
9298
* @inheritDoc
9399
*/

src/Messages/ParametersTrait.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<?php
22

3-
43
namespace Omnipay\NestPay\Messages;
54

6-
75
trait ParametersTrait
86
{
97
public function setResponseData($responseData): void

src/Messages/Purchase3DResponse.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
namespace Omnipay\NestPay\Messages;
77

8-
98
use DOMDocument;
109

1110
class Purchase3DResponse extends AbstractResponse

src/Messages/PurchaseRequest.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
namespace Omnipay\NestPay\Messages;
77

88
use Exception;
9+
use Omnipay\Common\Exception\InvalidResponseException;
10+
use Omnipay\Common\Message\ResponseInterface;
911

1012
class PurchaseRequest extends AbstractRequest
1113
{
@@ -20,14 +22,20 @@ public function getData()
2022
if ($this->getPaymentMethod() === self::PAYMENT_TYPE_3D) {
2123
$this->setAction('3d');
2224
$data = $this->getPurchase3DData();
23-
$this->setRequestParams($data);
24-
return $data;
25+
} else {
26+
$data = $this->getSalesRequestParams();
2527
}
26-
$data = $this->getRequestParams();
28+
2729
$this->setRequestParams($data);
2830
return $data;
2931
}
3032

33+
/**
34+
* @param mixed $data
35+
* @return ResponseInterface|AbstractResponse|Purchase3DResponse
36+
* @throws \JsonException
37+
* @throws InvalidResponseException
38+
*/
3139
public function sendData($data)
3240
{
3341
if ($this->getPaymentMethod() === self::PAYMENT_TYPE_3D) {
@@ -39,10 +47,15 @@ public function sendData($data)
3947
/**
4048
* @param $data
4149
* @return PurchaseResponse
50+
* @throws \JsonException
4251
*/
4352
protected function createResponse($data): PurchaseResponse
4453
{
45-
return new PurchaseResponse($this, $data);
54+
$response = new PurchaseResponse($this, $data);
55+
$requestParams = $this->getRequestParams();
56+
$response->setServiceRequestParams($requestParams);
57+
58+
return $response;
4659
}
4760

4861

src/Messages/RefundRequest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<?php
22

3-
43
namespace Omnipay\NestPay\Messages;
54

6-
75
use Omnipay\Common\Exception\InvalidRequestException;
86

97
class RefundRequest extends AbstractRequest
@@ -32,10 +30,15 @@ public function getData()
3230
/**
3331
* @param $data
3432
* @return RefundResponse
33+
* @throws \JsonException
3534
*/
3635
protected function createResponse($data): RefundResponse
3736
{
38-
return new RefundResponse($this, $data);
37+
$response = new RefundResponse($this, $data);
38+
$requestParams = $this->getRequestParams();
39+
$response->setServiceRequestParams($requestParams);
40+
41+
return $response;
3942
}
4043

4144
/**

src/Messages/RefundResponse.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<?php
22

3-
43
namespace Omnipay\NestPay\Messages;
54

6-
75
class RefundResponse extends AbstractResponse
86
{
97

src/Messages/RequestTrait.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<?php
22

3-
43
namespace Omnipay\NestPay\Messages;
54

6-
75
trait RequestTrait
86
{
97

0 commit comments

Comments
 (0)