Skip to content

Commit e0d4634

Browse files
authored
Merge pull request #2 from alegraio/dev
Edited actions.
2 parents 93d1920 + 9545a4e commit e0d4634

File tree

5 files changed

+63
-67
lines changed

5 files changed

+63
-67
lines changed

src/Messages/AbstractRequest.php

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest
1212
{
1313
/** @var string */
14-
protected $version = 'v1.0';
14+
protected $version = 'v0.01';
1515

1616
/** @var array */
1717
protected $endpoints = [
@@ -114,6 +114,24 @@ public function setPassword(string $value): AbstractRequest
114114
return $this->setParameter('password', $value);
115115
}
116116

117+
/**
118+
* @return string
119+
*/
120+
public function getPaymentType(): string
121+
{
122+
return $this->getParameter('paymentType');
123+
}
124+
125+
/**
126+
* @param string $value
127+
* @return AbstractRequest
128+
*/
129+
public function setPaymentType(string $value = ""): AbstractRequest
130+
{
131+
return $this->setParameter('paymentType', $value);
132+
}
133+
134+
117135
/**
118136
* @param mixed $data
119137
* @return ResponseInterface|AbstractResponse
@@ -168,23 +186,6 @@ public function setOrderId(string $value): AbstractRequest
168186
return $this->setParameter('orderId', $value);
169187
}
170188

171-
/**
172-
* @return string|null
173-
*/
174-
public function getPaymentType(): string
175-
{
176-
return $this->getParameter('paymentType') ?? null;
177-
}
178-
179-
/**
180-
* @param string $value
181-
* @return AbstractRequest
182-
*/
183-
public function setPaymentType(string $value): AbstractRequest
184-
{
185-
return $this->setParameter('paymentType', $value);
186-
}
187-
188189
/**
189190
* @return string
190191
*/
@@ -285,8 +286,7 @@ protected function getSalesRequestParams(): array
285286
);
286287

287288
$data['Order'] = array(
288-
'OrderID' => $this->getOrderId(),
289-
'GroupID' => ""
289+
'OrderID' => $this->getOrderId()
290290
);
291291

292292
$data['Customer'] = array(
@@ -297,8 +297,8 @@ protected function getSalesRequestParams(): array
297297
$data['Terminal'] = [
298298
'ProvUserID' => $this->getUserName(),
299299
'HashData' => $this->getTransactionHash(),
300-
'UserID' => $this->getUserName(),
301-
'ID' => str_repeat('0', 9 - strlen($this->getTerminalId())),
300+
'UserID' => 'PROVAUT',
301+
'ID' => $this->getTerminalId(),
302302
'MerchantID' => $this->getMerchantId()
303303
];
304304

@@ -308,14 +308,7 @@ protected function getSalesRequestParams(): array
308308
'Amount' => $this->getAmountInteger(),
309309
'CurrencyCode' => $this->currency_list[$this->getCurrency()],
310310
'CardholderPresentCode' => "0",
311-
'MotoInd' => "N",
312-
'Description' => "",
313-
'OriginalRetrefNum' => $this->getTransactionId(),
314-
'CepBank' => array(
315-
'GSMNumber' => $this->getCard()->getBillingPhone(),
316-
'CepBank' => ""
317-
),
318-
'PaymentType' => "K"
311+
'MotoInd' => "N"
319312
);
320313

321314
return $data;
@@ -332,7 +325,7 @@ protected function getAuthorizeRequestParams(): array
332325
'ProvUserID' => $this->getUserName(),
333326
'HashData' => $this->getTransactionHash(),
334327
'UserID' => $this->getUserName(),
335-
'ID' => str_repeat('0', 9 - strlen($this->getTerminalId())),
328+
'ID' => $this->getTerminalId(),
336329
'MerchantID' => $this->getMerchantId()
337330
];
338331
$data['Customer'] = array(
@@ -344,16 +337,15 @@ protected function getAuthorizeRequestParams(): array
344337
'ExpireDate' => $this->getCard()->getExpiryDate('my')
345338
);
346339
$data['Order'] = array(
347-
'OrderID' => $this->getOrderId(),
348-
'GroupID' => ""
340+
'OrderID' => $this->getOrderId()
349341
);
350342
$data['Transaction'] = array(
351343
'Type' => 'preauth',
352344
'InstallmentCnt' => $this->getInstallment(),
353345
'Amount' => $this->getAmountInteger(),
354346
'CurrencyCode' => $this->currency_list[$this->getCurrency()],
355347
'CardholderPresentCode' => "0",
356-
'MotoInd' => "H"
348+
'MotoInd' => "N"
357349
);
358350

359351
return $data;
@@ -365,7 +357,6 @@ protected function getAuthorizeRequestParams(): array
365357
*/
366358
protected function getSalesRequestParamsFor3d(): array
367359
{
368-
$params['apiversion'] = $this->version;
369360
$params['apiversion'] = $this->version;
370361
$params['mode'] = $this->getTestMode();
371362
$params['terminalprovuserid'] = $this->getUserName();

src/Messages/AbstractResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function getCode(): ?string
3737
*/
3838
public function isSuccessful(): bool
3939
{
40-
return isset($this->data["Transaction"]) ? $this->data["Transaction"]->Response->Code === '00' : false;
40+
return isset($this->data["Transaction"]) ? $this->data["Transaction"]->Response->Code == '00' : false;
4141
}
4242

4343
/**

src/Messages/AuthorizeRequest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ class AuthorizeRequest extends AbstractRequest
1616
*/
1717
public function getData(): array
1818
{
19-
return $data = $this->getAuthorizeRequestParams();
19+
$this->setPaymentType();
20+
return $this->getAuthorizeRequestParams();
2021
}
2122

2223
/**

src/Messages/CaptureRequest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ class CaptureRequest extends AbstractRequest
1414
*/
1515
public function getData(): array
1616
{
17-
$data = $this->getSalesRequestParams();
17+
$this->setPaymentType();
18+
$data = $this->getAuthorizeRequestParams();
1819
$data['Transaction']['Type'] = 'postauth';
20+
$data['Card']['CVV2'] = $this->getCard()->getCvv();
1921

2022
return $data;
2123
}

tests/GatewayTest.php

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function setUp()
2323
/** @var Gateway gateway */
2424
$this->gateway = new Gateway(null, $this->getHttpRequest());
2525
$this->gateway->setMerchantId('7000679');
26-
$this->gateway->setTerminalId('030691297');
26+
$this->gateway->setTerminalId('30691297');
2727
$this->gateway->setTestMode(true);
2828
}
2929

@@ -32,63 +32,61 @@ public function testAuthorize()
3232
{
3333
$this->options = [
3434
'card' => $this->getCardInfo(),
35-
'orderId' => '8443343542',
35+
'orderId' => '10082020_114109',
3636
'username' => 'PROVAUT',
37-
'password' => '123qweASD',
37+
'password' => '123qweASD/',
3838
'amount' => "1",
3939
'currency' => 'TRY',
40-
'installment' => "1",
41-
'paymentType' => ''
40+
'installment' => "",
41+
'clientIp' => '10.241.19.2'
4242
];
4343

4444
/** @var AuthorizeResponse $response */
4545
$response = $this->gateway->authorize($this->options)->send();
4646
$this->assertTrue($response->isSuccessful());
4747
}
4848

49-
public function testCompletePurchase()
49+
public function testCapture()
5050
{
5151
$this->options = [
5252
'card' => $this->getCardInfo(),
53-
'orderId' => '8443343542',
53+
'orderId' => '10082020_1141',
5454
'username' => 'PROVAUT',
55-
'password' => '123qweASD',
55+
'password' => '123qweASD/',
5656
'amount' => "1",
5757
'currency' => 'TRY',
58-
'installment' => "1",
59-
'cavv' => '1',
60-
'eci' => '1',
61-
'xid' => '1',
62-
'md' => '1',
63-
'paymentType' => ''
58+
'installment' => "",
59+
'clientIp' => '10.241.19.2'
6460
];
6561

66-
/** @var CompletePurchaseResponse $response */
67-
$response = $this->gateway->completePurchase($this->options)->send();
62+
/** @var CaptureResponse $response */
63+
$response = $this->gateway->capture($this->options)->send();
6864
$this->assertTrue($response->isSuccessful());
6965
}
7066

7167
public function testPurchase()
7268
{
7369
$this->options = [
7470
'card' => $this->getCardInfo(),
75-
'orderId' => '8443343542',
71+
'orderId' => '10082020_114108',
7672
'username' => 'PROVAUT',
77-
'password' => '123qweASD',
78-
'amount' => "1",
73+
'password' => '123qweASD/',
74+
'amount' => "100",
7975
'currency' => 'TRY',
8076
'returnUrl' => "www.backref.com.tr",
8177
'cancelUrl' => "www.backref.com.tr",
82-
'installment' => "1"
78+
'installment' => "",
79+
'paymentType' => '',
80+
'clientIp' => '10.241.19.2'
8381
];
8482

8583
/** @var PurchaseResponse $response */
8684
$response = $this->gateway->purchase($this->options)->send();
85+
8786
$this->assertTrue($response->isSuccessful());
8887
}
8988

90-
91-
public function testCapture()
89+
public function testCompletePurchase()
9290
{
9391
$this->options = [
9492
'card' => $this->getCardInfo(),
@@ -98,11 +96,15 @@ public function testCapture()
9896
'amount' => "1",
9997
'currency' => 'TRY',
10098
'installment' => "1",
99+
'cavv' => '1',
100+
'eci' => '1',
101+
'xid' => '1',
102+
'md' => '1',
101103
'paymentType' => ''
102104
];
103105

104-
/** @var CaptureResponse $response */
105-
$response = $this->gateway->capture($this->options)->send();
106+
/** @var CompletePurchaseResponse $response */
107+
$response = $this->gateway->completePurchase($this->options)->send();
106108
$this->assertTrue($response->isSuccessful());
107109
}
108110

@@ -112,12 +114,12 @@ public function testCapture()
112114
private function getCardInfo(): CreditCard
113115
{
114116
$cardInfo = $this->getValidCard();
115-
$cardInfo['number'] = '5406675406675403';
116-
$cardInfo['expiryMonth'] = "12";
117-
$cardInfo['expiryYear'] = "2015";
118-
$cardInfo['cvv'] = "000";
117+
$cardInfo['number'] = '5549608789641500';
118+
$cardInfo['expiryMonth'] = "03";
119+
$cardInfo['expiryYear'] = "2023";
120+
$cardInfo['cvv'] = "712";
119121
$card = new CreditCard($cardInfo);
120-
$card->setEmail("mail@mail.com");
122+
$card->setEmail("emrez@garanti.com.tr");
121123
$card->setFirstName('Test name');
122124
$card->setLastName('Test lastname');
123125

0 commit comments

Comments
 (0)