diff --git a/app/code/Magento/Paypal/Model/Api/Nvp.php b/app/code/Magento/Paypal/Model/Api/Nvp.php index 624068395394d..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) @@ -1488,7 +1498,28 @@ 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']]); + $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) { + $lastname = array_pop($nameParts); + $firstname = implode(' ', $nameParts); + $nameParts = [$firstname, $lastname]; + } + if (!empty($nameParts[0]) && !empty($nameParts[1])) { + $shippingAddress->addData( + [ + 'firstname' => $nameParts[0], + 'lastname' => $nameParts[1] + ] + ); + } else { + $shippingAddress->addData( + [ + 'firstname' => $data['FIRSTNAME'], + 'lastname' => $data['LASTNAME'] + ] + ); + } $this->setExportedShippingAddress($shippingAddress); } } @@ -1496,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) @@ -1526,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) @@ -1563,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) @@ -1577,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) @@ -1593,7 +1624,7 @@ protected function _filterToBool($value) /** * Filter for 'AUTOBILLAMT' * - * @param string $value + * @param string $value * @return string */ protected function _filterBillFailedLater($value) @@ -1604,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) @@ -1639,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; } } @@ -1726,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) @@ -1745,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 72f166e8d07c1..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) */ @@ -632,12 +634,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 @@ -698,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) @@ -723,7 +719,7 @@ public function prepareOrderReview($token = null) /** * Return callback response with shipping options * - * @param array $request + * @param array $request * @return string * @throws \Exception */ @@ -761,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) @@ -786,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) */ @@ -817,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; } @@ -910,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) @@ -970,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) */ @@ -1053,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) @@ -1070,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) @@ -1093,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) @@ -1117,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/app/code/Magento/Paypal/Test/Unit/Model/Api/NvpTest.php b/app/code/Magento/Paypal/Test/Unit/Model/Api/NvpTest.php index fcc7766ec298b..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,18 +218,20 @@ 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')); + $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()); 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..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( @@ -145,8 +159,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( @@ -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(); 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());