Skip to content

Commit

Permalink
Add getPaymentStatus method + PHPUnit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolay Vafiadis committed Sep 23, 2020
1 parent 9a439ad commit dcd7b96
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 2 deletions.
1 change: 0 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="tests/bootstrap.php"
>
<testsuites>
Expand Down
1 change: 1 addition & 0 deletions simpleApp/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

$config = [
'environment' => 'test',
'sslVerifyPeer' => true,
'merchantId' => '5078248497400694938',
'merchantSiteId' => '142163',
'merchantSecretKey' => 'F0EpuOTjZPIKw5SGcNGyISClL1zaVnArABS65EkfUIwVmzgNbEiiQeesGp4N79Rg',
Expand Down
11 changes: 11 additions & 0 deletions src/SafeCharge/Api/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,15 @@ public function getHashAlgorithm()
}
return $this->configData['hashAlgorithm'];
}

/**
* @return boolean
*/
public function sslVerifyPeer()
{
if (isset($this->configData['sslVerifyPeer']) && $this->configData['sslVerifyPeer'] == false ) {
return false;
}
return true;
}
}
6 changes: 6 additions & 0 deletions src/SafeCharge/Api/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ public function requestJson(ServiceInterface $service, $requestUrl, $params)

//Initiate cURL.
$ch = curl_init($requestUrl);

if ($config->sslVerifyPeer() == false) {
// connect via SSL without checking certificate
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
}

//Tell cURL that we want to send a POST request.
curl_setopt($ch, CURLOPT_POST, 1);
// set authorisation
Expand Down
20 changes: 20 additions & 0 deletions src/SafeCharge/Api/Service/PaymentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,24 @@ public function voidTransaction(array $params)

return $this->requestJson($params, 'voidTransaction.do');
}

/**
* @param array $params
*
* @return mixed
* @throws \SafeCharge\Api\Exception\ConnectionException
* @throws \SafeCharge\Api\Exception\ResponseException
* @throws \SafeCharge\Api\Exception\ValidationException
* @link https://www.safecharge.com/docs/API/main/indexMain_v1_0.html?json#getPaymentStatus
*/
public function getPaymentStatus(array $params)
{
$mandatoryFields = ['sessionToken'];

$params = $this->appendMerchantIdMerchantSiteIdTimeStamp($params);

$this->validate($params, $mandatoryFields);

return $this->requestJson($params, 'getPaymentStatus.do');
}
}
29 changes: 28 additions & 1 deletion tests/PaymentServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ public function testRefundTransaction()
*/
public function testVoidTransaction()
{

$transactionData = TestCaseHelper::createAndReturnTransaction(false);

$dynamicDescriptor = SimpleData::getDynamicDescriptor();
Expand All @@ -186,4 +185,32 @@ public function testVoidTransaction()
$response = $this->service->voidTransaction($params);
$this->assertEquals('SUCCESS', $response['status']);
}

/**
* @throws Exception
* @throws ConnectionException
* @throws ResponseException
* @throws ValidationException
* @run ./vendor/phpunit/phpunit/phpunit --filter testGetPaymentStatus ./tests/PaymentServiceTest.php
*/
public function testGetPaymentStatus()
{
$createPayment = $this->service->createPayment([
'currency' => SimpleData::getCurrency(),
'amount' => SimpleData::getAmount(),
'userTokenId' => TestCaseHelper::getUserTokenId(),
'paymentOption' => [
'card' => SimpleData::getCarData()
],
'billingAddress' => SimpleData::getBillingAddress(),
'deviceDetails' => SimpleData::getDeviceDetails()
]);

$params = [
'sessionToken' => $createPayment['sessionToken']
];

$response = $this->service->getPaymentStatus($params);
$this->assertEquals('SUCCESS', $response['status']);
}
}
1 change: 1 addition & 0 deletions tests/TestCaseHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public static function getClient()

self::$client = new RestClient([
'environment' => $config['environment'],
'sslVerifyPeer' => $config['sslVerifyPeer'],
'merchantId' => $config['merchantId'],
'merchantSiteId' => $config['merchantSiteId'],
'merchantSecretKey' => $config['merchantSecretKey'],
Expand Down
1 change: 1 addition & 0 deletions tests/config.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
environment = 'test'
sslVerifyPeer = true
merchantId = '5078248497400694938'
merchantSiteId = '142163'
merchantSecretKey = 'F0EpuOTjZPIKw5SGcNGyISClL1zaVnArABS65EkfUIwVmzgNbEiiQeesGp4N79Rg'
Expand Down

0 comments on commit dcd7b96

Please sign in to comment.