Skip to content

Commit b288e45

Browse files
authored
Merge pull request #7 from alegraio/dev
Edited responses
2 parents a3051a0 + 5e66cbc commit b288e45

File tree

2 files changed

+54
-45
lines changed

2 files changed

+54
-45
lines changed

src/Messages/AbstractResponse.php

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,43 +19,51 @@ abstract class AbstractResponse extends \Omnipay\Common\Message\AbstractResponse
1919
'prod' => 'https://sanalposprov.garanti.com.tr/servlet/gt3dengine'
2020
];
2121

22+
/**
23+
* AbstractResponse constructor.
24+
* @param RequestInterface $request
25+
* @param $data
26+
*/
2227
public function __construct(RequestInterface $request, $data)
2328
{
2429
parent::__construct($request, $data);
2530
$this->setData($data);
2631
}
2732

2833
/**
29-
* @return string
34+
* @return string|null
3035
*/
31-
public function getMessage(): string
36+
public function getMessage(): ?string
3237
{
38+
3339
if (!$this->isSuccessful()) {
34-
return $this->data["Transaction"]->Response->ErrorMsg . "->" . $this->data["Transaction"]->Response->SysErrMsg;
40+
return (string)$this->data->Transaction->Response->ErrorMsg;
3541
}
3642

37-
return isset($this->data["Transaction"]) ? $this->data["Transaction"]->Response->Message : $this->data;
43+
return (string)(!$this->getIsRedirect() ? $this->data->Transaction->Response->Message : null);
3844
}
3945

46+
/**
47+
* @return string|null
48+
*/
4049
public function getCode(): ?string
4150
{
42-
return (string)($this->data["Transaction"]->Response->Code ?? null);
51+
return (string)($this->data->Transaction->Response->Code ?? null);
4352
}
4453

4554
/**
46-
* @param mixed $data
47-
* @return array
55+
* @param $data
4856
*/
49-
public function setData($data): array
57+
public function setData($data): void
5058
{
5159
if (is_array($data)) {
5260
$content = $data;
5361
$this->setIsRedirect(true);
5462
} else {
55-
$content = (array)simplexml_load_string($data);
63+
$content = simplexml_load_string($data);
5664
}
5765

58-
return $this->data = $content;
66+
$this->data = $content;
5967
}
6068

6169
/**
@@ -82,7 +90,7 @@ public function isSuccessful(): bool
8290
if ($this->getIsRedirect()) {
8391
return true;
8492
} else {
85-
return current($this->data["Transaction"]->Response->Code) === '00';
93+
return (string)$this->data->Transaction->Response->Code === '00';
8694
}
8795
}
8896
}

tests/GatewayTest.php

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,50 @@ public function setUp()
3131
$this->gateway->setPassword('123qweASD/');
3232
}
3333

34+
35+
public function testCapture()
36+
{
37+
$this->options = [
38+
'card' => $this->getCardInfo(),
39+
'orderId' => '90082020_324109',
40+
'amount' => "100",
41+
'currency' => 'TRY',
42+
'installment' => "",
43+
'clientIp' => '10.241.19.2'
44+
];
45+
46+
/** @var CaptureResponse $response */
47+
$response = $this->gateway->capture($this->options)->send();
48+
$this->assertTrue($response->isSuccessful());
49+
}
50+
51+
public function testAuthorize()
52+
{
53+
$this->options = [
54+
'card' => $this->getCardInfo(),
55+
'orderId' => '90082020_324109',
56+
'amount' => "100",
57+
'currency' => 'TRY',
58+
'installment' => "",
59+
'clientIp' => '10.241.19.2'
60+
];
61+
62+
/** @var AuthorizeResponse $response */
63+
$response = $this->gateway->authorize($this->options)->send();
64+
$this->assertTrue($response->isSuccessful());
65+
}
66+
3467
public function testPurchase()
3568
{
3669
$this->options = [
3770
'card' => $this->getCardInfo(),
38-
'orderId' => '43282041_14102',
71+
'orderId' => '89852041_14102',
3972
'amount' => "10",
4073
'currency' => 'TRY',
4174
'returnUrl' => "https://eticaret.garanti.com.tr/destek/postback.aspx",
4275
'cancelUrl' => "https://eticaret.garanti.com.tr/destek/postback.aspx",
4376
'installment' => "",
44-
'paymentMethod' => '',
77+
'paymentMethod' => '3d',
4578
'clientIp' => '10.241.19.2',
4679
'secureKey' => '12345678'
4780
];
@@ -106,38 +139,6 @@ public function testRefund()
106139
}
107140

108141

109-
public function testAuthorize()
110-
{
111-
$this->options = [
112-
'card' => $this->getCardInfo(),
113-
'orderId' => '10082020_324109',
114-
'amount' => "100",
115-
'currency' => 'TRY',
116-
'installment' => "",
117-
'clientIp' => '10.241.19.2'
118-
];
119-
120-
/** @var AuthorizeResponse $response */
121-
$response = $this->gateway->authorize($this->options)->send();
122-
$this->assertTrue($response->isSuccessful());
123-
}
124-
125-
public function testCapture()
126-
{
127-
$this->options = [
128-
'card' => $this->getCardInfo(),
129-
'orderId' => '10082020_324109',
130-
'amount' => "100",
131-
'currency' => 'TRY',
132-
'installment' => "",
133-
'clientIp' => '10.241.19.2'
134-
];
135-
136-
/** @var CaptureResponse $response */
137-
$response = $this->gateway->capture($this->options)->send();
138-
$this->assertTrue($response->isSuccessful());
139-
}
140-
141142
/**
142143
* @return CreditCard
143144
*/

0 commit comments

Comments
 (0)