Skip to content

Commit 74559b9

Browse files
authored
Merge pull request #3 from alegraio/dev
Edited actions.
2 parents e0d4634 + 3695898 commit 74559b9

File tree

8 files changed

+100
-53
lines changed

8 files changed

+100
-53
lines changed

src/Messages/AbstractRequest.php

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -223,26 +223,26 @@ public function getLang(): string
223223
* @param string $value
224224
* @return AbstractRequest
225225
*/
226-
public function setSecureKey(string $value): AbstractRequest
226+
public function setLang(string $value): AbstractRequest
227227
{
228-
return $this->setParameter('secureKey', $value);
228+
return $this->setParameter('lang', $value);
229229
}
230230

231231
/**
232-
* @return string
232+
* @param string $value
233+
* @return AbstractRequest
233234
*/
234-
public function getSecureKey(): string
235+
public function setSecureKey(string $value): AbstractRequest
235236
{
236-
return $this->getParameter('secureKey');
237+
return $this->setParameter('secureKey', $value);
237238
}
238239

239240
/**
240-
* @param string $value
241-
* @return AbstractRequest
241+
* @return string
242242
*/
243-
public function setLang(string $value): AbstractRequest
243+
public function getSecureKey(): string
244244
{
245-
return $this->setParameter('lang', $value);
245+
return $this->getParameter('secureKey');
246246
}
247247

248248
/**
@@ -353,32 +353,33 @@ protected function getAuthorizeRequestParams(): array
353353

354354
/**
355355
* @return array
356-
* @throws \Omnipay\Common\Exception\InvalidRequestException
357356
*/
358357
protected function getSalesRequestParamsFor3d(): array
359358
{
360359
$params['apiversion'] = $this->version;
361360
$params['mode'] = $this->getTestMode();
362361
$params['terminalprovuserid'] = $this->getUserName();
363-
$params['terminaluserid'] = str_repeat('0', 9 - strlen($this->getTerminalId()));
364-
$params['terminalid'] = str_repeat('0', 9 - strlen($this->getTerminalId()));
362+
$params['terminaluserid'] = $this->getUserName();
363+
$params['terminalid'] = $this->getTerminalId();
365364
$params['terminalmerchantid'] = $this->getMerchantId();
366-
$params['orderid'] = $this->getOrderId();
367-
$params['customeremailaddress'] = $this->getCard()->getEmail();
368-
$params['customeripaddress'] = $this->getClientIp();
369-
$params['txnamount'] = $this->getAmount();
365+
$params['txntype'] = 'sales';
366+
$params['txnamount'] = $this->getAmountInteger();
370367
$params['txncurrencycode'] = $this->currency_list[$this->getCurrency()];
371368
$params['txninstallmentcount'] = $this->getInstallment();
369+
$params['customeremailaddress'] = $this->getCard()->getEmail();
370+
$params['customeripaddress'] = $this->getClientIp();
371+
$params['orderid'] = $this->getOrderId();
372372
$params['successurl'] = $this->getReturnUrl();
373373
$params['errorurl'] = $this->getCancelUrl();
374374
$params['lang'] = $this->getLang();
375-
$params['txntimestamp'] = time();
376-
$params['txntimeoutperiod'] = "60";
377-
$params['addcampaigninstallment'] = "N";
378-
$params['totallinstallmentcount'] = "0";
379-
$params['installmentonlyforcommercialcard'] = "0";
380-
$params['txntype'] = 'sales';
381-
$params['secure3dsecuritylevel'] = '3d';
375+
$params['txntimestamp'] = date("d/m/Y H:i:s");
376+
$params['refreshtime'] = 5;
377+
$params['cardnumber'] = $this->getCard()->getNumber();
378+
$params['cardexpiredatemonth'] = $this->getCard()->getExpiryMonth();
379+
$params['cardexpiredateyear'] = $this->getCard()->getExpiryYear();
380+
$params['cardexpiredateyear'] = $this->getCard()->getExpiryYear();
381+
$params['cardcvv2'] = $this->getCard()->getCvv();
382+
$params['secure3dsecuritylevel'] = '3D';
382383

383384
$hashData = strtoupper(sha1($this->getTerminalId() . $params['orderid'] . $params['txnamount'] . $params['successurl'] . $params['errorurl'] . $params['txntype'] . $params['txninstallmentcount'] . $this->getSecureKey() . $this->getSecurityHash()));
384385
$params['secure3dhash'] = $hashData;

src/Messages/AbstractResponse.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,28 @@ public function getCode(): ?string
3232
return (string)$this->data["Transaction"]->Response->Code ?? null;
3333
}
3434

35-
/**
36-
* @return boolean
37-
*/
38-
public function isSuccessful(): bool
39-
{
40-
return isset($this->data["Transaction"]) ? $this->data["Transaction"]->Response->Code == '00' : false;
41-
}
42-
4335
/**
4436
* @param string $data
4537
* @return array
4638
*/
4739
public function setData(string $data): array
4840
{
4941
if (mb_strpos($data, "html")) {
50-
$content = (array)trim(strip_tags($data));
42+
$content = (array)$data;
5143
} else {
5244
$content = (array)simplexml_load_string($data);
5345
}
5446

5547
return $this->data = $content;
5648
}
49+
50+
/**
51+
* Is the response successful?
52+
*
53+
* @return bool
54+
*/
55+
public function isSuccessful()
56+
{
57+
58+
}
5759
}

src/Messages/AuthorizeResponse.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,11 @@
99
class AuthorizeResponse extends AbstractResponse
1010
{
1111

12+
/**
13+
* @return boolean
14+
*/
15+
public function isSuccessful(): bool
16+
{
17+
return isset($this->data["Transaction"]) ? $this->data["Transaction"]->Response->Code == '00' : false;
18+
}
1219
}

src/Messages/CaptureResponse.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,11 @@
88
class CaptureResponse extends AbstractResponse
99
{
1010

11+
/**
12+
* @return boolean
13+
*/
14+
public function isSuccessful(): bool
15+
{
16+
return isset($this->data["Transaction"]) ? $this->data["Transaction"]->Response->Code == '00' : false;
17+
}
1118
}

src/Messages/CompletePurchaseRequest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class CompletePurchaseRequest extends AbstractRequest
1616
*/
1717
public function getData()
1818
{
19+
$this->setPaymentType();
20+
1921
if (!in_array($this->getMd(), array(1, 2, 3, 4))) {
2022
throw new RuntimeException('3DSecure verification error');
2123
}

src/Messages/CompletePurchaseResponse.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,11 @@
77

88
class CompletePurchaseResponse extends AbstractResponse
99
{
10-
10+
/**
11+
* @return boolean
12+
*/
13+
public function isSuccessful(): bool
14+
{
15+
return isset($this->data["Transaction"]) ? $this->data["Transaction"]->Response->Code == '00' : false;
16+
}
1117
}

src/Messages/PurchaseResponse.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,27 @@
88
class PurchaseResponse extends AbstractResponse
99
{
1010

11+
/**
12+
* @return boolean
13+
*/
14+
public function isSuccessful(): bool
15+
{
16+
return true;
17+
}
18+
19+
/**
20+
* @return bool
21+
*/
22+
public function isRedirect(): bool
23+
{
24+
return true;
25+
}
26+
27+
/**
28+
* @return array
29+
*/
30+
public function getRedirectData(): array
31+
{
32+
return $this->getData();
33+
}
1134
}

tests/GatewayTest.php

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public function setUp()
2727
$this->gateway->setTestMode(true);
2828
}
2929

30-
3130
public function testAuthorize()
3231
{
3332
$this->options = [
@@ -68,39 +67,39 @@ public function testPurchase()
6867
{
6968
$this->options = [
7069
'card' => $this->getCardInfo(),
71-
'orderId' => '10082020_114108',
70+
'orderId' => '10082020_114102',
7271
'username' => 'PROVAUT',
7372
'password' => '123qweASD/',
74-
'amount' => "100",
73+
'amount' => "10",
7574
'currency' => 'TRY',
76-
'returnUrl' => "www.backref.com.tr",
77-
'cancelUrl' => "www.backref.com.tr",
75+
'returnUrl' => "https://eticaret.garanti.com.tr/destek/postback.aspx",
76+
'cancelUrl' => "https://eticaret.garanti.com.tr/destek/postback.aspx",
7877
'installment' => "",
79-
'paymentType' => '',
80-
'clientIp' => '10.241.19.2'
78+
'paymentType' => '3d',
79+
'clientIp' => '10.241.19.2',
80+
'secureKey' => '12345678'
8181
];
8282

8383
/** @var PurchaseResponse $response */
8484
$response = $this->gateway->purchase($this->options)->send();
85-
8685
$this->assertTrue($response->isSuccessful());
8786
}
8887

8988
public function testCompletePurchase()
9089
{
9190
$this->options = [
9291
'card' => $this->getCardInfo(),
93-
'orderId' => '8443343542',
92+
'orderId' => '10082020_114212',
9493
'username' => 'PROVAUT',
95-
'password' => '123qweASD',
96-
'amount' => "1",
94+
'password' => '123qweASD/',
95+
'amount' => "10",
9796
'currency' => 'TRY',
98-
'installment' => "1",
99-
'cavv' => '1',
100-
'eci' => '1',
101-
'xid' => '1',
97+
'installment' => "",
98+
'cavv' => 'jCm0m+u/0hUfAREHBAMBcfN+pSo=',
99+
'eci' => '02',
100+
'xid' => 'RszfrwEYe/8xb7rnrPuh6C9pZSQ=',
102101
'md' => '1',
103-
'paymentType' => ''
102+
'clientIp' => '10.241.19.2'
104103
];
105104

106105
/** @var CompletePurchaseResponse $response */
@@ -114,10 +113,10 @@ public function testCompletePurchase()
114113
private function getCardInfo(): CreditCard
115114
{
116115
$cardInfo = $this->getValidCard();
117-
$cardInfo['number'] = '5549608789641500';
118-
$cardInfo['expiryMonth'] = "03";
119-
$cardInfo['expiryYear'] = "2023";
120-
$cardInfo['cvv'] = "712";
116+
$cardInfo['number'] = '4282209004348015';
117+
$cardInfo['expiryMonth'] = "08";
118+
$cardInfo['expiryYear'] = "22";
119+
$cardInfo['cvv'] = "123";
121120
$card = new CreditCard($cardInfo);
122121
$card->setEmail("emrez@garanti.com.tr");
123122
$card->setFirstName('Test name');

0 commit comments

Comments
 (0)