Skip to content

Commit

Permalink
Merge pull request #34 from Nuvei/development
Browse files Browse the repository at this point in the history
Align methods to current API + PHPUnit tests
  • Loading branch information
Silviyap authored Aug 15, 2024
2 parents 634d2ca + 5e7476e commit 493fca5
Show file tree
Hide file tree
Showing 20 changed files with 1,953 additions and 55 deletions.
98 changes: 94 additions & 4 deletions src/Nuvei/Api/Service/AdvancedAPMIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ public function addBankAccount(array $params)
'userTokenId',
];

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

return $this->requestJson($params, 'addBankAccount.do');
return $this->call($params, $mandatoryFields, 'addBankAccount.do', null, true);
}

/**
Expand Down Expand Up @@ -91,4 +88,97 @@ public function enrollAccount(array $params)

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

/**
* @param array $params
*
* @return mixed
* @throws \Nuvei\Api\Exception\ConnectionException
* @throws \Nuvei\Api\Exception\ResponseException
* @throws \Nuvei\Api\Exception\ValidationException
* @link https://docs.nuvei.com/api/advanced/indexAdvanced.html?json#fundAccount
*/
public function fundAccount(array $params)
{
$mandatoryFields = [
'sessionToken',
'merchantId',
'merchantSiteId',
'clientUniqueId',
'clientRequestId',
'paymentOption' =>[
'alternativePaymentMethod' => [
'paymentMethod'
],
],
'userId',
];

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

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

/**
* @param array $params
*
* @return mixed
* @throws \Nuvei\Api\Exception\ConnectionException
* @throws \Nuvei\Api\Exception\ResponseException
* @throws \Nuvei\Api\Exception\ValidationException
* @link https://docs.nuvei.com/api/advanced/indexAdvanced.html?json#getAccountDetails
*/
public function getAccountDetails(array $params)
{
$mandatoryFields = [
'sessionToken',
'merchantId',
'merchantSiteId',
'clientUniqueId',
'clientRequestId',
'paymentOption' =>[
'alternativePaymentMethod' => [
'paymentMethod'
],
],
'userId',
];

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

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

/**
* @param array $params
*
* @return mixed
* @throws \Nuvei\Api\Exception\ConnectionException
* @throws \Nuvei\Api\Exception\ResponseException
* @throws \Nuvei\Api\Exception\ValidationException
* @link https://docs.nuvei.com/api/advanced/indexAdvanced.html?json#getDocumentUrl
*/
public function getDocumentUrl(array $params)
{
$mandatoryFields = [
'sessionToken',
'merchantId',
'merchantSiteId',
'clientUniqueId',
'clientRequestId',
'paymentOption' =>[
'alternativePaymentMethod' => [
'paymentMethod'
],
],
'documentType',
];

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

return $this->requestJson($params, 'getDocumentUrl.do');
}
}
40 changes: 34 additions & 6 deletions src/Nuvei/Api/Service/BaseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ public function getSessionToken()
*/
public function appendMerchantIdMerchantSiteIdTimeStamp($params = [])
{
if (empty($params['merchantId'])) {
$params['merchantId'] = $this->client->getConfig()->getMerchantId();
}
if (empty($params['merchantSiteId'])) {
$params['merchantSiteId'] = $this->client->getConfig()->getMerchantSiteId();
$params = ['merchantSiteId' => $this->client->getConfig()->getMerchantSiteId()] + $params;
}
if (empty($params['merchantId'])) {
$params = ['merchantId' => $this->client->getConfig()->getMerchantId()] + $params;
}
if (empty($params['timeStamp'])) {
$params['timeStamp'] = date('YmdHms');
Expand Down Expand Up @@ -178,14 +178,14 @@ public function requestJson($params, $endpoint)
$params['sourceApplication'] = Utils::getSourceApplication();
$params['webMasterId'] = Utils::getWebMasterID();

if($debug) {
if ($debug) {
echo "\nMethod: " . $endpoint . "\nRequest: ";
print_r($params);
}

$response = $curlClient->requestJson($this, $this->apiUrl . $endpoint, $params);

if($debug) {
if ($debug) {
echo "Response: ";
print_r($response);
}
Expand All @@ -208,4 +208,32 @@ public function requestPost($params, $endpoint)

return $curlClient->requestPost($this, $this->apiUrl . $endpoint, $params);
}

protected function call($params, $mandatoryFields, $endpoint, $checksumParametersOrder = null, $processAdditionalParams = false)
{
if (!$checksumParametersOrder && $processAdditionalParams) {
$paramKeys = array_keys($params);
$checksumParametersOrder = [
'merchantId',
'merchantSiteId',
...$paramKeys,
'timeStamp',
'checksum'
];
}
if (!$checksumParametersOrder) {
$checksumParametersOrder = $mandatoryFields;
}
$params = $this->appendMerchantIdMerchantSiteIdTimeStamp($params);

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

return $this->requestJson($params, $endpoint);
}
}
90 changes: 90 additions & 0 deletions src/Nuvei/Api/Service/KYC.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php
namespace Nuvei\Api\Service;

use Nuvei\Api\Service\BaseService;
use Nuvei\Api\RestClient;

class KYC extends BaseService
{
/**
* Orders constructor.
*
* @param RestClient $client
*
* @throws \Nuvei\Api\Exception\ConfigurationException
*/
public function __construct(RestClient $client)
{
parent::__construct($client);
}

/**
* @param array $params
*
* @return mixed
* @throws \Nuvei\Api\Exception\ConnectionException
* @throws \Nuvei\Api\Exception\ResponseException
* @throws \Nuvei\Api\Exception\ValidationException
* @link https://docs.nuvei.com/api/advanced/indexAdvanced.html?json#eKYC
*/
public function getEKYC($params = [])
{
$mandatory = [
'merchantId',
'merchantSiteId',
'userTokenId',
'userId',
'clientUniqueId',
'clientRequestId',
'userDetails',
'ekycUserDetails',
'timeStamp',
'checksum'
];

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

return $this->call($params, $mandatory, 'eKYC.do', $checksumParametersOrder, true);
}

/**
* @param array $params
*
* @return mixed
* @throws \Nuvei\Api\Exception\ConnectionException
* @throws \Nuvei\Api\Exception\ResponseException
* @throws \Nuvei\Api\Exception\ValidationException
* @link https://docs.nuvei.com/api/advanced/indexAdvanced.html?json#getDocumentUploadUrl
*/
public function getDocumentUploadUrl($params = [])
{
$mandatory = [
'merchantId',
'merchantSiteId',
'userTokenId',
'userId',
'clientUniqueId',
'clientRequestId',
'userDetails',
'kycUserDetails',
'timeStamp',
'checksum'
];

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

return $this->call($params, $mandatory, 'getDocumentUploadUrl.do', $checksumParametersOrder, true);
}
}
49 changes: 46 additions & 3 deletions src/Nuvei/Api/Service/Payments/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ public function createSubscription(array $params)

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

return $this->requestJson($params, 'createSubscription.do');
$return = $this->requestJson($params, 'createSubscription.do');
$return['params'] = $params;
return $return;
}

/**
Expand Down Expand Up @@ -129,8 +131,8 @@ public function getSubscriptionsList(array $params)
'merchantId',
'merchantSiteId',
'userTokenId',
'planId',
'subscriptionId',
'planIds',
'subscriptionIds',
'subscriptionStatus',
'timeStamp',
'merchantSecretKey'
Expand All @@ -153,6 +155,7 @@ public function getSubscriptionsList(array $params)
* @throws \Nuvei\Api\Exception\ConnectionException
* @throws \Nuvei\Api\Exception\ResponseException
* @throws \Nuvei\Api\Exception\ValidationException
* @link https://docs.nuvei.com/api/advanced/indexAdvanced.html?json#getSubscriptionPlans
*/
public function getSubscriptionPlans(array $params)
{
Expand All @@ -169,4 +172,44 @@ public function getSubscriptionPlans(array $params)

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

/**
* @param array $params
*
* @return mixed
* @throws \Nuvei\Api\Exception\ConnectionException
* @throws \Nuvei\Api\Exception\ResponseException
* @throws \Nuvei\Api\Exception\ValidationException
* @link https://docs.nuvei.com/api/advanced/indexAdvanced.html?json#editSubscription
*/
public function editSubscription(array $params)
{
$mandatoryFields = [
'merchantId',
'merchantSiteId',
'subscriptionId',
'timeStamp',
'checksum'
];

$checksumParametersOrder = [
'merchantId',
'merchantSiteId',
'subscriptionId',
'userPaymentOptionId',
'recurringAmount',
'currency',
'timeStamp',
'merchantSecretKey'
];

$params = $this->appendMerchantIdMerchantSiteIdTimeStamp($params);
if (empty($params['checksum'])) {
$params['checksum'] = Utils::calculateChecksum($params, $checksumParametersOrder, $this->client->getConfig()->getMerchantSecretKey(), $this->client->getConfig()->getHashAlgorithm());
}

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

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

0 comments on commit 493fca5

Please sign in to comment.