Skip to content

Commit

Permalink
Add authorize3d method + PHPUnit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolay Vafiadis committed Sep 25, 2020
1 parent dcd7b96 commit 472969f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
25 changes: 25 additions & 0 deletions src/SafeCharge/Api/Service/PaymentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,31 @@ public function initPayment(array $params)
return $this->requestJson($params, 'initPayment.do');
}

/**
* @param array $params
*
* @return mixed
* @throws \SafeCharge\Api\Exception\ConnectionException
* @throws \SafeCharge\Api\Exception\ResponseException
* @throws \SafeCharge\Api\Exception\ValidationException
*/
public function authorize3d(array $params)
{
$mandatoryFields = ['merchantId', 'merchantSiteId', 'sessionToken', 'timeStamp', 'checksum', 'currency', 'amount', 'paymentOption', 'relatedTransactionId', 'deviceDetails', 'billingAddress'];

$checksumParametersOrder = ['merchantId', 'merchantSiteId', 'clientRequestId', 'amount', 'currency', 'timeStamp', 'merchantSecretKey'];

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

$params['checksum'] = Utils::calculateChecksum($params, $checksumParametersOrder, $this->client->getConfig()->getMerchantSecretKey(), $this->client->getConfig()->getHashAlgorithm());
$params['sessionToken'] = $this->getSessionToken();


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

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

/**
* @param array $params
*
Expand Down
33 changes: 31 additions & 2 deletions tests/PaymentServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,47 @@ public function testCreatePayment()
*/
public function testInitPayment()
{
$response = $this->service->createPayment([
$response = $this->service->initPayment([
'currency' => SimpleData::getCurrency(),
'amount' => SimpleData::getAmount(),
'userTokenId' => TestCaseHelper::getUserTokenId(),
'paymentOption' => [
'card' => SimpleData::getCarData()
],
'billingAddress' => SimpleData::getBillingAddress()
'billingAddress' => SimpleData::getBillingAddress(),
'deviceDetails' => SimpleData::getDeviceDetails()
]);
$this->assertEquals('SUCCESS', $response['status']);
}

/**
* @throws ConnectionException
* @throws ResponseException
* @throws ValidationException
* @run ./vendor/phpunit/phpunit/phpunit --filter testAuthorize3d ./tests/PaymentServiceTest.php
*/
public function testAuthorize3d()
{
$paramsAuthorize3d = $paramsInitPayment = [
'currency' => SimpleData::getCurrency(),
'amount' => SimpleData::getAmount(),
'paymentOption' => [
'card' => SimpleData::getCarData()
],
'billingAddress' => SimpleData::getBillingAddress(),
'deviceDetails' => SimpleData::getDeviceDetails(),
];

$paramsInitPayment['userTokenId'] = TestCaseHelper::getUserTokenId();
$initPaymentResponse = $this->service->initPayment($paramsInitPayment);

$paramsAuthorize3d['relatedTransactionId'] = $initPaymentResponse['transactionId'];
$paramsAuthorize3d['sessionToken'] = $initPaymentResponse['sessionToken'];
$authorize3dResponse = $this->service->authorize3d($paramsAuthorize3d);

$this->assertEquals('SUCCESS', $authorize3dResponse['status']);
}

/**
* @return mixed
* @throws ConnectionException
Expand Down

0 comments on commit 472969f

Please sign in to comment.