Skip to content

Commit

Permalink
Merge pull request #21 from SafeChargeInternational/development
Browse files Browse the repository at this point in the history
New PaymentServices
  • Loading branch information
nikivf authored Mar 5, 2021
2 parents ed7378b + 4064b78 commit 4c0ad87
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 3 deletions.
60 changes: 60 additions & 0 deletions src/SafeCharge/Api/Service/PaymentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,4 +296,64 @@ public function getPaymentStatus(array $params)

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

/**
* @param array $params
*
* @return mixed
* @throws \SafeCharge\Api\Exception\ConnectionException
* @throws \SafeCharge\Api\Exception\ResponseException
* @throws \SafeCharge\Api\Exception\ValidationException
*/
public function getCardDetails(array $params)
{
$mandatoryFields = ['sessionToken', 'merchantId', 'merchantSiteId', 'cardNumber'];

$params = $this->appendMerchantIdMerchantSiteIdTimeStamp($params);
$params['sessionToken'] = $this->getSessionToken();

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

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

/**
* @param array $params
*
* @return mixed
* @throws \SafeCharge\Api\Exception\ConnectionException
* @throws \SafeCharge\Api\Exception\ResponseException
* @throws \SafeCharge\Api\Exception\ValidationException
*/
public function getMcpRates(array $params)
{
$mandatoryFields = ['sessionToken', 'merchantId', 'merchantSiteId', 'fromCurrency'];

$params = $this->appendMerchantIdMerchantSiteIdTimeStamp($params);
$params['sessionToken'] = $this->getSessionToken();

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

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

/**
* @param array $params
*
* @return mixed
* @throws \SafeCharge\Api\Exception\ConnectionException
* @throws \SafeCharge\Api\Exception\ResponseException
* @throws \SafeCharge\Api\Exception\ValidationException
*/
public function getDccDetails(array $params)
{
$mandatoryFields = ['sessionToken', 'merchantId', 'merchantSiteId', 'clientRequestId', 'clientUniqueId', 'originalAmount', 'originalCurrency'];

$params = $this->appendMerchantIdMerchantSiteIdTimeStamp($params);
$params['sessionToken'] = $this->getSessionToken();

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

return $this->requestJson($params, 'getDccDetails.do');
}
}
66 changes: 63 additions & 3 deletions tests/PaymentServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function __construct()
* @throws ConnectionException
* @throws ResponseException
* @throws ValidationException
* @run ./vendor/phpunit/phpunit/phpunit --filter testCreatePayment ./tests/PaymentServiceTest.php
*/
public function testCreatePayment()
{
Expand All @@ -47,7 +48,8 @@ public function testCreatePayment()
'card' => SimpleData::getCardData()
],
'billingAddress' => SimpleData::getBillingAddress(),
'deviceDetails' => SimpleData::getDeviceDetails()
'deviceDetails' => SimpleData::getDeviceDetails(),
'currencyConversion' => SimpleData::getCurrencyConversion(),
]);
$this->assertEquals('SUCCESS', $response['status']);
}
Expand Down Expand Up @@ -139,6 +141,7 @@ public function testVerify3d()
* @throws ConnectionException
* @throws ResponseException
* @throws ValidationException
* @run ./vendor/phpunit/phpunit/phpunit --filter testOpenOrder ./tests/PaymentServiceTest.php
*/
public function testOpenOrder()
{
Expand All @@ -157,11 +160,11 @@ public function testOpenOrder()
'dynamicDescriptor' => SimpleData::getDynamicDescriptor(),
'merchantDetails' => SimpleData::getMerchantDetails(),
'addendums' => SimpleData::getAddEndUms(),
'currencyConversion'=> SimpleData::getCurrencyConversion(),
];

$response = $this->service->openOrder($params);
$this->assertContains('orderId', $response);
return $response['orderId'];
$this->assertEquals('SUCCESS', $response['status']);
}

/**
Expand Down Expand Up @@ -276,4 +279,61 @@ public function testGetPaymentStatus()
$response = $this->service->getPaymentStatus($params);
$this->assertEquals('SUCCESS', $response['status']);
}

/**
* @return mixed
* @throws ConnectionException
* @throws ResponseException
* @throws ValidationException
* @run ./vendor/phpunit/phpunit/phpunit --filter testGetCardDetails ./tests/PaymentServiceTest.php
*/
public function testGetCardDetails()
{
$params = [
'cardNumber' => SimpleData::getCardNumber()
];

$response = $this->service->getCardDetails($params);
$this->assertEquals('SUCCESS', $response['status']);
}

/**
* @return mixed
* @throws ConnectionException
* @throws ResponseException
* @throws ValidationException
* @run ./vendor/phpunit/phpunit/phpunit --filter testGetMcpRates ./tests/PaymentServiceTest.php
*/
public function testGetMcpRates()
{
$params = [
'fromCurrency' => SimpleData::getCurrency()
];

$response = $this->service->getMcpRates($params);
$this->assertEquals('SUCCESS', $response['status']);
}

/**
* @return mixed
* @throws ConnectionException
* @throws ResponseException
* @throws ValidationException
* @run ./vendor/phpunit/phpunit/phpunit --filter testGetDccDetails ./tests/PaymentServiceTest.php
*/
public function testGetDccDetails()
{
$params = [
'clientRequestId' => '100',
'clientUniqueId' => '12345',
"apm" => "apmgw_expresscheckout",
'amount' => '10',
'originalAmount' => '15',
'originalCurrency' => 'GBP',
'currency' => 'EUR',
];

$response = $this->service->getDccDetails($params);
$this->assertEquals('SUCCESS', $response['status']);
}
}
13 changes: 13 additions & 0 deletions tests/SimpleData.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ public static function getAmount()
return "10";
}

public static function getCurrencyConversion()
{
return [
'originalAmount' => "10",
'originalCurrency' => "USD"
];
}

public static function getAmountDetails()
{
return [
Expand Down Expand Up @@ -129,6 +137,11 @@ public static function getDynamicDescriptor()
];
}

public static function getCardNumber()
{
return '4012001037141112';
}

public static function getCardData($cardNumber = false, $ccTempToken = false)
{
if ($cardNumber === false) {
Expand Down

0 comments on commit 4c0ad87

Please sign in to comment.