diff --git a/phpunit.xml b/phpunit.xml index 767f5cf..0c64e6e 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -8,7 +8,6 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" - syntaxCheck="false" bootstrap="tests/bootstrap.php" > diff --git a/simpleApp/test.php b/simpleApp/test.php index f394478..c5b2cfa 100644 --- a/simpleApp/test.php +++ b/simpleApp/test.php @@ -12,6 +12,7 @@ $config = [ 'environment' => 'test', + 'sslVerifyPeer' => true, 'merchantId' => '5078248497400694938', 'merchantSiteId' => '142163', 'merchantSecretKey' => 'F0EpuOTjZPIKw5SGcNGyISClL1zaVnArABS65EkfUIwVmzgNbEiiQeesGp4N79Rg', diff --git a/src/SafeCharge/Api/Config.php b/src/SafeCharge/Api/Config.php index 3635e5f..b6ac06a 100644 --- a/src/SafeCharge/Api/Config.php +++ b/src/SafeCharge/Api/Config.php @@ -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; + } } diff --git a/src/SafeCharge/Api/HttpClient.php b/src/SafeCharge/Api/HttpClient.php index 7c83ab3..b21f410 100644 --- a/src/SafeCharge/Api/HttpClient.php +++ b/src/SafeCharge/Api/HttpClient.php @@ -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 diff --git a/src/SafeCharge/Api/Service/PaymentService.php b/src/SafeCharge/Api/Service/PaymentService.php index 3bd3bdd..4656e30 100644 --- a/src/SafeCharge/Api/Service/PaymentService.php +++ b/src/SafeCharge/Api/Service/PaymentService.php @@ -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'); + } } diff --git a/tests/PaymentServiceTest.php b/tests/PaymentServiceTest.php index caf64ef..e181854 100644 --- a/tests/PaymentServiceTest.php +++ b/tests/PaymentServiceTest.php @@ -165,7 +165,6 @@ public function testRefundTransaction() */ public function testVoidTransaction() { - $transactionData = TestCaseHelper::createAndReturnTransaction(false); $dynamicDescriptor = SimpleData::getDynamicDescriptor(); @@ -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']); + } } diff --git a/tests/TestCaseHelper.php b/tests/TestCaseHelper.php index 7d85a87..a099e15 100644 --- a/tests/TestCaseHelper.php +++ b/tests/TestCaseHelper.php @@ -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'], diff --git a/tests/config.ini b/tests/config.ini index 27f1603..585d396 100644 --- a/tests/config.ini +++ b/tests/config.ini @@ -1,4 +1,5 @@ environment = 'test' +sslVerifyPeer = true merchantId = '5078248497400694938' merchantSiteId = '142163' merchantSecretKey = 'F0EpuOTjZPIKw5SGcNGyISClL1zaVnArABS65EkfUIwVmzgNbEiiQeesGp4N79Rg'