From e7f8f3271c82cf4e2c5a8f9b9d9078d2913d2ca2 Mon Sep 17 00:00:00 2001 From: Emil Georgiev Date: Wed, 29 Nov 2017 14:29:53 +0200 Subject: [PATCH] Added county parameter to UnitTests Added county to checksum of createUser --- .../Api/Service/Payments/CreditCard.php | 2 +- .../Api/Service/Payments/Payout.php | 76 +++++++++++++++++++ .../Api/Service/UserPaymentOptions.php | 14 ++++ .../Api/Service/UsersManagement.php | 2 + src/SafeCharge/Api/Utils.php | 12 +++ tests/AlternativePaymentMethodTest.php | 2 +- tests/CreditCardTest.php | 4 +- tests/OrdersManagementTest.php | 4 +- tests/PayoutTest.php | 61 +++++++++++++++ tests/RefundTest.php | 2 +- tests/SettleTest.php | 2 +- tests/SimpleData.php | 9 ++- tests/TestCaseHelper.php | 22 +++++- tests/ThreeDsecureTest.php | 2 +- tests/UsersManagementTest.php | 2 + tests/VoidTest.php | 2 +- 16 files changed, 204 insertions(+), 14 deletions(-) create mode 100644 src/SafeCharge/Api/Service/Payments/Payout.php create mode 100644 tests/PayoutTest.php diff --git a/src/SafeCharge/Api/Service/Payments/CreditCard.php b/src/SafeCharge/Api/Service/Payments/CreditCard.php index d5de417..fe52408 100644 --- a/src/SafeCharge/Api/Service/Payments/CreditCard.php +++ b/src/SafeCharge/Api/Service/Payments/CreditCard.php @@ -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']; diff --git a/src/SafeCharge/Api/Service/Payments/Payout.php b/src/SafeCharge/Api/Service/Payments/Payout.php new file mode 100644 index 0000000..a4c7b1d --- /dev/null +++ b/src/SafeCharge/Api/Service/Payments/Payout.php @@ -0,0 +1,76 @@ +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'); + } + + +} \ No newline at end of file diff --git a/src/SafeCharge/Api/Service/UserPaymentOptions.php b/src/SafeCharge/Api/Service/UserPaymentOptions.php index 84b648f..b763f14 100644 --- a/src/SafeCharge/Api/Service/UserPaymentOptions.php +++ b/src/SafeCharge/Api/Service/UserPaymentOptions.php @@ -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 diff --git a/src/SafeCharge/Api/Service/UsersManagement.php b/src/SafeCharge/Api/Service/UsersManagement.php index 29b9135..b04f6d1 100644 --- a/src/SafeCharge/Api/Service/UsersManagement.php +++ b/src/SafeCharge/Api/Service/UsersManagement.php @@ -41,6 +41,7 @@ public function createUser(array $params) 'phone', 'locale', 'email', + 'county', 'timeStamp', 'merchantSecretKey' ]; @@ -80,6 +81,7 @@ public function updateUser(array $params) 'phone', 'locale', 'email', + 'county', 'timeStamp', 'merchantSecretKey' ]; diff --git a/src/SafeCharge/Api/Utils.php b/src/SafeCharge/Api/Utils.php index 11b25a9..b2591ca 100644 --- a/src/SafeCharge/Api/Utils.php +++ b/src/SafeCharge/Api/Utils.php @@ -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]); + } + } + } \ No newline at end of file diff --git a/tests/AlternativePaymentMethodTest.php b/tests/AlternativePaymentMethodTest.php index 63494a2..68def65 100644 --- a/tests/AlternativePaymentMethodTest.php +++ b/tests/AlternativePaymentMethodTest.php @@ -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(), diff --git a/tests/CreditCardTest.php b/tests/CreditCardTest.php index ab58bda..e238147 100644 --- a/tests/CreditCardTest.php +++ b/tests/CreditCardTest.php @@ -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; @@ -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(), diff --git a/tests/OrdersManagementTest.php b/tests/OrdersManagementTest.php index 436b1b7..ccd781f 100644 --- a/tests/OrdersManagementTest.php +++ b/tests/OrdersManagementTest.php @@ -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(), @@ -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(), diff --git a/tests/PayoutTest.php b/tests/PayoutTest.php new file mode 100644 index 0000000..cd13ddc --- /dev/null +++ b/tests/PayoutTest.php @@ -0,0 +1,61 @@ +_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']); + } + +} diff --git a/tests/RefundTest.php b/tests/RefundTest.php index bca8cc9..7476df6 100644 --- a/tests/RefundTest.php +++ b/tests/RefundTest.php @@ -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', diff --git a/tests/SettleTest.php b/tests/SettleTest.php index e082068..cb86d18 100644 --- a/tests/SettleTest.php +++ b/tests/SettleTest.php @@ -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', diff --git a/tests/SimpleData.php b/tests/SimpleData.php index cca385d..29516f8 100644 --- a/tests/SimpleData.php +++ b/tests/SimpleData.php @@ -7,6 +7,11 @@ class SimpleData { + public static function getCurrency() + { + return 'EUR'; + } + public static function getAmountDetails() { return [ @@ -85,8 +90,8 @@ public static function getBillingAddress($addCountryCode = false) "city" => "some city", $countryParameter => "US", "state" => "AK", - "county" => "Anchorage", "email" => "someemail@somedomain.com", + "county" => "Anchorage", ]; } @@ -115,7 +120,7 @@ public static function getDynamicDescriptor() { return [ "merchantName" => "merchantName", - "merchantPhone" => "merchantPhone" + "merchantPhone" => "+4412378" ]; } diff --git a/tests/TestCaseHelper.php b/tests/TestCaseHelper.php index f6ef5b9..410a6bb 100644 --- a/tests/TestCaseHelper.php +++ b/tests/TestCaseHelper.php @@ -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 @@ -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(), @@ -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(), @@ -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']; + } + } \ No newline at end of file diff --git a/tests/ThreeDsecureTest.php b/tests/ThreeDsecureTest.php index cf62590..601b9ca 100644 --- a/tests/ThreeDsecureTest.php +++ b/tests/ThreeDsecureTest.php @@ -52,7 +52,7 @@ public function getExampleData() 'clientUniqueId' => '12345', 'clientRequestId' => '1484759782197', 'isDynamic3D' => '0', - 'currency' => 'EUR', + 'currency' => SimpleData::getCurrency(), 'amount' => "5000", 'amountDetails' => SimpleData::getAmountDetails(), 'items' => [ diff --git a/tests/UsersManagementTest.php b/tests/UsersManagementTest.php index 7bdeb69..cf44a14 100644 --- a/tests/UsersManagementTest.php +++ b/tests/UsersManagementTest.php @@ -26,6 +26,7 @@ public function testCreateUser() 'city' => '', 'zip' => '', 'countryCode' => 'GB', + 'county' => 'Anchorage', 'phone' => '', 'locale' => 'en_UK', 'email' => 'john.smith@test.com', @@ -53,6 +54,7 @@ public function testUpdateUser($userTokenId) 'city' => 'London', 'zip' => '', 'countryCode' => 'GB', + 'county' => 'Anchorage', 'phone' => '', 'locale' => 'en_UK', 'email' => 'john.smith@test.com', diff --git a/tests/VoidTest.php b/tests/VoidTest.php index f9aca7b..2b4ce96 100644 --- a/tests/VoidTest.php +++ b/tests/VoidTest.php @@ -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',