Skip to content

Commit bb52a46

Browse files
authored
Merge pull request #9 from alegraio/dev
Edited amount.
2 parents 539a7bb + 40204fe commit bb52a46

File tree

5 files changed

+53
-51
lines changed

5 files changed

+53
-51
lines changed

src/Messages/AbstractRequest.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -231,43 +231,38 @@ protected function getHttpMethod(): string
231231

232232
/**
233233
* @return string
234+
* @throws \Omnipay\Common\Exception\InvalidRequestException
234235
*/
235236
protected function getTransactionHash(): string
236237
{
238+
$amount = (int)$this->getAmount();
239+
237240
return strtoupper(SHA1(sprintf('%s%s%s%s%s',
238241
$this->getOrderId(),
239242
$this->getTerminalId(),
240243
$this->getCard()->getNumber(),
241-
$this->getAmountInteger(),
244+
$amount,
242245
$this->getSecurityHash())));
243246
}
244247

245248
/**
246249
* @return string
250+
* @throws \Omnipay\Common\Exception\InvalidRequestException
247251
*/
248-
protected function getCompletePurchaseTransactionHash(): string
252+
protected function getTransactionHashWithoutCardNumber(): string
249253
{
250-
return strtoupper(SHA1(sprintf('%s%s%s%s',
251-
$this->getOrderId(),
252-
$this->getTerminalId(),
253-
$this->getAmountInteger(),
254-
$this->getSecurityHash())));
255-
}
254+
$amount = (int)$this->getAmount();
256255

257-
/**
258-
* @return string
259-
*/
260-
protected function getRefundOrVoidHash(): string
261-
{
262256
return strtoupper(SHA1(sprintf('%s%s%s%s',
263257
$this->getOrderId(),
264258
$this->getTerminalId(),
265-
$this->getAmountInteger(),
259+
$amount,
266260
$this->getSecurityHash())));
267261
}
268262

269263
/**
270264
* @return array
265+
* @throws \Omnipay\Common\Exception\InvalidRequestException
271266
*/
272267
protected function getSalesRequestParams(): array
273268
{
@@ -298,7 +293,7 @@ protected function getSalesRequestParams(): array
298293
$data['Transaction'] = array(
299294
'Type' => 'sales',
300295
'InstallmentCnt' => $this->getInstallment(),
301-
'Amount' => $this->getAmountInteger(),
296+
'Amount' => (int)$this->getAmount(),
302297
'CurrencyCode' => $this->currency_list[$this->getCurrency()],
303298
'CardholderPresentCode' => "0",
304299
'MotoInd' => "N"
@@ -307,11 +302,14 @@ protected function getSalesRequestParams(): array
307302
return $data;
308303
}
309304

305+
310306
/**
311307
* @return array
308+
* @throws \Omnipay\Common\Exception\InvalidRequestException
312309
*/
313310
protected function getCompleteSalesRequestParams(): array
314311
{
312+
315313
$data = $this->getInfo();
316314
$data['Order'] = array(
317315
'OrderID' => $this->getOrderId()
@@ -323,15 +321,15 @@ protected function getCompleteSalesRequestParams(): array
323321

324322
$data['Terminal'] = [
325323
'ProvUserID' => $this->getUserName(),
326-
'HashData' => $this->getCompletePurchaseTransactionHash(),
324+
'HashData' => $this->getTransactionHashWithoutCardNumber(),
327325
'UserID' => $this->getUserName(),
328326
'ID' => $this->getTerminalId(),
329327
'MerchantID' => $this->getMerchantId()
330328
];
331329

332330
$data['Transaction'] = array(
333331
'Type' => 'sales',
334-
'Amount' => $this->getAmountInteger(),
332+
'Amount' => (int)$this->getAmount(),
335333
'CurrencyCode' => $this->currency_list[$this->getCurrency()],
336334
'MotoInd' => "N"
337335
);
@@ -341,6 +339,7 @@ protected function getCompleteSalesRequestParams(): array
341339

342340
/**
343341
* @return array
342+
* @throws \Omnipay\Common\Exception\InvalidRequestException
344343
*/
345344
protected function getAuthorizeRequestParams(): array
346345
{
@@ -366,7 +365,7 @@ protected function getAuthorizeRequestParams(): array
366365
$data['Transaction'] = array(
367366
'Type' => 'preauth',
368367
'InstallmentCnt' => $this->getInstallment(),
369-
'Amount' => $this->getAmountInteger(),
368+
'Amount' => (int)$this->getAmount(),
370369
'CurrencyCode' => $this->currency_list[$this->getCurrency()],
371370
'CardholderPresentCode' => "0",
372371
'MotoInd' => "N"
@@ -377,6 +376,7 @@ protected function getAuthorizeRequestParams(): array
377376

378377
/**
379378
* @return array
379+
* @throws \Omnipay\Common\Exception\InvalidRequestException
380380
*/
381381
protected function getSalesRequestParamsFor3d(): array
382382
{
@@ -387,7 +387,7 @@ protected function getSalesRequestParamsFor3d(): array
387387
$params['terminalid'] = $this->getTerminalId();
388388
$params['terminalmerchantid'] = $this->getMerchantId();
389389
$params['txntype'] = 'sales';
390-
$params['txnamount'] = $this->getAmountInteger();
390+
$params['txnamount'] = (int)$this->getAmount();
391391
$params['txncurrencycode'] = $this->currency_list[$this->getCurrency()];
392392
$params['txninstallmentcount'] = $this->getInstallment();
393393
$params['customeremailaddress'] = $this->getCard()->getEmail();

src/Messages/PurchaseRequest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public function getData()
2020
if ($this->getPaymentMethod() === self::PAYMENT_TYPE_3D) {
2121
return $this->getSalesRequestParamsFor3d();
2222
}
23+
2324
return $this->getSalesRequestParams();
2425
}
2526

src/Messages/RefundRequest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function getData(): array
1919
$data['Mode'] = $this->getTestMode() ? 'TEST' : 'PROD';
2020
$data['Terminal'] = [
2121
'ProvUserID' => $this->getUserName(),
22-
'HashData' => $this->getRefundOrVoidHash(),
22+
'HashData' => $this->getTransactionHashWithoutCardNumber(),
2323
'UserID' => $this->getUserName(),
2424
'ID' => $this->getTerminalId(),
2525
'MerchantID' => $this->getMerchantId()
@@ -33,7 +33,7 @@ public function getData(): array
3333

3434
$data['Transaction'] = array(
3535
'Type' => 'refund',
36-
'Amount' => $this->getAmountInteger(),
36+
'Amount' => (int)$this->getAmount(),
3737
'CurrencyCode' => $this->currency_list[$this->getCurrency()]
3838
);
3939

src/Messages/VoidRequest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function getData(): array
1919
$data['Mode'] = $this->getTestMode() ? 'TEST' : 'PROD';
2020
$data['Terminal'] = [
2121
'ProvUserID' => $this->getUserName(),
22-
'HashData' => $this->getRefundOrVoidHash(),
22+
'HashData' => $this->getTransactionHashWithoutCardNumber(),
2323
'UserID' => $this->getUserName(),
2424
'ID' => $this->getTerminalId(),
2525
'MerchantID' => $this->getMerchantId()
@@ -34,7 +34,7 @@ public function getData(): array
3434
$data['Transaction'] = array(
3535
'Type' => 'void',
3636
'InstallmentCnt' => $this->getInstallment(),
37-
'Amount' => $this->getAmountInteger(),
37+
'Amount' => (int)$this->getAmount(),
3838
'CurrencyCode' => $this->currency_list[$this->getCurrency()],
3939
'CardholderPresentCode' => "0",
4040
'MotoInd' => "N"

tests/GatewayTest.php

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,38 @@ public function setUp()
3232
}
3333

3434

35+
public function testPurchase()
36+
{
37+
$this->options = [
38+
'card' => $this->getCardInfo(),
39+
'orderId' => '8985204111',
40+
'amount' => "100",
41+
'currency' => 'TRY',
42+
'returnUrl' => "https://eticaret.garanti.com.tr/destek/postback.aspx",
43+
'cancelUrl' => "https://eticaret.garanti.com.tr/destek/postback.aspx",
44+
'installment' => "",
45+
'paymentMethod' => '3d',
46+
'clientIp' => '10.241.19.2',
47+
'secureKey' => '12345678'
48+
];
49+
50+
/** @var PurchaseResponse $response */
51+
$response = $this->gateway->purchase($this->options)->send();
52+
53+
$this->assertTrue($response->isSuccessful());
54+
}
55+
56+
3557
public function testCompletePurchase()
3658
{
3759
$this->options = [
38-
'orderId' => '234567',
39-
'amount' => "300",
60+
'orderId' => '424569',
61+
'amount' => "3",
4062
'currency' => 'TRY',
4163
'cavv' => 'jCm0m+u/0hUfAREHBAMBcfN+pSo=',
4264
'eci' => '02',
4365
'xid' => 'RszfrwEYe/8xb7rnrPuh6C9pZSQ=',
44-
'md' => 'SbEsOKX7ObDWDySsIxdAWk+S+OBRqtO9JhbzBb2vwcwcMfMi8VJcrKYBp01awsE1igb80xCyNEI/BNFWrX8oWwIKPyiRfx+dQIiKnFFIkyv1ZIVKeQ27LLFEx62qjVpSI31fondWTP98n7pChG/Jmg==',
66+
'md' => 'SbEsOKX7ObDWDySsIxdAWk+S+OBRqtO9JhbzBb2vwcwJ7nw4PmXWPaXT2zLq3Mz4hAI7F3GTIgCh4F8EC2l0LMYOr9yaA8G0yq3hudtek3FZtMRuxD29rUwF3a10zd3fQI/tSTSHkMdiT5kjKRC4Eg==',
4567
'mdStatus' => '1',
4668
'clientIp' => '172.18.0.1'
4769
];
@@ -83,27 +105,6 @@ public function testAuthorize()
83105
$this->assertTrue($response->isSuccessful());
84106
}
85107

86-
public function testPurchase()
87-
{
88-
$this->options = [
89-
'card' => $this->getCardInfo(),
90-
'orderId' => '89852041_14102',
91-
'amount' => "10",
92-
'currency' => 'TRY',
93-
'returnUrl' => "https://eticaret.garanti.com.tr/destek/postback.aspx",
94-
'cancelUrl' => "https://eticaret.garanti.com.tr/destek/postback.aspx",
95-
'installment' => "",
96-
'paymentMethod' => '3d',
97-
'clientIp' => '10.241.19.2',
98-
'secureKey' => '12345678'
99-
];
100-
101-
/** @var PurchaseResponse $response */
102-
$response = $this->gateway->purchase($this->options)->send();
103-
$this->assertTrue($response->isSuccessful());
104-
}
105-
106-
107108
public function testVoid()
108109
{
109110
$this->options = [
@@ -144,10 +145,10 @@ public function testRefund()
144145
private function getCardInfo(): CreditCard
145146
{
146147
$cardInfo = $this->getValidCard();
147-
$cardInfo['number'] = '5406697543211173';//4282209004348015
148-
$cardInfo['expiryMonth'] = "03"; //08";
149-
$cardInfo['expiryYear'] = "23";//22";
150-
$cardInfo['cvv'] = "465";//123";
148+
$cardInfo['number'] = '4282209004348015';
149+
$cardInfo['expiryMonth'] = "08";
150+
$cardInfo['expiryYear'] = "22";
151+
$cardInfo['cvv'] = "123";
151152
$card = new CreditCard($cardInfo);
152153
$card->setEmail("emrez@garanti.com.tr");
153154
$card->setFirstName('Test name');

0 commit comments

Comments
 (0)