Skip to content

Commit

Permalink
Merge pull request #1 from iSerter/master
Browse files Browse the repository at this point in the history
parameter validations & mutations
  • Loading branch information
iSerter authored Nov 28, 2017
2 parents 9d524f1 + 1765cb5 commit bb375a9
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 11 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
* guzzlehttp/guzzle: ^6.3

### Todo
* Auto currency code conversion. (TL to 949, USD to 840, etc.)
* Test Cases
* Validations: card number (Pan), urls, expireDate, etc..

#### Merchant Ayarları (opsiyonel)
`merchantId` ve `merchantPassword` parametreleri global config objesinde birkez yada her servis başına ayrı ayrı set edilebilir.
Expand All @@ -33,7 +31,7 @@ $service->params()
->setRequestId('unique-request-id'); // verifyEnrollmentRequestId
$response = $service->makeRequest()->getResponse();
echo $response->Status . PHP_EOL; // Y/N/E
echo $response->Status; // Y/N/E
```

Expand All @@ -55,6 +53,5 @@ $service->params()
->setTransactionId($data['VerifyEnrollmentRequestId']);
$response = $service->makeRequest()->getResponse();
var_dump($response->isSuccessfull()); // true/false
```
24 changes: 23 additions & 1 deletion src/Services/MpiEnrollment/MpiEnrollmentParameters.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

namespace Teknasyon\Isbank\Services\MpiEnrollment;

use function GuzzleHttp\Psr7\str;
use Teknasyon\Isbank\Helpers\CurrencyCode;
use Teknasyon\Isbank\IsbankConfig;

Expand Down Expand Up @@ -29,7 +31,7 @@ class MpiEnrollmentParameters
public function __construct()
{
$this->setMerchantId(IsbankConfig::get('merchantId'))
->setMerchantPassword(IsbankConfig::get('merchantPassword'));
->setMerchantPassword(IsbankConfig::get('merchantPassword'));
}

/*
Expand Down Expand Up @@ -85,6 +87,9 @@ public function getPan()
*/
public function setPan($pan)
{
if (strlen($pan) != 16 || !is_numeric($pan)) {
throw new \InvalidArgumentException("Invalid Pan (card number)");
}
$this->pan = $pan;
return $this;
}
Expand All @@ -103,6 +108,17 @@ public function getExpiryDate()
*/
public function setExpiryDate($expiryDate)
{
if(strlen($expiryDate) === 6) {
$expiryDate = substr($expiryDate,-4);
}

if(strlen($expiryDate) != 4
|| substr($expiryDate,0,2) < date('y')
|| substr($expiryDate,2,2) > 31
|| substr($expiryDate,2,2) < 1) {
throw new \InvalidArgumentException("Expiry date must be in YYMM format, and cannot be a past date.");
}

$this->expiryDate = $expiryDate;
return $this;
}
Expand Down Expand Up @@ -222,6 +238,9 @@ public function getSuccessUrl()
*/
public function setSuccessUrl($successUrl)
{
if(filter_var($successUrl, FILTER_VALIDATE_URL) === false) {
throw new \InvalidArgumentException("Invalid Success URL provided for Isbank MPI Enrollment service.");
}
$this->successUrl = $successUrl;
return $this;
}
Expand All @@ -240,6 +259,9 @@ public function getFailureUrl()
*/
public function setFailureUrl($failureUrl)
{
if(filter_var($failureUrl, FILTER_VALIDATE_URL) === false) {
throw new \InvalidArgumentException("Invalid Failure URL provided for Isbank MPI Enrollment service.");
}
$this->failureUrl = $failureUrl;
return $this;
}
Expand Down
13 changes: 12 additions & 1 deletion src/Services/VirtualPos/VirtualPosParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public function __construct()
->setMerchantPassword(IsbankConfig::get('merchantPassword'));
}


/*
|--------------------------------------------------------------------------
| Helpers
Expand Down Expand Up @@ -281,6 +280,18 @@ public function getExpiry()
*/
public function setExpiry($expiry)
{
// Convert YYMM to YYYYMM
if(strlen($expiry) === 4) {
$expiry = '20'.$expiry;
}

if(strlen($expiry) != 6
|| substr($expiry,0,4) < date('Y')
|| substr($expiry,4,2) > 31
|| substr($expiry,4,2) < 1) {
throw new \InvalidArgumentException("Invalid expiry date provided as Isbank Virtual POS parameter.");
}

$this->expiry = $expiry;
return $this;
}
Expand Down
21 changes: 16 additions & 5 deletions tests/MpiEnrollmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function testGlobalTestEnvironmentConfigAppliesToTheService()
{
$this->assertTrue($this->service->isTestEnvironment());
}

public function testEndpointIsOfTheTestEnvironment()
{
$this->assertEquals(
Expand All @@ -43,21 +43,32 @@ public function testEndpointIsOfTheTestEnvironment()

public function testParametersCanBeSet()
{
$pan = 123456789; // @todo rest of the params
$pan = 1234567891234567; // @todo rest of the params
$expiryDate = '2012';
$this->service->params()
->setPan($pan);
->setPan($pan)
->setExpiryDate($expiryDate);

$this->assertEquals($pan, $this->service->params()->getPan());
$this->assertEquals($expiryDate, $this->service->params()->getExpiryDate());
}

public function testExpireDateAcceptsYYYYMMFormat()
{
$this->service->params()
->setExpiryDate('201905');

$this->assertEquals('1905', $this->service->params()->getExpiryDate());
}

public function testParametersCanBeSetViaClosure()
{

$this->service->setParams(function (MpiEnrollmentParameters $params) {
$params->setPan(123456789);
$params->setPan(1234567891234567);
});

$this->assertEquals('123456789', $this->service->params()->getPan());
$this->assertEquals('1234567891234567', $this->service->params()->getPan());
}

public function testAlphaCurrencyCodeGetsConvertedToNumericCode()
Expand Down

0 comments on commit bb375a9

Please sign in to comment.