diff --git a/src/SafeCharge/Api/Service/PaymentService.php b/src/SafeCharge/Api/Service/PaymentService.php index 4656e30..5198bdc 100644 --- a/src/SafeCharge/Api/Service/PaymentService.php +++ b/src/SafeCharge/Api/Service/PaymentService.php @@ -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 * diff --git a/tests/PaymentServiceTest.php b/tests/PaymentServiceTest.php index e181854..790ba4c 100644 --- a/tests/PaymentServiceTest.php +++ b/tests/PaymentServiceTest.php @@ -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