From b7ed069d9ef282d2137d65c8b5245ef96d4f6b9a Mon Sep 17 00:00:00 2001 From: bradleybrecher Date: Fri, 19 Jul 2019 17:18:18 -0400 Subject: [PATCH 01/10] Comment out shipping address setters since paypal doesn't provide shipping info --- app/code/Magento/Paypal/Model/Express/Checkout.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Paypal/Model/Express/Checkout.php b/app/code/Magento/Paypal/Model/Express/Checkout.php index 72f166e8d07c1..500baa53e4a38 100644 --- a/app/code/Magento/Paypal/Model/Express/Checkout.php +++ b/app/code/Magento/Paypal/Model/Express/Checkout.php @@ -632,12 +632,12 @@ public function returnFromPaypal($token, string $payerIdentifier = null) if ($exportedShippingAddress && $isButton) { $this->_setExportedAddressData($shippingAddress, $exportedShippingAddress); // PayPal doesn't provide detailed shipping info: prefix, middlename, lastname, suffix - $shippingAddress->setPrefix(null); - $shippingAddress->setMiddlename(null); - $shippingAddress->setLastname(null); - $shippingAddress->setSuffix(null); - $shippingAddress->setCollectShippingRates(true); - $shippingAddress->setSameAsBilling(0); +// $shippingAddress->setPrefix(null); +// $shippingAddress->setMiddlename(null); +// $shippingAddress->setLastname(null); +// $shippingAddress->setSuffix(null); +// $shippingAddress->setCollectShippingRates(true); +// $shippingAddress->setSameAsBilling(0); } // import shipping method From 20ec6cc6226c1068de4a43c0b1ac1700a7b71e28 Mon Sep 17 00:00:00 2001 From: bradleybrecher Date: Fri, 19 Jul 2019 17:19:55 -0400 Subject: [PATCH 02/10] Split up SHIPTONAME recieved from Paypal into first and last name --- app/code/Magento/Paypal/Model/Api/Nvp.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Paypal/Model/Api/Nvp.php b/app/code/Magento/Paypal/Model/Api/Nvp.php index 624068395394d..e2284bc2fc74b 100644 --- a/app/code/Magento/Paypal/Model/Api/Nvp.php +++ b/app/code/Magento/Paypal/Model/Api/Nvp.php @@ -1488,7 +1488,18 @@ protected function _exportAddresses($data) \Magento\Framework\DataObject\Mapper::accumulateByMap($data, $shippingAddress, $this->_shippingAddressMap); $this->_applyStreetAndRegionWorkarounds($shippingAddress); // PayPal doesn't provide detailed shipping name fields, so the name will be overwritten - $shippingAddress->addData(['firstname' => $data['SHIPTONAME']]); + $_arraydata = explode(' ', $data['SHIPTONAME'], 2); + if (!empty($_arraydata[0]) && !empty($_arraydata[1])) { + $shippingAddress->addData(array( + 'firstname' => $_arraydata[0], + 'lastname' => $_arraydata[1] + )); + } else { + $shippingAddress->addData(array( + 'firstname' => $data['FIRSTNAME'], + 'lastname' => $data['LASTNAME'] + )); + } $this->setExportedShippingAddress($shippingAddress); } } From 171ce10d1bd3d3d6a7072f5a3be814757e0c270c Mon Sep 17 00:00:00 2001 From: bradleybrecher Date: Tue, 23 Jul 2019 14:06:13 -0400 Subject: [PATCH 03/10] Delete commented out code --- app/code/Magento/Paypal/Model/Express/Checkout.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/app/code/Magento/Paypal/Model/Express/Checkout.php b/app/code/Magento/Paypal/Model/Express/Checkout.php index 500baa53e4a38..b42c26a9cda17 100644 --- a/app/code/Magento/Paypal/Model/Express/Checkout.php +++ b/app/code/Magento/Paypal/Model/Express/Checkout.php @@ -632,12 +632,6 @@ public function returnFromPaypal($token, string $payerIdentifier = null) if ($exportedShippingAddress && $isButton) { $this->_setExportedAddressData($shippingAddress, $exportedShippingAddress); // PayPal doesn't provide detailed shipping info: prefix, middlename, lastname, suffix -// $shippingAddress->setPrefix(null); -// $shippingAddress->setMiddlename(null); -// $shippingAddress->setLastname(null); -// $shippingAddress->setSuffix(null); -// $shippingAddress->setCollectShippingRates(true); -// $shippingAddress->setSameAsBilling(0); } // import shipping method From 8c88936245e49567ae08bf8ca5d987d7cdeaaabe Mon Sep 17 00:00:00 2001 From: bradleybrecher Date: Tue, 23 Jul 2019 14:56:29 -0400 Subject: [PATCH 04/10] Set the edge case for when there is more than one first and/or last name --- app/code/Magento/Paypal/Model/Api/Nvp.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Paypal/Model/Api/Nvp.php b/app/code/Magento/Paypal/Model/Api/Nvp.php index e2284bc2fc74b..88f7ffbca8251 100644 --- a/app/code/Magento/Paypal/Model/Api/Nvp.php +++ b/app/code/Magento/Paypal/Model/Api/Nvp.php @@ -1488,7 +1488,13 @@ protected function _exportAddresses($data) \Magento\Framework\DataObject\Mapper::accumulateByMap($data, $shippingAddress, $this->_shippingAddressMap); $this->_applyStreetAndRegionWorkarounds($shippingAddress); // PayPal doesn't provide detailed shipping name fields, so the name will be overwritten - $_arraydata = explode(' ', $data['SHIPTONAME'], 2); + $_arraydata = explode(' ', $data['SHIPTONAME']); + // when there is more than one first and/or last name, we assume that the last word in the string is the last name + if(count($_arraydata) > 2){ + $lastname = array_pop($_arraydata); + $firstname = join(' ', $_arraydata); + $_arraydata = array($firstname,$lastname); + } if (!empty($_arraydata[0]) && !empty($_arraydata[1])) { $shippingAddress->addData(array( 'firstname' => $_arraydata[0], From 591a1aeb3a18b657f350ef3064a525a82994b743 Mon Sep 17 00:00:00 2001 From: bradleybrecher Date: Wed, 24 Jul 2019 09:20:53 -0400 Subject: [PATCH 05/10] Syntax fixes to array and implode function --- app/code/Magento/Paypal/Model/Api/Nvp.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/Paypal/Model/Api/Nvp.php b/app/code/Magento/Paypal/Model/Api/Nvp.php index 88f7ffbca8251..601a1a6fa408f 100644 --- a/app/code/Magento/Paypal/Model/Api/Nvp.php +++ b/app/code/Magento/Paypal/Model/Api/Nvp.php @@ -1488,17 +1488,17 @@ protected function _exportAddresses($data) \Magento\Framework\DataObject\Mapper::accumulateByMap($data, $shippingAddress, $this->_shippingAddressMap); $this->_applyStreetAndRegionWorkarounds($shippingAddress); // PayPal doesn't provide detailed shipping name fields, so the name will be overwritten - $_arraydata = explode(' ', $data['SHIPTONAME']); + $nameParts = explode(' ', $data['SHIPTONAME']); // when there is more than one first and/or last name, we assume that the last word in the string is the last name - if(count($_arraydata) > 2){ - $lastname = array_pop($_arraydata); - $firstname = join(' ', $_arraydata); - $_arraydata = array($firstname,$lastname); + if(count($nameParts) > 2){ + $lastname = array_pop($nameParts); + $firstname = implode(' ', $nameParts); + $nameParts = [$firstname, $lastname]; } - if (!empty($_arraydata[0]) && !empty($_arraydata[1])) { + if (!empty($nameParts[0]) && !empty($nameParts[1])) { $shippingAddress->addData(array( - 'firstname' => $_arraydata[0], - 'lastname' => $_arraydata[1] + 'firstname' => $nameParts[0], + 'lastname' => $nameParts[1] )); } else { $shippingAddress->addData(array( From ca16634b40099479a50a6d1bac4487ab5f72f46a Mon Sep 17 00:00:00 2001 From: bradleybrecher Date: Thu, 25 Jul 2019 11:54:02 -0400 Subject: [PATCH 06/10] Fix PHP Code Sniffer Violations --- app/code/Magento/Paypal/Model/Api/Nvp.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Paypal/Model/Api/Nvp.php b/app/code/Magento/Paypal/Model/Api/Nvp.php index 601a1a6fa408f..57f8945b24b64 100644 --- a/app/code/Magento/Paypal/Model/Api/Nvp.php +++ b/app/code/Magento/Paypal/Model/Api/Nvp.php @@ -1490,21 +1490,21 @@ protected function _exportAddresses($data) // PayPal doesn't provide detailed shipping name fields, so the name will be overwritten $nameParts = explode(' ', $data['SHIPTONAME']); // when there is more than one first and/or last name, we assume that the last word in the string is the last name - if(count($nameParts) > 2){ + if (count($nameParts) > 2) { $lastname = array_pop($nameParts); $firstname = implode(' ', $nameParts); $nameParts = [$firstname, $lastname]; } if (!empty($nameParts[0]) && !empty($nameParts[1])) { - $shippingAddress->addData(array( + $shippingAddress->addData([ 'firstname' => $nameParts[0], 'lastname' => $nameParts[1] - )); + ]); } else { - $shippingAddress->addData(array( + $shippingAddress->addData([ 'firstname' => $data['FIRSTNAME'], 'lastname' => $data['LASTNAME'] - )); + ]); } $this->setExportedShippingAddress($shippingAddress); } From 57e762abbc9fbd81f3787faaad15ce0b2830be7f Mon Sep 17 00:00:00 2001 From: bradleybrecher Date: Thu, 1 Aug 2019 10:21:45 -0400 Subject: [PATCH 07/10] Remove integration test to check if lastname is null since there is now a lastname --- .../testsuite/Magento/Paypal/Model/Express/CheckoutTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/dev/tests/integration/testsuite/Magento/Paypal/Model/Express/CheckoutTest.php b/dev/tests/integration/testsuite/Magento/Paypal/Model/Express/CheckoutTest.php index 3f7f8719fd587..8d6e4dbf30ae5 100644 --- a/dev/tests/integration/testsuite/Magento/Paypal/Model/Express/CheckoutTest.php +++ b/dev/tests/integration/testsuite/Magento/Paypal/Model/Express/CheckoutTest.php @@ -278,7 +278,6 @@ public function testReturnFromPaypal() $this->assertTrue((bool)$shippingAddress->getSameAsBilling()); $this->assertNull($shippingAddress->getPrefix()); $this->assertNull($shippingAddress->getMiddlename()); - $this->assertNull($shippingAddress->getLastname()); $this->assertNull($shippingAddress->getSuffix()); $this->assertTrue($shippingAddress->getShouldIgnoreValidation()); $this->assertContains('exported', $shippingAddress->getFirstname()); From 1f1f010f57a42764df417e0fcbc12866fdd1f621 Mon Sep 17 00:00:00 2001 From: bradleybrecher Date: Thu, 1 Aug 2019 10:37:00 -0400 Subject: [PATCH 08/10] Update test to test whether the fullname is equal to the firstname + last:name --- app/code/Magento/Paypal/Test/Unit/Model/Api/NvpTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Paypal/Test/Unit/Model/Api/NvpTest.php b/app/code/Magento/Paypal/Test/Unit/Model/Api/NvpTest.php index fcc7766ec298b..d58b9ec9bdd5b 100644 --- a/app/code/Magento/Paypal/Test/Unit/Model/Api/NvpTest.php +++ b/app/code/Magento/Paypal/Test/Unit/Model/Api/NvpTest.php @@ -199,7 +199,7 @@ public function testCallGetExpressCheckoutDetails() )); $this->model->callGetExpressCheckoutDetails(); $address = $this->model->getExportedShippingAddress(); - $this->assertEquals('Ship To Name', $address->getData('firstname')); + $this->assertEquals('Ship To Name', ($address->getData('firstname') . " " . $address->getData('lastname'))); $this->assertEquals(implode("\n", ['testStreet','testApartment']), $address->getStreet()); $this->assertEquals('testCompany', $address->getCompany()); $this->assertEquals('testCity', $address->getCity()); From 7938e614f4a4c192c1c2871e99bf73223f4b828e Mon Sep 17 00:00:00 2001 From: bradleybrecher Date: Thu, 1 Aug 2019 15:07:59 -0400 Subject: [PATCH 09/10] PHP Code Sniffer violations fix using PHPCBF --- app/code/Magento/Paypal/Model/Api/Nvp.php | 260 +++++++++--------- .../Magento/Paypal/Model/Express/Checkout.php | 172 ++++++------ .../Magento/Paypal/Model/Api/NvpTest.php | 4 +- 3 files changed, 226 insertions(+), 210 deletions(-) diff --git a/app/code/Magento/Paypal/Model/Api/Nvp.php b/app/code/Magento/Paypal/Model/Api/Nvp.php index 57f8945b24b64..b7d8f2927b749 100644 --- a/app/code/Magento/Paypal/Model/Api/Nvp.php +++ b/app/code/Magento/Paypal/Model/Api/Nvp.php @@ -11,9 +11,10 @@ /** * NVP API wrappers model + * * @TODO: move some parts to abstract, don't hesitate to throw exceptions on api calls * - * @method string getToken() + * @method string getToken() * @SuppressWarnings(PHPMD.TooManyFields) * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -476,6 +477,7 @@ class Nvp extends \Magento\Paypal\Model\Api\AbstractApi /** * Map for shipping address import/export (extends billing address mapper) + * * @var array */ protected $_shippingAddressMap = [ @@ -491,6 +493,7 @@ class Nvp extends \Magento\Paypal\Model\Api\AbstractApi /** * Map for callback request + * * @var array */ protected $_callbackRequestMap = [ @@ -504,6 +507,7 @@ class Nvp extends \Magento\Paypal\Model\Api\AbstractApi /** * Payment information response specifically to be collected after some requests + * * @var string[] */ protected $_paymentInformationResponse = [ @@ -523,6 +527,7 @@ class Nvp extends \Magento\Paypal\Model\Api\AbstractApi /** * Line items export mapping settings + * * @var array */ protected $_lineItemTotalExportMap = [ @@ -533,6 +538,7 @@ class Nvp extends \Magento\Paypal\Model\Api\AbstractApi /** * Line items export mapping settings + * * @var array */ protected $_lineItemExportItemsFormat = [ @@ -544,6 +550,7 @@ class Nvp extends \Magento\Paypal\Model\Api\AbstractApi /** * Shipping options export to request mapping settings + * * @var array */ protected $_shippingOptionsExportItemsFormat = [ @@ -737,16 +744,16 @@ class Nvp extends \Magento\Paypal\Model\Api\AbstractApi protected $_headers = []; /** - * @param \Magento\Customer\Helper\Address $customerAddress - * @param \Psr\Log\LoggerInterface $logger - * @param Logger $customLogger - * @param \Magento\Framework\Locale\ResolverInterface $localeResolver - * @param \Magento\Directory\Model\RegionFactory $regionFactory - * @param \Magento\Directory\Model\CountryFactory $countryFactory - * @param ProcessableExceptionFactory $processableExceptionFactory - * @param \Magento\Framework\Exception\LocalizedExceptionFactory $frameworkExceptionFactory - * @param \Magento\Framework\HTTP\Adapter\CurlFactory $curlFactory - * @param array $data + * @param \Magento\Customer\Helper\Address $customerAddress + * @param \Psr\Log\LoggerInterface $logger + * @param Logger $customLogger + * @param \Magento\Framework\Locale\ResolverInterface $localeResolver + * @param \Magento\Directory\Model\RegionFactory $regionFactory + * @param \Magento\Directory\Model\CountryFactory $countryFactory + * @param ProcessableExceptionFactory $processableExceptionFactory + * @param \Magento\Framework\Exception\LocalizedExceptionFactory $frameworkExceptionFactory + * @param \Magento\Framework\HTTP\Adapter\CurlFactory $curlFactory + * @param array $data * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -805,7 +812,7 @@ public function getBillingAgreementType() * TODO: put together style and giropay settings * * @return void - * @link https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_SetExpressCheckout + * @link https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_SetExpressCheckout */ public function callSetExpressCheckout() { @@ -836,7 +843,7 @@ public function callSetExpressCheckout() * GetExpressCheckoutDetails call * * @return void - * @link https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_GetExpressCheckoutDetails + * @link https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_GetExpressCheckoutDetails */ public function callGetExpressCheckoutDetails() { @@ -851,7 +858,7 @@ public function callGetExpressCheckoutDetails() * DoExpressCheckout call * * @return void - * @link https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_DoExpressCheckoutPayment + * @link https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_DoExpressCheckoutPayment */ public function callDoExpressCheckoutPayment() { @@ -890,7 +897,7 @@ public function callDoDirectPayment() * Do Reference Transaction call * * @return void - * @link https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_DoReferenceTransaction + * @link https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_DoReferenceTransaction */ public function callDoReferenceTransaction() { @@ -903,7 +910,7 @@ public function callDoReferenceTransaction() /** * Check whether the last call was returned with fraud warning * - * @return bool + * @return bool * @SuppressWarnings(PHPMD.BooleanGetMethodName) */ public function getIsFraudDetected() @@ -927,7 +934,7 @@ public function callDoReauthorization() * DoCapture call * * @return void - * @link https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_DoCapture + * @link https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_DoCapture */ public function callDoCapture() { @@ -942,7 +949,7 @@ public function callDoCapture() * DoAuthorization call * * @return $this - * @link https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_DoAuthorization + * @link https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_DoAuthorization */ public function callDoAuthorization() { @@ -958,7 +965,7 @@ public function callDoAuthorization() * DoVoid call * * @return void - * @link https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_DoVoid + * @link https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_DoVoid */ public function callDoVoid() { @@ -970,7 +977,7 @@ public function callDoVoid() * GetTransactionDetails * * @return void - * @link https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_GetTransactionDetails + * @link https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_GetTransactionDetails */ public function callGetTransactionDetails() { @@ -983,7 +990,7 @@ public function callGetTransactionDetails() * RefundTransaction call * * @return void - * @link https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_RefundTransaction + * @link https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_RefundTransaction */ public function callRefundTransaction() { @@ -999,7 +1006,7 @@ public function callRefundTransaction() * ManagePendingTransactionStatus * * @return void - * @link https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_ManagePendingTransactionStatus + * @link https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_ManagePendingTransactionStatus */ public function callManagePendingTransactionStatus() { @@ -1015,8 +1022,8 @@ public function callManagePendingTransactionStatus() * GetPalDetails call * * @return void - * @link https://www.x.com/docs/DOC-1300 - * @link https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_ECButtonIntegration + * @link https://www.x.com/docs/DOC-1300 + * @link https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_ECButtonIntegration */ public function callGetPalDetails() { @@ -1028,7 +1035,7 @@ public function callGetPalDetails() * Set Customer BillingAgreement call * * @return void - * @link https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_SetCustomerBillingAgreement + * @link https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_SetCustomerBillingAgreement */ public function callSetCustomerBillingAgreement() { @@ -1041,7 +1048,7 @@ public function callSetCustomerBillingAgreement() * Get Billing Agreement Customer Details call * * @return void - * @link https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_GetBillingAgreementCustomerDetails + * @link https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_GetBillingAgreementCustomerDetails */ public function callGetBillingAgreementCustomerDetails() { @@ -1084,7 +1091,7 @@ public function callUpdateBillingAgreement() /** * Import callback request array into $this public data * - * @param array $request + * @param array $request * @return \Magento\Framework\DataObject */ public function prepareShippingOptionsCallbackAddress(array $request) @@ -1114,8 +1121,8 @@ public function formatShippingOptionsCallback() /** * Add method to request array * - * @param string $methodName - * @param array $request + * @param string $methodName + * @param array $request * @return array */ protected function _addMethodToRequest($methodName, $request) @@ -1128,7 +1135,7 @@ protected function _addMethodToRequest($methodName, $request) * Additional response processing. * Hack to cut off length from API type response params. * - * @param array $response + * @param array $response * @return array */ protected function _postProcessResponse($response) @@ -1154,10 +1161,10 @@ protected function _postProcessResponse($response) /** * Do the API call * - * @param string $methodName - * @param array $request - * @return array - * @throws \Magento\Framework\Exception\LocalizedException|\Exception + * @param string $methodName + * @param array $request + * @return array + * @throws \Magento\Framework\Exception\LocalizedException|\Exception * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function call($methodName, array $request) @@ -1244,7 +1251,7 @@ public function call($methodName, array $request) /** * Setter for 'raw response needed' flag * - * @param bool $flag + * @param bool $flag * @return $this */ public function setRawResponseNeeded($flag) @@ -1256,9 +1263,9 @@ public function setRawResponseNeeded($flag) /** * Handle logical errors * - * @param array $response - * @return void - * @throws \Magento\Paypal\Model\Api\ProcessableException|\Magento\Framework\Exception\LocalizedException + * @param array $response + * @return void + * @throws \Magento\Paypal\Model\Api\ProcessableException|\Magento\Framework\Exception\LocalizedException * @SuppressWarnings(PHPMD.NPathComplexity) */ protected function _handleCallErrors($response) @@ -1294,7 +1301,9 @@ protected function _handleCallErrors($response) $exceptionPhrase = __('PayPal gateway has rejected request. %1', $errorMessages); - /** @var \Magento\Framework\Exception\LocalizedException $exception */ + /** + * @var \Magento\Framework\Exception\LocalizedException $exception +*/ $firstError = $errors[0]['code']; $exception = $this->_isProcessableError($firstError) ? $this->_processableExceptionFactory->create( @@ -1310,9 +1319,9 @@ protected function _handleCallErrors($response) /** * Format error message from error code, short error message and long error message * - * @param string $errorCode - * @param string $shortErrorMessage - * @param string $longErrorMessage + * @param string $errorCode + * @param string $shortErrorMessage + * @param string $longErrorMessage * @return string */ protected function _formatErrorMessage($errorCode, $shortErrorMessage, $longErrorMessage) @@ -1327,7 +1336,7 @@ protected function _formatErrorMessage($errorCode, $shortErrorMessage, $longErro /** * Check whether PayPal error can be processed * - * @param int $errorCode + * @param int $errorCode * @return bool */ protected function _isProcessableError($errorCode) @@ -1344,7 +1353,7 @@ protected function _isProcessableError($errorCode) /** * Extract errors from PayPal's response and return them in array * - * @param array $response + * @param array $response * @return array */ protected function _extractErrorsFromResponse($response) @@ -1370,7 +1379,7 @@ protected function _extractErrorsFromResponse($response) /** * Catch success calls and collect warnings * - * @param array $response + * @param array $response * @return bool success flag */ protected function _isCallSuccessful($response) @@ -1396,8 +1405,8 @@ protected function _isCallSuccessful($response) /** * Validate response array. * - * @param string $method - * @param array $response + * @param string $method + * @param array $response * @return bool */ protected function _validateResponse($method, $response) @@ -1414,7 +1423,8 @@ protected function _validateResponse($method, $response) /** * Parse an NVP response string into an associative array - * @param string $nvpstr + * + * @param string $nvpstr * @return array */ protected function _deformatNVP($nvpstr) @@ -1443,8 +1453,8 @@ protected function _deformatNVP($nvpstr) /** * NVP doesn't support passing discount total as a separate amount - add it as a line item * - * @param array $request - * @param int $i + * @param array $request + * @param int $i * @return true|null */ protected function _exportLineItems(array &$request, $i = 0) @@ -1459,10 +1469,10 @@ protected function _exportLineItems(array &$request, $i = 0) /** * Create billing and shipping addresses basing on response data * - * @param array $data - * @return void + * @param array $data + * @return void * @deprecated 100.2.2 typo in method name - * @see _exportAddresses + * @see _exportAddresses */ protected function _exportAddressses($data) { @@ -1472,7 +1482,7 @@ protected function _exportAddressses($data) /** * Create billing and shipping addresses basing on response data * - * @param array $data + * @param array $data * @return void */ protected function _exportAddresses($data) @@ -1496,15 +1506,19 @@ protected function _exportAddresses($data) $nameParts = [$firstname, $lastname]; } if (!empty($nameParts[0]) && !empty($nameParts[1])) { - $shippingAddress->addData([ + $shippingAddress->addData( + [ 'firstname' => $nameParts[0], 'lastname' => $nameParts[1] - ]); + ] + ); } else { - $shippingAddress->addData([ + $shippingAddress->addData( + [ 'firstname' => $data['FIRSTNAME'], 'lastname' => $data['LASTNAME'] - ]); + ] + ); } $this->setExportedShippingAddress($shippingAddress); } @@ -1513,7 +1527,7 @@ protected function _exportAddresses($data) /** * Adopt specified address object to be compatible with Magento * - * @param \Magento\Framework\DataObject $address + * @param \Magento\Framework\DataObject $address * @return void */ protected function _applyStreetAndRegionWorkarounds(\Magento\Framework\DataObject $address) @@ -1543,7 +1557,7 @@ protected function _applyStreetAndRegionWorkarounds(\Magento\Framework\DataObjec /** * Prepare request data basing on provided addresses * - * @param array $to + * @param array $to * @return array */ protected function _importAddresses(array $to) @@ -1580,7 +1594,7 @@ protected function _importAddresses(array $to) /** * Filter for credit card type * - * @param string $value + * @param string $value * @return string */ protected function _filterCcType($value) @@ -1594,7 +1608,7 @@ protected function _filterCcType($value) /** * Filter for true/false values (converts to boolean) * - * @param mixed $value + * @param mixed $value * @return bool|mixed */ protected function _filterToBool($value) @@ -1610,7 +1624,7 @@ protected function _filterToBool($value) /** * Filter for 'AUTOBILLAMT' * - * @param string $value + * @param string $value * @return string */ protected function _filterBillFailedLater($value) @@ -1621,31 +1635,31 @@ protected function _filterBillFailedLater($value) /** * Filter for 'BILLINGPERIOD' and 'TRIALBILLINGPERIOD' * - * @param string $value + * @param string $value * @return string */ protected function _filterPeriodUnit($value) { switch ($value) { - case 'day': - return 'Day'; - case 'week': - return 'Week'; - case 'semi_month': - return 'SemiMonth'; - case 'month': - return 'Month'; - case 'year': - return 'Year'; - default: - break; + case 'day': + return 'Day'; + case 'week': + return 'Week'; + case 'semi_month': + return 'SemiMonth'; + case 'month': + return 'Month'; + case 'year': + return 'Year'; + default: + break; } } /** * Filter for 'FAILEDINITAMTACTION' * - * @param string $value + * @param string $value * @return string */ protected function _filterInitialAmountMayFail($value) @@ -1656,77 +1670,77 @@ protected function _filterInitialAmountMayFail($value) /** * Filter for billing agreement status * - * @param string $value + * @param string $value * @return string */ protected function _filterBillingAgreementStatus($value) { switch ($value) { - case 'canceled': - return 'Canceled'; - case 'active': - return 'Active'; - default: - break; + case 'canceled': + return 'Canceled'; + case 'active': + return 'Active'; + default: + break; } } /** * Convert payment status from NVP format to paypal/info model format * - * @param string $value - * @return string|null + * @param string $value + * @return string|null * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ protected function _filterPaymentStatusFromNvpToInfo($value) { switch ($value) { - case 'None': - return \Magento\Paypal\Model\Info::PAYMENTSTATUS_NONE; - case 'Completed': - return \Magento\Paypal\Model\Info::PAYMENTSTATUS_COMPLETED; - case 'Denied': - return \Magento\Paypal\Model\Info::PAYMENTSTATUS_DENIED; - case 'Expired': - return \Magento\Paypal\Model\Info::PAYMENTSTATUS_EXPIRED; - case 'Failed': - return \Magento\Paypal\Model\Info::PAYMENTSTATUS_FAILED; - case 'In-Progress': - return \Magento\Paypal\Model\Info::PAYMENTSTATUS_INPROGRESS; - case 'Pending': - return \Magento\Paypal\Model\Info::PAYMENTSTATUS_PENDING; - case 'Refunded': - return \Magento\Paypal\Model\Info::PAYMENTSTATUS_REFUNDED; - case 'Partially-Refunded': - return \Magento\Paypal\Model\Info::PAYMENTSTATUS_REFUNDEDPART; - case 'Reversed': - return \Magento\Paypal\Model\Info::PAYMENTSTATUS_REVERSED; - case 'Canceled-Reversal': - return \Magento\Paypal\Model\Info::PAYMENTSTATUS_UNREVERSED; - case 'Processed': - return \Magento\Paypal\Model\Info::PAYMENTSTATUS_PROCESSED; - case 'Voided': - return \Magento\Paypal\Model\Info::PAYMENTSTATUS_VOIDED; - default: - break; + case 'None': + return \Magento\Paypal\Model\Info::PAYMENTSTATUS_NONE; + case 'Completed': + return \Magento\Paypal\Model\Info::PAYMENTSTATUS_COMPLETED; + case 'Denied': + return \Magento\Paypal\Model\Info::PAYMENTSTATUS_DENIED; + case 'Expired': + return \Magento\Paypal\Model\Info::PAYMENTSTATUS_EXPIRED; + case 'Failed': + return \Magento\Paypal\Model\Info::PAYMENTSTATUS_FAILED; + case 'In-Progress': + return \Magento\Paypal\Model\Info::PAYMENTSTATUS_INPROGRESS; + case 'Pending': + return \Magento\Paypal\Model\Info::PAYMENTSTATUS_PENDING; + case 'Refunded': + return \Magento\Paypal\Model\Info::PAYMENTSTATUS_REFUNDED; + case 'Partially-Refunded': + return \Magento\Paypal\Model\Info::PAYMENTSTATUS_REFUNDEDPART; + case 'Reversed': + return \Magento\Paypal\Model\Info::PAYMENTSTATUS_REVERSED; + case 'Canceled-Reversal': + return \Magento\Paypal\Model\Info::PAYMENTSTATUS_UNREVERSED; + case 'Processed': + return \Magento\Paypal\Model\Info::PAYMENTSTATUS_PROCESSED; + case 'Voided': + return \Magento\Paypal\Model\Info::PAYMENTSTATUS_VOIDED; + default: + break; } } /** * Convert payment review action to NVP-compatible value * - * @param string $value + * @param string $value * @return string|null */ protected function _filterPaymentReviewAction($value) { switch ($value) { - case \Magento\Paypal\Model\Pro::PAYMENT_REVIEW_ACCEPT: - return 'Accept'; - case \Magento\Paypal\Model\Pro::PAYMENT_REVIEW_DENY: - return 'Deny'; - default: - break; + case \Magento\Paypal\Model\Pro::PAYMENT_REVIEW_ACCEPT: + return 'Accept'; + case \Magento\Paypal\Model\Pro::PAYMENT_REVIEW_DENY: + return 'Deny'; + default: + break; } } @@ -1743,7 +1757,7 @@ protected function _getCaptureCompleteType() /** * Return each call request without unused fields in case of Express Checkout Unilateral payments * - * @param string $methodName Current method name + * @param string $methodName Current method name * @return array */ protected function _prepareEachCallRequest($methodName) @@ -1762,7 +1776,7 @@ protected function _prepareEachCallRequest($methodName) /** * Check the EC request against unilateral payments mode and remove the SUBJECT if needed * - * @param &array $requestFields + * @param &array $requestFields * @return void */ protected function _prepareExpressCheckoutCallRequest(&$requestFields) diff --git a/app/code/Magento/Paypal/Model/Express/Checkout.php b/app/code/Magento/Paypal/Model/Express/Checkout.php index b42c26a9cda17..f836f958e0c55 100644 --- a/app/code/Magento/Paypal/Model/Express/Checkout.php +++ b/app/code/Magento/Paypal/Model/Express/Checkout.php @@ -46,6 +46,7 @@ class Checkout /** * Flag which says that was used PayPal Express Checkout button for checkout * Uses additional_information as storage + * * @var string */ const PAYMENT_INFO_BUTTON = 'button'; @@ -273,32 +274,32 @@ class Checkout protected $totalsCollector; /** - * @param \Psr\Log\LoggerInterface $logger - * @param \Magento\Customer\Model\Url $customerUrl - * @param \Magento\Tax\Helper\Data $taxData - * @param \Magento\Checkout\Helper\Data $checkoutData - * @param \Magento\Customer\Model\Session $customerSession - * @param \Magento\Framework\App\Cache\Type\Config $configCacheType - * @param \Magento\Framework\Locale\ResolverInterface $localeResolver - * @param \Magento\Paypal\Model\Info $paypalInfo - * @param \Magento\Store\Model\StoreManagerInterface $storeManager - * @param \Magento\Framework\UrlInterface $coreUrl - * @param \Magento\Paypal\Model\CartFactory $cartFactory - * @param \Magento\Checkout\Model\Type\OnepageFactory $onepageFactory - * @param \Magento\Quote\Api\CartManagementInterface $quoteManagement - * @param \Magento\Paypal\Model\Billing\AgreementFactory $agreementFactory - * @param \Magento\Paypal\Model\Api\Type\Factory $apiTypeFactory - * @param DataObject\Copy $objectCopyService - * @param \Magento\Checkout\Model\Session $checkoutSession - * @param \Magento\Framework\Encryption\EncryptorInterface $encryptor - * @param \Magento\Framework\Message\ManagerInterface $messageManager - * @param \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository - * @param AccountManagement $accountManagement - * @param OrderSender $orderSender - * @param \Magento\Quote\Api\CartRepositoryInterface $quoteRepository - * @param \Magento\Quote\Model\Quote\TotalsCollector $totalsCollector - * @param array $params - * @throws \Exception + * @param \Psr\Log\LoggerInterface $logger + * @param \Magento\Customer\Model\Url $customerUrl + * @param \Magento\Tax\Helper\Data $taxData + * @param \Magento\Checkout\Helper\Data $checkoutData + * @param \Magento\Customer\Model\Session $customerSession + * @param \Magento\Framework\App\Cache\Type\Config $configCacheType + * @param \Magento\Framework\Locale\ResolverInterface $localeResolver + * @param \Magento\Paypal\Model\Info $paypalInfo + * @param \Magento\Store\Model\StoreManagerInterface $storeManager + * @param \Magento\Framework\UrlInterface $coreUrl + * @param \Magento\Paypal\Model\CartFactory $cartFactory + * @param \Magento\Checkout\Model\Type\OnepageFactory $onepageFactory + * @param \Magento\Quote\Api\CartManagementInterface $quoteManagement + * @param \Magento\Paypal\Model\Billing\AgreementFactory $agreementFactory + * @param \Magento\Paypal\Model\Api\Type\Factory $apiTypeFactory + * @param DataObject\Copy $objectCopyService + * @param \Magento\Checkout\Model\Session $checkoutSession + * @param \Magento\Framework\Encryption\EncryptorInterface $encryptor + * @param \Magento\Framework\Message\ManagerInterface $messageManager + * @param \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository + * @param AccountManagement $accountManagement + * @param OrderSender $orderSender + * @param \Magento\Quote\Api\CartRepositoryInterface $quoteRepository + * @param \Magento\Quote\Model\Quote\TotalsCollector $totalsCollector + * @param array $params + * @throws \Exception * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -406,9 +407,9 @@ public function getCheckoutShortcutImageUrl() /** * Setter that enables giropay redirects flow * - * @param string $successUrl - payment success result - * @param string $cancelUrl - payment cancellation result - * @param string $pendingUrl - pending payment result + * @param string $successUrl - payment success result + * @param string $cancelUrl - payment cancellation result + * @param string $pendingUrl - pending payment result * @return $this */ public function prepareGiropayUrls($successUrl, $cancelUrl, $pendingUrl) @@ -420,7 +421,7 @@ public function prepareGiropayUrls($successUrl, $cancelUrl, $pendingUrl) /** * Set create billing agreement flag * - * @param bool $flag + * @param bool $flag * @return $this */ public function setIsBillingAgreementRequested($flag) @@ -432,7 +433,7 @@ public function setIsBillingAgreementRequested($flag) /** * Set flag that forces to use BillMeLater * - * @param bool $isBml + * @param bool $isBml * @return $this */ public function setIsBml($isBml) @@ -444,7 +445,7 @@ public function setIsBml($isBml) /** * Setter for customer * - * @param CustomerDataObject $customerData + * @param CustomerDataObject $customerData * @return $this */ public function setCustomerData(CustomerDataObject $customerData) @@ -457,9 +458,9 @@ public function setCustomerData(CustomerDataObject $customerData) /** * Setter for customer with billing and shipping address changing ability * - * @param CustomerDataObject $customerData - * @param Address|null $billingAddress - * @param Address|null $shippingAddress + * @param CustomerDataObject $customerData + * @param Address|null $billingAddress + * @param Address|null $shippingAddress * @return $this */ public function setCustomerWithAddressChange( @@ -475,11 +476,11 @@ public function setCustomerWithAddressChange( /** * Reserve order ID for specified quote and start checkout on PayPal * - * @param string $returnUrl - * @param string $cancelUrl - * @param bool|null $button - * @return string - * @throws \Magento\Framework\Exception\LocalizedException + * @param string $returnUrl + * @param string $cancelUrl + * @param bool|null $button + * @return string + * @throws \Magento\Framework\Exception\LocalizedException * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) @@ -535,8 +536,7 @@ public function start($returnUrl, $cancelUrl, $button = null) // suppress or export shipping address $address = null; if ($this->_quote->getIsVirtual()) { - if ($this->_config->getValue('requireBillingAddress') - == PaypalConfig::REQUIRE_BILLING_ADDRESS_VIRTUAL + if ($this->_config->getValue('requireBillingAddress')== PaypalConfig::REQUIRE_BILLING_ADDRESS_VIRTUAL ) { $this->_getApi()->setRequireBillingAddress(1); } @@ -557,7 +557,9 @@ public function start($returnUrl, $cancelUrl, $button = null) $this->_quote->getPayment()->save(); } - /** @var $cart \Magento\Payment\Model\Cart */ + /** + * @var $cart \Magento\Payment\Model\Cart +*/ $cart = $this->_cartFactory->create(['salesModel' => $this->_quote]); $this->_getApi()->setPaypalCart($cart); @@ -606,9 +608,9 @@ public function canSkipOrderReviewStep() * Rewrite billing address by paypal, save old billing address for new customer, and * export shipping address in case address absence * - * @param string $token - * @param string|null $payerIdentifier - * @return void + * @param string $token + * @param string|null $payerIdentifier + * @return void * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ @@ -692,9 +694,9 @@ public function returnFromPaypal($token, string $payerIdentifier = null) /** * Check whether order review has enough data to initialize * - * @param string|null $token - * @return void - * @throws \Magento\Framework\Exception\LocalizedException + * @param string|null $token + * @return void + * @throws \Magento\Framework\Exception\LocalizedException * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function prepareOrderReview($token = null) @@ -717,7 +719,7 @@ public function prepareOrderReview($token = null) /** * Return callback response with shipping options * - * @param array $request + * @param array $request * @return string * @throws \Exception */ @@ -755,7 +757,7 @@ public function getShippingOptionsCallbackResponse(array $request) /** * Set shipping method to quote, if needed * - * @param string $methodCode + * @param string $methodCode * @return void */ public function updateShippingMethod($methodCode) @@ -780,9 +782,9 @@ public function updateShippingMethod($methodCode) /** * Place the order when customer returned from PayPal until this moment all quote data must be valid. * - * @param string $token - * @param string|null $shippingMethodCode - * @return void + * @param string $token + * @param string|null $shippingMethodCode + * @return void * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ @@ -811,24 +813,24 @@ public function place($token, $shippingMethodCode = null) switch ($order->getState()) { // even after placement paypal can disallow to authorize/capture, but will wait until bank transfers money - case \Magento\Sales\Model\Order::STATE_PENDING_PAYMENT: - // TODO - break; + case \Magento\Sales\Model\Order::STATE_PENDING_PAYMENT: + // TODO + break; // regular placement, when everything is ok - case \Magento\Sales\Model\Order::STATE_PROCESSING: - case \Magento\Sales\Model\Order::STATE_COMPLETE: - case \Magento\Sales\Model\Order::STATE_PAYMENT_REVIEW: - try { - if (!$order->getEmailSent()) { - $this->orderSender->send($order); - } - } catch (\Exception $e) { - $this->_logger->critical($e); + case \Magento\Sales\Model\Order::STATE_PROCESSING: + case \Magento\Sales\Model\Order::STATE_COMPLETE: + case \Magento\Sales\Model\Order::STATE_PAYMENT_REVIEW: + try { + if (!$order->getEmailSent()) { + $this->orderSender->send($order); } - $this->_checkoutSession->start(); - break; - default: - break; + } catch (\Exception $e) { + $this->_logger->critical($e); + } + $this->_checkoutSession->start(); + break; + default: + break; } $this->_order = $order; } @@ -904,8 +906,8 @@ public function getCheckoutMethod() /** * Sets address data from exported address * - * @param Address $address - * @param array $exportedAddress + * @param Address $address + * @param array $exportedAddress * @return void */ protected function _setExportedAddressData($address, $exportedAddress) @@ -964,10 +966,10 @@ protected function _getApi() * Returns empty array if it was impossible to obtain any shipping rate and * if there are shipping rates obtained, the method must return one of them as default. * - * @param Address $address - * @param bool $mayReturnEmpty - * @param bool $calculateTax - * @return array|false + * @param Address $address + * @param bool $mayReturnEmpty + * @param bool $calculateTax + * @return array|false * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ @@ -1047,9 +1049,9 @@ protected function _prepareShippingOptions(Address $address, $mayReturnEmpty = f * * This function is used as a callback comparison function in shipping options sorting process * - * @see self::_prepareShippingOptions() - * @param \Magento\Framework\DataObject $option1 - * @param \Magento\Framework\DataObject $option2 + * @see self::_prepareShippingOptions() + * @param \Magento\Framework\DataObject $option1 + * @param \Magento\Framework\DataObject $option2 * @return int */ protected static function cmpShippingOptions(DataObject $option1, DataObject $option2) @@ -1064,8 +1066,8 @@ protected static function cmpShippingOptions(DataObject $option1, DataObject $op * If in future the issue is fixed, we don't need to attempt to match it. It would be enough to set the method code * before collecting shipping rates * - * @param Address $address - * @param string $selectedCode + * @param Address $address + * @param string $selectedCode * @return string */ protected function _matchShippingMethodCode(Address $address, $selectedCode) @@ -1087,8 +1089,8 @@ protected function _matchShippingMethodCode(Address $address, $selectedCode) /** * Create payment redirect url * - * @param bool|null $button - * @param string $token + * @param bool|null $button + * @param string $token * @return void */ protected function _setRedirectUrl($button, $token) @@ -1111,8 +1113,8 @@ public function getCustomerSession() /** * Set shipping options to api * - * @param \Magento\Paypal\Model\Cart $cart - * @param \Magento\Quote\Model\Quote\Address|null $address + * @param \Magento\Paypal\Model\Cart $cart + * @param \Magento\Quote\Model\Quote\Address|null $address * @return void */ private function setShippingOptions(PaypalCart $cart, Address $address = null) diff --git a/dev/tests/integration/testsuite/Magento/Paypal/Model/Api/NvpTest.php b/dev/tests/integration/testsuite/Magento/Paypal/Model/Api/NvpTest.php index a492c5402e3fa..efde6ddaca90b 100644 --- a/dev/tests/integration/testsuite/Magento/Paypal/Model/Api/NvpTest.php +++ b/dev/tests/integration/testsuite/Magento/Paypal/Model/Api/NvpTest.php @@ -145,8 +145,8 @@ public function testCallRefundTransaction() ); $httpQuery = 'TRANSACTIONID=fooTransactionId&REFUNDTYPE=Partial' - .'&CURRENCYCODE=USD&AMT=145.98&METHOD=RefundTransaction' - .'&VERSION=72.0&BUTTONSOURCE=Magento_Cart_'; + . '&CURRENCYCODE=USD&AMT=145.98&METHOD=RefundTransaction' + . '&VERSION=72.0&BUTTONSOURCE=Magento_Cart_'; $this->httpClient->expects($this->once())->method('write') ->with( From c25830cf93ac11ee5b250e40700b64f1f9c21697 Mon Sep 17 00:00:00 2001 From: bradleybrecher Date: Fri, 2 Aug 2019 17:51:17 -0400 Subject: [PATCH 10/10] PHP Code Sniffer violations fix using PHPCBF --- .../Paypal/Test/Unit/Model/Api/NvpTest.php | 112 +++++++++++------- .../Magento/Paypal/Model/Api/NvpTest.php | 42 +++++-- 2 files changed, 102 insertions(+), 52 deletions(-) diff --git a/app/code/Magento/Paypal/Test/Unit/Model/Api/NvpTest.php b/app/code/Magento/Paypal/Test/Unit/Model/Api/NvpTest.php index d58b9ec9bdd5b..b73fdb24f602d 100644 --- a/app/code/Magento/Paypal/Test/Unit/Model/Api/NvpTest.php +++ b/app/code/Magento/Paypal/Test/Unit/Model/Api/NvpTest.php @@ -14,37 +14,59 @@ */ class NvpTest extends \PHPUnit\Framework\TestCase { - /** @var \Magento\Paypal\Model\Api\Nvp */ + /** + * @var \Magento\Paypal\Model\Api\Nvp + */ protected $model; - /** @var \Magento\Customer\Helper\Address|\PHPUnit_Framework_MockObject_MockObject */ + /** + * @var \Magento\Customer\Helper\Address|\PHPUnit_Framework_MockObject_MockObject + */ protected $customerAddressHelper; - /** @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject */ + /** + * @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject + */ protected $logger; - /** @var \Magento\Framework\Locale\ResolverInterface|\PHPUnit_Framework_MockObject_MockObject */ + /** + * @var \Magento\Framework\Locale\ResolverInterface|\PHPUnit_Framework_MockObject_MockObject + */ protected $resolver; - /** @var \Magento\Directory\Model\RegionFactory|\PHPUnit_Framework_MockObject_MockObject */ + /** + * @var \Magento\Directory\Model\RegionFactory|\PHPUnit_Framework_MockObject_MockObject + */ protected $regionFactory; - /** @var \Magento\Directory\Model\CountryFactory|\PHPUnit_Framework_MockObject_MockObject */ + /** + * @var \Magento\Directory\Model\CountryFactory|\PHPUnit_Framework_MockObject_MockObject + */ protected $countryFactory; - /** @var \Magento\Paypal\Model\Api\ProcessableException|\PHPUnit_Framework_MockObject_MockObject */ + /** + * @var \Magento\Paypal\Model\Api\ProcessableException|\PHPUnit_Framework_MockObject_MockObject + */ protected $processableException; - /** @var \Magento\Framework\Exception\LocalizedException|\PHPUnit_Framework_MockObject_MockObject */ + /** + * @var \Magento\Framework\Exception\LocalizedException|\PHPUnit_Framework_MockObject_MockObject + */ protected $exception; - /** @var \Magento\Framework\HTTP\Adapter\Curl|\PHPUnit_Framework_MockObject_MockObject */ + /** + * @var \Magento\Framework\HTTP\Adapter\Curl|\PHPUnit_Framework_MockObject_MockObject + */ protected $curl; - /** @var \Magento\Paypal\Model\Config|\PHPUnit_Framework_MockObject_MockObject */ + /** + * @var \Magento\Paypal\Model\Config|\PHPUnit_Framework_MockObject_MockObject + */ protected $config; - /** @var \Magento\Payment\Model\Method\Logger|\PHPUnit_Framework_MockObject_MockObject */ + /** + * @var \Magento\Payment\Model\Method\Logger|\PHPUnit_Framework_MockObject_MockObject + */ protected $customLoggerMock; protected function setUp() @@ -64,26 +86,34 @@ protected function setUp() ); $processableExceptionFactory->expects($this->any()) ->method('create') - ->will($this->returnCallback(function ($arguments) { - $this->processableException = $this->getMockBuilder( - \Magento\Paypal\Model\Api\ProcessableException::class + ->will( + $this->returnCallback( + function ($arguments) { + $this->processableException = $this->getMockBuilder( + \Magento\Paypal\Model\Api\ProcessableException::class + ) + ->setConstructorArgs([$arguments['phrase'], null, $arguments['code']]) + ->getMock(); + return $this->processableException; + } ) - ->setConstructorArgs([$arguments['phrase'], null, $arguments['code']]) - ->getMock(); - return $this->processableException; - })); + ); $exceptionFactory = $this->createPartialMock( \Magento\Framework\Exception\LocalizedExceptionFactory::class, ['create'] ); $exceptionFactory->expects($this->any()) ->method('create') - ->will($this->returnCallback(function ($arguments) { - $this->exception = $this->getMockBuilder(\Magento\Framework\Exception\LocalizedException::class) - ->setConstructorArgs([$arguments['phrase']]) - ->getMock(); - return $this->exception; - })); + ->will( + $this->returnCallback( + function ($arguments) { + $this->exception = $this->getMockBuilder(\Magento\Framework\Exception\LocalizedException::class) + ->setConstructorArgs([$arguments['phrase']]) + ->getMock(); + return $this->exception; + } + ) + ); $this->curl = $this->createMock(\Magento\Framework\HTTP\Adapter\Curl::class); $curlFactory = $this->createPartialMock(\Magento\Framework\HTTP\Adapter\CurlFactory::class, ['create']); $curlFactory->expects($this->any())->method('create')->will($this->returnValue($this->curl)); @@ -108,8 +138,8 @@ protected function setUp() } /** - * @param \Magento\Paypal\Model\Api\Nvp $nvpObject - * @param string $property + * @param \Magento\Paypal\Model\Api\Nvp $nvpObject + * @param string $property * @return mixed */ protected function _invokeNvpProperty(\Magento\Paypal\Model\Api\Nvp $nvpObject, $property) @@ -122,11 +152,11 @@ protected function _invokeNvpProperty(\Magento\Paypal\Model\Api\Nvp $nvpObject, } /** - * @param string $response - * @param array $processableErrors - * @param null|string $exception - * @param string $exceptionMessage - * @param null|int $exceptionCode + * @param string $response + * @param array $processableErrors + * @param null|string $exception + * @param string $exceptionMessage + * @param null|int $exceptionCode * @dataProvider callDataProvider */ public function testCall($response, $processableErrors, $exception, $exceptionMessage = '', $exceptionCode = null) @@ -188,15 +218,17 @@ public function testCallGetExpressCheckoutDetails() { $this->curl->expects($this->once()) ->method('read') - ->will($this->returnValue( - "\r\n" . 'ACK=Success&SHIPTONAME=Ship%20To%20Name' - . '&SHIPTOSTREET=testStreet' - . '&SHIPTOSTREET2=testApartment' - . '&BUSINESS=testCompany' - . '&SHIPTOCITY=testCity' - . '&PHONENUM=223322' - . '&STATE=testSTATE' - )); + ->will( + $this->returnValue( + "\r\n" . 'ACK=Success&SHIPTONAME=Ship%20To%20Name' + . '&SHIPTOSTREET=testStreet' + . '&SHIPTOSTREET2=testApartment' + . '&BUSINESS=testCompany' + . '&SHIPTOCITY=testCity' + . '&PHONENUM=223322' + . '&STATE=testSTATE' + ) + ); $this->model->callGetExpressCheckoutDetails(); $address = $this->model->getExportedShippingAddress(); $this->assertEquals('Ship To Name', ($address->getData('firstname') . " " . $address->getData('lastname'))); diff --git a/dev/tests/integration/testsuite/Magento/Paypal/Model/Api/NvpTest.php b/dev/tests/integration/testsuite/Magento/Paypal/Model/Api/NvpTest.php index efde6ddaca90b..894b8215f9ef7 100644 --- a/dev/tests/integration/testsuite/Magento/Paypal/Model/Api/NvpTest.php +++ b/dev/tests/integration/testsuite/Magento/Paypal/Model/Api/NvpTest.php @@ -44,7 +44,9 @@ protected function setUp() { $this->objectManager = Bootstrap::getObjectManager(); - /** @var CurlFactory|MockObject $httpFactory */ + /** + * @var CurlFactory|MockObject $httpFactory +*/ $httpFactory = $this->getMockBuilder(CurlFactory::class) ->disableOriginalConstructor() ->getMock(); @@ -55,17 +57,23 @@ protected function setUp() $httpFactory->method('create') ->willReturn($this->httpClient); - $this->nvpApi = $this->objectManager->create(Nvp::class, [ + $this->nvpApi = $this->objectManager->create( + Nvp::class, [ 'curlFactory' => $httpFactory - ]); + ] + ); - /** @var ProductMetadataInterface|MockObject $productMetadata */ + /** + * @var ProductMetadataInterface|MockObject $productMetadata +*/ $productMetadata = $this->getMockBuilder(ProductMetadataInterface::class) ->getMock(); $productMetadata->method('getEdition') ->willReturn(''); - /** @var Config $config */ + /** + * @var Config $config +*/ $config = $this->objectManager->get(Config::class); $config->setMethodCode(Config::METHOD_EXPRESS); @@ -82,12 +90,14 @@ protected function setUp() * * @magentoConfigFixture current_store tax/weee/enable 1 * @magentoConfigFixture current_store tax/weee/include_in_subtotal 0 - * @magentoDataFixture Magento/Paypal/_files/quote_with_fpt.php + * @magentoDataFixture Magento/Paypal/_files/quote_with_fpt.php */ public function testRequestTotalsAndLineItemsWithFPT() { $quote = $this->getQuote('100000016'); - /** @var CartFactory $cartFactory */ + /** + * @var CartFactory $cartFactory +*/ $cartFactory = $this->objectManager->get(CartFactory::class); $cart = $cartFactory->create(['salesModel' => $quote]); @@ -125,11 +135,15 @@ public function testRequestTotalsAndLineItemsWithFPT() */ public function testCallRefundTransaction() { - /** @var \Magento\Sales\Model\Order $order */ + /** + * @var \Magento\Sales\Model\Order $order +*/ $order = $this->objectManager->create(\Magento\Sales\Model\Order::class); $order->loadByIncrementId('100000001'); - /** @var \Magento\Sales\Model\Order\Payment $payment */ + /** + * @var \Magento\Sales\Model\Order\Payment $payment +*/ $payment = $order->getPayment(); $this->nvpApi->setPayment( @@ -163,16 +177,20 @@ public function testCallRefundTransaction() /** * Gets quote by reserved order id. * - * @param string $reservedOrderId + * @param string $reservedOrderId * @return Quote */ private function getQuote($reservedOrderId) { - /** @var SearchCriteriaBuilder $searchCriteriaBuilder */ + /** + * @var SearchCriteriaBuilder $searchCriteriaBuilder +*/ $searchCriteriaBuilder = $this->objectManager->create(SearchCriteriaBuilder::class); $searchCriteria = $searchCriteriaBuilder->addFilter('reserved_order_id', $reservedOrderId) ->create(); - /** @var QuoteRepository $quoteRepository */ + /** + * @var QuoteRepository $quoteRepository +*/ $quoteRepository = $this->objectManager->get(QuoteRepository::class); $items = $quoteRepository->getList($searchCriteria) ->getItems();