Skip to content

Commit

Permalink
Added county parameter to UnitTests
Browse files Browse the repository at this point in the history
Added county to checksum of createUser
  • Loading branch information
emog committed Nov 29, 2017
1 parent 4efdddd commit e7f8f32
Show file tree
Hide file tree
Showing 16 changed files with 204 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/SafeCharge/Api/Service/Payments/CreditCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function cardTokenization(array $params)
*/
public function paymentCC(array $params)
{
$mandatoryFields = ['sessionToken', 'merchantId', 'merchantSiteId', 'transactionType', 'isRebilling', 'currency', 'amount', 'items', 'timeStamp', 'checksum'];
$mandatoryFields = ['sessionToken', 'merchantId', 'merchantSiteId', 'transactionType', 'isRebilling', 'currency', 'amount','amountDetails', 'items', 'timeStamp', 'checksum'];

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

Expand Down
76 changes: 76 additions & 0 deletions src/SafeCharge/Api/Service/Payments/Payout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
/**
* MIT License
*
* Copyright (c) 2017 Safecharge Bulgaria ltd
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

namespace SafeCharge\Api\Service\Payments;

use SafeCharge\Api\RestClient;
use SafeCharge\Api\Service\BaseService;
use SafeCharge\Api\Utils;


class Payout extends BaseService
{

/**
* Payout constructor.
* @param RestClient $client
*/
public function __construct(RestClient $client)
{
parent::__construct($client);
}

/**
* @param array $params
* @return mixed
* @link https://www.safecharge.com/docs/API/#payout
*/
public function payout(array $params)
{
$mandatoryFields = ['merchantId', 'merchantSiteId', 'currency', 'amount', 'timeStamp', 'checksum'];

$checksumParametersOrder = [
'merchantId',
'merchantSiteId',
'clientRequestId',
'amount',
'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, 'payout.do');
}


}
14 changes: 14 additions & 0 deletions src/SafeCharge/Api/Service/UserPaymentOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@
class UserPaymentOptions extends BaseService
{

private $commonBillingAddressCheckSumOrder = [
'firstName',
'lastName',
'address',
'phone',
'zip',
'city',
'countryCode',
'state',
'email',
'county'

];

/**
* UserPaymentOptions constructor.
* @param RestClient $client
Expand Down
2 changes: 2 additions & 0 deletions src/SafeCharge/Api/Service/UsersManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function createUser(array $params)
'phone',
'locale',
'email',
'county',
'timeStamp',
'merchantSecretKey'
];
Expand Down Expand Up @@ -80,6 +81,7 @@ public function updateUser(array $params)
'phone',
'locale',
'email',
'county',
'timeStamp',
'merchantSecretKey'
];
Expand Down
12 changes: 12 additions & 0 deletions src/SafeCharge/Api/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,16 @@ public static function arrayToString($array)
return $string;
}

/**
* @param $element
* @param $array
*/
public static function removeElementFromArray($element, &$array)
{
$index = array_search($element, $array);
if ($index !== false) {
unset($array[$index]);
}
}

}
2 changes: 1 addition & 1 deletion tests/AlternativePaymentMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function testPaymentAPM()
'userTokenId' => TestCaseHelper::getUserTokenId(),
'clientUniqueId' => '12345',
'clientRequestId' => '1484759782197',
'currency' => 'EUR',
'currency' => SimpleData::getCurrency(),
'amount' => "10",
'amountDetails' => SimpleData::getAmountDetails(),
'items' => SimpleData::getItems(),
Expand Down
4 changes: 2 additions & 2 deletions tests/CreditCardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function testPaymentCCWithCard()
public function testPaymentCCWithOrderIdAndCard()
{
//TestCaseHelper::openOrderAndReturnOrderId() will create a new sessionToken
$orderId = TestCaseHelper::openOrderAndReturnOrderId();
$orderId = TestCaseHelper::openOrderAndReturnOrderId();
$params = $this->getExampleData();
$params['cardData'] = SimpleData::getCarData();
$params['orderId'] = $orderId;
Expand All @@ -75,7 +75,7 @@ public function getExampleData()
'transactionType' => 'Auth',
'isRebilling' => '0',
'isPartialApproval' => '0',
'currency' => 'EUR',
'currency' => SimpleData::getCurrency(),
'amount' => "10",
'amountDetails' => SimpleData::getAmountDetails(),
'items' => SimpleData::getItems(),
Expand Down
4 changes: 2 additions & 2 deletions tests/OrdersManagementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testOpenOrder()
'userTokenId' => TestCaseHelper::getUserTokenId(),
'clientUniqueId' => '',
'clientRequestId' => '',
'currency' => 'USD',
'currency' => SimpleData::getCurrency(),
'amount' => "10",
'amountDetails' => SimpleData::getAmountDetails(),
'items' => SimpleData::getItems(),
Expand Down Expand Up @@ -51,7 +51,7 @@ public function testUpdateOrder($orderId)
"orderId" => $orderId,
'clientUniqueId' => '',
'clientRequestId' => '',
'currency' => 'USD',
'currency' => SimpleData::getCurrency(),
'amount' => "10",
'amountDetails' => SimpleData::getAmountDetails(),
'items' => SimpleData::getItems(),
Expand Down
61 changes: 61 additions & 0 deletions tests/PayoutTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
* MIT License
*
* Copyright (c) 2017 Safecharge Bulgaria ltd
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

namespace SafeCharge\Tests;

use SafeCharge\Api\Service\Payments\Payout;

class PayoutTest extends \PHPUnit_Framework_TestCase
{
private $_service;

public function __construct()
{
$this->_service = new Payout(TestCaseHelper::getClient());
}

public function testPayout()
{
$params = [
'userTokenId' => TestCaseHelper::getUserTokenId(),
'clientRequestId' => '100',
'clientUniqueId' => '12345',
'amount' => "9.0",
'currency' => SimpleData::getCurrency(),
'dynamicDescriptor' => SimpleData::getDynamicDescriptor(),
'merchantDetails' => SimpleData::getMerchantDetails(),
'userPaymentOption' => [
'userPaymentOptionId' => TestCaseHelper::getUPOCreditCardId(),
'CVV' => '234'
],
'comment' => 'some comment',
'urlDetails' => SimpleData::getUrlDetails(true),
];

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

}
2 changes: 1 addition & 1 deletion tests/RefundTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function testRefundTransaction()
'clientRequestId' => '100',
'clientUniqueId' => '12345',
'amount' => 10,
'currency' => 'EUR',
'currency' => SimpleData::getCurrency(),
'relatedTransactionId' => $transactionData['transactionId'],
'authCode' => $transactionData['authCode'],
'comment' => 'some comment',
Expand Down
2 changes: 1 addition & 1 deletion tests/SettleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testSettleTransaction()
'clientRequestId' => '100',
'clientUniqueId' => '12345',
'amount' => "9.0",
'currency' => 'EUR',
'currency' => SimpleData::getCurrency(),
'relatedTransactionId' => $transactionData['transactionId'],
'authCode' => $transactionData['authCode'],
'descriptorMerchantName' => 'Name',
Expand Down
9 changes: 7 additions & 2 deletions tests/SimpleData.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
class SimpleData
{

public static function getCurrency()
{
return 'EUR';
}

public static function getAmountDetails()
{
return [
Expand Down Expand Up @@ -85,8 +90,8 @@ public static function getBillingAddress($addCountryCode = false)
"city" => "some city",
$countryParameter => "US",
"state" => "AK",
"county" => "Anchorage",
"email" => "[email protected]",
"county" => "Anchorage",
];
}

Expand Down Expand Up @@ -115,7 +120,7 @@ public static function getDynamicDescriptor()
{
return [
"merchantName" => "merchantName",
"merchantPhone" => "merchantPhone"
"merchantPhone" => "+4412378"
];
}

Expand Down
22 changes: 20 additions & 2 deletions tests/TestCaseHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use SafeCharge\Api\Service\AuthenticationManagement;
use SafeCharge\Api\Service\OrdersManagement;
use SafeCharge\Api\Service\Payments\CreditCard;
use SafeCharge\Api\Service\UserPaymentOptions;
use SafeCharge\Api\Service\UsersManagement;

class TestCaseHelper extends \PHPUnit_Framework_TestCase
Expand Down Expand Up @@ -105,7 +106,7 @@ public static function createAndReturnTransaction($amount = 10, $isAuth = false)
'transactionType' => $isAuth ? 'Auth' : 'Sale',
'isRebilling' => '0',
'isPartialApproval' => '0',
'currency' => 'EUR',
'currency' => SimpleData::getCurrency(),
'amount' => $amount,
'amountDetails' => SimpleData::getAmountDetails(),
'items' => SimpleData::getItems(),
Expand Down Expand Up @@ -141,7 +142,7 @@ public static function openOrderAndReturnOrderId()
'userTokenId' => TestCaseHelper::getUserTokenId(),
'clientUniqueId' => '',
'clientRequestId' => '',
'currency' => 'USD',
'currency' => SimpleData::getCurrency(),
'amount' => "10",
'amountDetails' => SimpleData::getAmountDetails(),
'items' => SimpleData::getItems(),
Expand All @@ -158,4 +159,21 @@ public static function openOrderAndReturnOrderId()
return $response['orderId'];
}

public static function getUPOCreditCardId()
{
$service = new UserPaymentOptions(self::getClient());

$cardData = SimpleData::getCarData();
$params = [
'userTokenId' => TestCaseHelper::getUserTokenId(),
'clientRequestId' => '235',
'ccCardNumber' => $cardData['cardNumber'],
'ccExpMonth' => $cardData['expirationMonth'],
'ccExpYear' => $cardData['expirationYear'],
'ccNameOnCard' => $cardData['cardHolderName'],
];
$response = $service->addUPOCreditCard($params);
return $response['userPaymentOptionId'];
}

}
2 changes: 1 addition & 1 deletion tests/ThreeDsecureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function getExampleData()
'clientUniqueId' => '12345',
'clientRequestId' => '1484759782197',
'isDynamic3D' => '0',
'currency' => 'EUR',
'currency' => SimpleData::getCurrency(),
'amount' => "5000",
'amountDetails' => SimpleData::getAmountDetails(),
'items' => [
Expand Down
2 changes: 2 additions & 0 deletions tests/UsersManagementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function testCreateUser()
'city' => '',
'zip' => '',
'countryCode' => 'GB',
'county' => 'Anchorage',
'phone' => '',
'locale' => 'en_UK',
'email' => '[email protected]',
Expand Down Expand Up @@ -53,6 +54,7 @@ public function testUpdateUser($userTokenId)
'city' => 'London',
'zip' => '',
'countryCode' => 'GB',
'county' => 'Anchorage',
'phone' => '',
'locale' => 'en_UK',
'email' => '[email protected]',
Expand Down
2 changes: 1 addition & 1 deletion tests/VoidTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testVoidTransaction()
'clientRequestId' => '100',
'clientUniqueId' => '12345',
'amount' => "9.0",
'currency' => 'EUR',
'currency' => SimpleData::getCurrency(),
'relatedTransactionId' => $transactionData['transactionId'],
'authCode' => $transactionData['authCode'],
'descriptorMerchantName' => 'Name',
Expand Down

0 comments on commit e7f8f32

Please sign in to comment.