Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Static Protected Member Functions | Protected Attributes
Checkout Class Reference
Inheritance diagram for Checkout:
Checkout

Public Member Functions

 __construct (\Psr\Log\LoggerInterface $logger, \Magento\Customer\Model\Url $customerUrl, \Magento\Tax\Helper\Data $taxData, \Magento\Checkout\Helper\Data $checkoutData, \Magento\Customer\Model\Session $customerSession, \Magento\Framework\App\Cache\Type\Config $configCacheType, \Magento\Framework\Locale\ResolverInterface $localeResolver, \Magento\Paypal\Model\Info $paypalInfo, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\UrlInterface $coreUrl, \Magento\Paypal\Model\CartFactory $cartFactory, \Magento\Checkout\Model\Type\OnepageFactory $onepageFactory, \Magento\Quote\Api\CartManagementInterface $quoteManagement, \Magento\Paypal\Model\Billing\AgreementFactory $agreementFactory, \Magento\Paypal\Model\Api\Type\Factory $apiTypeFactory, \Magento\Framework\DataObject\Copy $objectCopyService, \Magento\Checkout\Model\Session $checkoutSession, \Magento\Framework\Encryption\EncryptorInterface $encryptor, \Magento\Framework\Message\ManagerInterface $messageManager, \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository, AccountManagement $accountManagement, OrderSender $orderSender, \Magento\Quote\Api\CartRepositoryInterface $quoteRepository, \Magento\Quote\Model\Quote\TotalsCollector $totalsCollector, $params=[])
 
 getCheckoutShortcutImageUrl ()
 
 prepareGiropayUrls ($successUrl, $cancelUrl, $pendingUrl)
 
 setIsBillingAgreementRequested ($flag)
 
 setIsBml ($isBml)
 
 setCustomerData (CustomerDataObject $customerData)
 
 setCustomerWithAddressChange (CustomerDataObject $customerData, $billingAddress=null, $shippingAddress=null)
 
 canSkipOrderReviewStep ()
 
 returnFromPaypal ($token)
 
 prepareOrderReview ($token=null)
 
 getShippingOptionsCallbackResponse (array $request)
 
 updateShippingMethod ($methodCode)
 
 place ($token, $shippingMethodCode=null)
 
 getRedirectUrl ()
 
 getBillingAgreement ()
 
 getOrder ()
 
 getCheckoutMethod ()
 
 getCustomerSession ()
 

Data Fields

const PAL_CACHE_ID = 'paypal_express_checkout_pal'
 
const PAYMENT_INFO_TRANSPORT_TOKEN = 'paypal_express_checkout_token'
 
const PAYMENT_INFO_TRANSPORT_SHIPPING_OVERRIDDEN = 'paypal_express_checkout_shipping_overridden'
 
const PAYMENT_INFO_TRANSPORT_SHIPPING_METHOD = 'paypal_express_checkout_shipping_method'
 
const PAYMENT_INFO_TRANSPORT_PAYER_ID = 'paypal_express_checkout_payer_id'
 
const PAYMENT_INFO_TRANSPORT_REDIRECT = 'paypal_express_checkout_redirect_required'
 
const PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT = 'paypal_ec_create_ba'
 
const PAYMENT_INFO_BUTTON = 'button'
 

Protected Member Functions

 _setExportedAddressData ($address, $exportedAddress)
 
 _setBillingAgreementRequest ()
 
 _getApi ()
 
 _prepareShippingOptions (Address $address, $mayReturnEmpty=false, $calculateTax=false)
 
 _matchShippingMethodCode (Address $address, $selectedCode)
 
 _setRedirectUrl ($button, $token)
 
 prepareGuestQuote ()
 

Static Protected Member Functions

static cmpShippingOptions (DataObject $option1, DataObject $option2)
 

Protected Attributes

 $_quote
 
 $_config
 
 $_api
 
 $_apiType = \Magento\Paypal\Model\Api\Nvp::class
 
 $_methodType = PaypalConfig::METHOD_WPP_EXPRESS
 
 $_redirectUrl = ''
 
 $_pendingPaymentMessage = ''
 
 $_checkoutRedirectUrl = ''
 
 $_customerSession
 
 $_giropayUrls = []
 
 $_isBARequested = false
 
 $_isBml = false
 
 $_customerId
 
 $_billingAgreement
 
 $_order
 
 $_configCacheType
 
 $_checkoutData
 
 $_taxData
 
 $_customerUrl
 
 $_logger
 
 $_localeResolver
 
 $_paypalInfo
 
 $_storeManager
 
 $_coreUrl
 
 $_cartFactory
 
 $_checkoutOnepageFactory
 
 $_agreementFactory
 
 $_apiTypeFactory
 
 $_objectCopyService
 
 $_checkoutSession
 
 $_customerRepository
 
 $_accountManagement
 
 $_encryptor
 
 $_messageManager
 
 $orderSender
 
 $quoteRepository
 
 $quoteManagement
 
 $totalsCollector
 

Detailed Description

Wrapper that performs Paypal Express and Checkout communication

@SuppressWarnings(PHPMD.TooManyFields) @SuppressWarnings(PHPMD.ExcessiveClassComplexity) @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 25 of file Checkout.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Psr\Log\LoggerInterface  $logger,
\Magento\Customer\Model\Url  $customerUrl,
\Magento\Tax\Helper\Data  $taxData,
\Magento\Checkout\Helper\Data  $checkoutData,
\Magento\Customer\Model\Session  $customerSession,
\Magento\Framework\App\Cache\Type\Config  $configCacheType,
\Magento\Framework\Locale\ResolverInterface  $localeResolver,
\Magento\Paypal\Model\Info  $paypalInfo,
\Magento\Store\Model\StoreManagerInterface  $storeManager,
\Magento\Framework\UrlInterface  $coreUrl,
\Magento\Paypal\Model\CartFactory  $cartFactory,
\Magento\Checkout\Model\Type\OnepageFactory  $onepageFactory,
\Magento\Quote\Api\CartManagementInterface  $quoteManagement,
\Magento\Paypal\Model\Billing\AgreementFactory  $agreementFactory,
\Magento\Paypal\Model\Api\Type\Factory  $apiTypeFactory,
\Magento\Framework\DataObject\Copy  $objectCopyService,
\Magento\Checkout\Model\Session  $checkoutSession,
\Magento\Framework\Encryption\EncryptorInterface  $encryptor,
\Magento\Framework\Message\ManagerInterface  $messageManager,
\Magento\Customer\Api\CustomerRepositoryInterface  $customerRepository,
AccountManagement  $accountManagement,
OrderSender  $orderSender,
\Magento\Quote\Api\CartRepositoryInterface  $quoteRepository,
\Magento\Quote\Model\Quote\TotalsCollector  $totalsCollector,
  $params = [] 
)
Parameters
\Psr\Log\LoggerInterface$logger
\Magento\Customer\Model\Url$customerUrl
\Magento\Tax\Helper\Data$taxData
\Magento\Checkout\Helper\Data$checkoutData
\Magento\Customer\Model\Session$customerSession
\Magento\Framework\App\Cache\Type\Config$configCacheType
\Magento\Framework\Locale\ResolverInterface$localeResolver
\Magento\Paypal\Model\Info$paypalInfo
\Magento\Store\Model\StoreManagerInterface$storeManager
\Magento\Framework\UrlInterface$coreUrl
\Magento\Paypal\Model\CartFactory$cartFactory
\Magento\Checkout\Model\Type\OnepageFactory$onepageFactory
\Magento\Quote\Api\CartManagementInterface$quoteManagement
\Magento\Paypal\Model\Billing\AgreementFactory$agreementFactory
\Magento\Paypal\Model\Api\Type\Factory$apiTypeFactory
DataObject\Copy$objectCopyService
\Magento\Checkout\Model\Session$checkoutSession
\Magento\Framework\Encryption\EncryptorInterface$encryptor
\Magento\Framework\Message\ManagerInterface$messageManager
\Magento\Customer\Api\CustomerRepositoryInterface$customerRepository
AccountManagement$accountManagement
OrderSender$orderSender
\Magento\Quote\Api\CartRepositoryInterface$quoteRepository
\Magento\Quote\Model\Quote\TotalsCollector$totalsCollector
array$params
Exceptions

Definition at line 303 of file Checkout.php.

329  {
330  $this->quoteManagement = $quoteManagement;
331  $this->_customerUrl = $customerUrl;
332  $this->_taxData = $taxData;
333  $this->_checkoutData = $checkoutData;
334  $this->_configCacheType = $configCacheType;
335  $this->_logger = $logger;
336  $this->_localeResolver = $localeResolver;
337  $this->_paypalInfo = $paypalInfo;
338  $this->_storeManager = $storeManager;
339  $this->_coreUrl = $coreUrl;
340  $this->_cartFactory = $cartFactory;
341  $this->_checkoutOnepageFactory = $onepageFactory;
342  $this->_agreementFactory = $agreementFactory;
343  $this->_apiTypeFactory = $apiTypeFactory;
344  $this->_objectCopyService = $objectCopyService;
345  $this->_checkoutSession = $checkoutSession;
346  $this->_customerRepository = $customerRepository;
347  $this->_encryptor = $encryptor;
348  $this->_messageManager = $messageManager;
349  $this->orderSender = $orderSender;
350  $this->_accountManagement = $accountManagement;
351  $this->quoteRepository = $quoteRepository;
352  $this->totalsCollector = $totalsCollector;
353  $this->_customerSession = isset($params['session'])
354  && $params['session'] instanceof \Magento\Customer\Model\Session ? $params['session'] : $customerSession;
355 
356  if (isset($params['config']) && $params['config'] instanceof PaypalConfig) {
357  $this->_config = $params['config'];
358  } else {
359  throw new \Exception('Config instance is required.');
360  }
361 
362  if (isset($params['quote']) && $params['quote'] instanceof \Magento\Quote\Model\Quote) {
363  $this->_quote = $params['quote'];
364  } else {
365  throw new \Exception('Quote instance is required.');
366  }
367  }
$customerUrl
Definition: info.phtml:28
$storeManager
$customerRepository
$accountManagement
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

Member Function Documentation

◆ _getApi()

_getApi ( )
protected

Get api

Returns
\Magento\Paypal\Model\Api\Nvp

Definition at line 955 of file Checkout.php.

956  {
957  if (null === $this->_api) {
958  $this->_api = $this->_apiTypeFactory->create($this->_apiType)->setConfigObject($this->_config);
959  }
960  return $this->_api;
961  }

◆ _matchShippingMethodCode()

_matchShippingMethodCode ( Address  $address,
  $selectedCode 
)
protected

Try to find whether the code provided by PayPal corresponds to any of possible shipping rates

This method was created only because PayPal has issues with returning the selected code. 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

Parameters
Address$address
string$selectedCode
Returns
string

Definition at line 1076 of file Checkout.php.

1077  {
1078  $options = $this->_prepareShippingOptions($address, false);
1079  foreach ($options as $option) {
1080  if ($selectedCode === $option['code'] // the proper case as outlined in documentation
1081  || $selectedCode === $option['name'] // workaround: PayPal may return name instead of the code
1082  // workaround: PayPal may concatenate code and name, and return it instead of the code:
1083  || $selectedCode === "{$option['code']} {$option['name']}"
1084  ) {
1085  return $option['code'];
1086  }
1087  }
1088  return '';
1089  }
_prepareShippingOptions(Address $address, $mayReturnEmpty=false, $calculateTax=false)
Definition: Checkout.php:976
$address
Definition: customer.php:38

◆ _prepareShippingOptions()

_prepareShippingOptions ( Address  $address,
  $mayReturnEmpty = false,
  $calculateTax = false 
)
protected

Attempt to collect address shipping rates and return them for further usage in instant update API

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.

Parameters
Address$address
bool$mayReturnEmpty
bool$calculateTax
Returns
array|false @SuppressWarnings(PHPMD.CyclomaticComplexity) @SuppressWarnings(PHPMD.NPathComplexity)

Definition at line 976 of file Checkout.php.

977  {
978  $options = [];
979  $i = 0;
980  $iMin = false;
981  $min = false;
982  $userSelectedOption = null;
983 
984  foreach ($address->getGroupedAllShippingRates() as $group) {
985  foreach ($group as $rate) {
986  $amount = (double)$rate->getPrice();
987  if ($rate->getErrorMessage()) {
988  continue;
989  }
990  $isDefault = $address->getShippingMethod() === $rate->getCode();
991  $amountExclTax = $this->_taxData->getShippingPrice($amount, false, $address);
992  $amountInclTax = $this->_taxData->getShippingPrice($amount, true, $address);
993 
994  $options[$i] = new \Magento\Framework\DataObject(
995  [
996  'is_default' => $isDefault,
997  'name' => trim("{$rate->getCarrierTitle()} - {$rate->getMethodTitle()}", ' -'),
998  'code' => $rate->getCode(),
999  'amount' => $amountExclTax,
1000  ]
1001  );
1002  if ($calculateTax) {
1003  $options[$i]->setTaxAmount(
1004  $amountInclTax - $amountExclTax + $address->getTaxAmount() - $address->getShippingTaxAmount()
1005  );
1006  }
1007  if ($isDefault) {
1008  $userSelectedOption = $options[$i];
1009  }
1010  if (false === $min || $amountInclTax < $min) {
1011  $min = $amountInclTax;
1012  $iMin = $i;
1013  }
1014  $i++;
1015  }
1016  }
1017 
1018  if ($mayReturnEmpty && $userSelectedOption === null) {
1019  $options[] = new \Magento\Framework\DataObject(
1020  [
1021  'is_default' => true,
1022  'name' => __('N/A'),
1023  'code' => 'no_rate',
1024  'amount' => 0.00,
1025  ]
1026  );
1027  if ($calculateTax) {
1028  $options[$i]->setTaxAmount($address->getTaxAmount());
1029  }
1030  } elseif ($userSelectedOption === null && isset($options[$iMin])) {
1031  $options[$iMin]->setIsDefault(true);
1032  }
1033 
1034  // Magento will transfer only first 10 cheapest shipping options if there are more than 10 available.
1035  if (count($options) > 10) {
1036  usort($options, [get_class($this), 'cmpShippingOptions']);
1037  array_splice($options, 10);
1038  // User selected option will be always included in options list
1039  if ($userSelectedOption !== null && !in_array($userSelectedOption, $options)) {
1040  $options[9] = $userSelectedOption;
1041  }
1042  }
1043 
1044  return $options;
1045  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$group
Definition: sections.phtml:16
__()
Definition: __.php:13
$address
Definition: customer.php:38
$amount
Definition: order.php:14
$i
Definition: gallery.phtml:31

◆ _setBillingAgreementRequest()

_setBillingAgreementRequest ( )
protected

Set create billing agreement flag to api call

Returns
$this

Definition at line 928 of file Checkout.php.

929  {
930  if (!$this->_customerId) {
931  return $this;
932  }
933 
934  $isRequested = $this->_isBARequested || $this->_quote->getPayment()
935  ->getAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT);
936 
937  if (!($this->_config->getValue('allow_ba_signup') == PaypalConfig::EC_BA_SIGNUP_AUTO
938  || $isRequested && $this->_config->shouldAskToCreateBillingAgreement())
939  ) {
940  return $this;
941  }
942 
943  if (!$this->_agreementFactory->create()->needToCreateForCustomer($this->_customerId)) {
944  return $this;
945  }
946  $this->_getApi()->setBillingType($this->_getApi()->getBillingAgreementType());
947  return $this;
948  }

◆ _setExportedAddressData()

_setExportedAddressData (   $address,
  $exportedAddress 
)
protected

Sets address data from exported address

Parameters
Address$address
array$exportedAddress
Returns
void

Definition at line 913 of file Checkout.php.

914  {
915  foreach ($exportedAddress->getExportedKeys() as $key) {
916  $data = $exportedAddress->getData($key);
917  if (!empty($data)) {
918  $address->setDataUsingMethod($key, $data);
919  }
920  }
921  }
$address
Definition: customer.php:38

◆ _setRedirectUrl()

_setRedirectUrl (   $button,
  $token 
)
protected

Create payment redirect url

Parameters
bool | null$button
string$token
Returns
void

Definition at line 1098 of file Checkout.php.

1099  {
1100  $this->_redirectUrl = ($button && !$this->_taxData->getConfig()->priceIncludesTax())
1101  ? $this->_config->getExpressCheckoutStartUrl($token)
1102  : $this->_config->getPayPalBasicStartUrl($token);
1103  }

◆ canSkipOrderReviewStep()

canSkipOrderReviewStep ( )

Check whether system can skip order review page before placing order

Returns
bool

Definition at line 596 of file Checkout.php.

597  {
598  $isOnepageCheckout = !$this->_quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_BUTTON);
599  return $this->_config->isOrderReviewStepDisabled() && $isOnepageCheckout;
600  }

◆ cmpShippingOptions()

static cmpShippingOptions ( DataObject  $option1,
DataObject  $option2 
)
staticprotected

Compare two shipping options based on their amounts

This function is used as a callback comparison function in shipping options sorting process

See also
self::_prepareShippingOptions()
Parameters
\Magento\Framework\DataObject$option1
\Magento\Framework\DataObject$option2
Returns
int

Definition at line 1057 of file Checkout.php.

1058  {
1059  if ($option1->getAmount() == $option2->getAmount()) {
1060  return 0;
1061  }
1062  return ($option1->getAmount() < $option2->getAmount()) ? -1 : 1;
1063  }

◆ getBillingAgreement()

getBillingAgreement ( )

Get created billing agreement

Returns
\Magento\Paypal\Model\Billing\Agreement|null

Definition at line 871 of file Checkout.php.

◆ getCheckoutMethod()

getCheckoutMethod ( )

Get checkout method

Returns
string

Definition at line 891 of file Checkout.php.

892  {
893  if ($this->getCustomerSession()->isLoggedIn()) {
894  return \Magento\Checkout\Model\Type\Onepage::METHOD_CUSTOMER;
895  }
896  if (!$this->_quote->getCheckoutMethod()) {
897  if ($this->_checkoutData->isAllowedGuestCheckout($this->_quote)) {
898  $this->_quote->setCheckoutMethod(\Magento\Checkout\Model\Type\Onepage::METHOD_GUEST);
899  } else {
900  $this->_quote->setCheckoutMethod(\Magento\Checkout\Model\Type\Onepage::METHOD_REGISTER);
901  }
902  }
903  return $this->_quote->getCheckoutMethod();
904  }

◆ getCheckoutShortcutImageUrl()

getCheckoutShortcutImageUrl ( )

Checkout with PayPal image URL getter

Spares API calls of getting "pal" variable, by putting it into cache per store view

Returns
string

Definition at line 376 of file Checkout.php.

377  {
378  // get "pal" thing from cache or lookup it via API
379  $pal = null;
380  if ($this->_config->areButtonsDynamic()) {
381  $cacheId = self::PAL_CACHE_ID . $this->_storeManager->getStore()->getId();
382  $pal = $this->_configCacheType->load($cacheId);
383  if (self::PAL_CACHE_ID == $pal) {
384  $pal = null;
385  } elseif (!$pal) {
386  $pal = null;
387  try {
388  $this->_getApi()->callGetPalDetails();
389  $pal = $this->_getApi()->getPal();
390  $this->_configCacheType->save($pal, $cacheId);
391  } catch (\Exception $e) {
392  $this->_configCacheType->save(self::PAL_CACHE_ID, $cacheId);
393  $this->_logger->critical($e);
394  }
395  }
396  }
397 
398  return $this->_config->getExpressCheckoutShortcutImageUrl(
399  $this->_localeResolver->getLocale(),
400  $this->_quote->getBaseGrandTotal(),
401  $pal
402  );
403  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17

◆ getCustomerSession()

getCustomerSession ( )

Get customer session object

Returns
\Magento\Customer\Model\Session

Definition at line 1110 of file Checkout.php.

1111  {
1112  return $this->_customerSession;
1113  }

◆ getOrder()

getOrder ( )

Return order

Returns
\Magento\Sales\Model\Order

Definition at line 881 of file Checkout.php.

882  {
883  return $this->_order;
884  }

◆ getRedirectUrl()

getRedirectUrl ( )

Determine whether redirect somewhere specifically is required

Returns
string

Definition at line 861 of file Checkout.php.

862  {
863  return $this->_redirectUrl;
864  }

◆ getShippingOptionsCallbackResponse()

getShippingOptionsCallbackResponse ( array  $request)

Return callback response with shipping options

Parameters
array$request
Returns
string
Exceptions

Definition at line 726 of file Checkout.php.

727  {
728  $debugData = ['request' => $request, 'response' => []];
729 
730  try {
731  // obtain addresses
732  $address = $this->_getApi()->prepareShippingOptionsCallbackAddress($request);
733  $quoteAddress = $this->_quote->getShippingAddress();
734 
735  // compare addresses, calculate shipping rates and prepare response
736  $options = [];
737  if ($address && $quoteAddress && !$this->_quote->getIsVirtual()) {
738  foreach ($address->getExportedKeys() as $key) {
739  $quoteAddress->setDataUsingMethod($key, $address->getData($key));
740  }
741  $quoteAddress->setCollectShippingRates(true);
742  $this->totalsCollector->collectAddressTotals($this->_quote, $quoteAddress);
743  $options = $this->_prepareShippingOptions($quoteAddress, false, true);
744  }
745  $response = $this->_getApi()->setShippingOptions($options)->formatShippingOptionsCallback();
746 
747  // log request and response
748  $debugData['response'] = $response;
749  $this->_logger->debug(var_export($debugData, true));
750  return $response;
751  } catch (\Exception $e) {
752  $this->_logger->debug(var_export($debugData, true));
753  throw $e;
754  }
755  }
$response
Definition: 404.php:11
_prepareShippingOptions(Address $address, $mayReturnEmpty=false, $calculateTax=false)
Definition: Checkout.php:976
$address
Definition: customer.php:38

◆ place()

place (   $token,
  $shippingMethodCode = null 
)

Place the order when customer returned from PayPal until this moment all quote data must be valid.

Parameters
string$token
string | null$shippingMethodCode
Returns
void @SuppressWarnings(PHPMD.CyclomaticComplexity) @SuppressWarnings(PHPMD.NPathComplexity)

Definition at line 791 of file Checkout.php.

792  {
793  if ($shippingMethodCode) {
794  $this->updateShippingMethod($shippingMethodCode);
795  }
796 
797  if ($this->getCheckoutMethod() == \Magento\Checkout\Model\Type\Onepage::METHOD_GUEST) {
798  $this->prepareGuestQuote();
799  }
800 
801  $this->ignoreAddressValidation();
802  $this->_quote->collectTotals();
803  $order = $this->quoteManagement->submit($this->_quote);
804 
805  if (!$order) {
806  return;
807  }
808 
809  // commence redirecting to finish payment, if paypal requires it
810  if ($order->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_REDIRECT)) {
811  $this->_redirectUrl = $this->_config->getExpressCheckoutCompleteUrl($token);
812  }
813 
814  switch ($order->getState()) {
815  // even after placement paypal can disallow to authorize/capture, but will wait until bank transfers money
816  case \Magento\Sales\Model\Order::STATE_PENDING_PAYMENT:
817  // TODO
818  break;
819  // regular placement, when everything is ok
820  case \Magento\Sales\Model\Order::STATE_PROCESSING:
821  case \Magento\Sales\Model\Order::STATE_COMPLETE:
822  case \Magento\Sales\Model\Order::STATE_PAYMENT_REVIEW:
823  try {
824  if (!$order->getEmailSent()) {
825  $this->orderSender->send($order);
826  }
827  } catch (\Exception $e) {
828  $this->_logger->critical($e);
829  }
830  $this->_checkoutSession->start();
831  break;
832  default:
833  break;
834  }
835  $this->_order = $order;
836  }
$order
Definition: order.php:55

◆ prepareGiropayUrls()

prepareGiropayUrls (   $successUrl,
  $cancelUrl,
  $pendingUrl 
)

Setter that enables giropay redirects flow

Parameters
string$successUrl- payment success result
string$cancelUrl- payment cancellation result
string$pendingUrl- pending payment result
Returns
$this

Definition at line 413 of file Checkout.php.

414  {
415  $this->_giropayUrls = [$successUrl, $cancelUrl, $pendingUrl];
416  return $this;
417  }

◆ prepareGuestQuote()

prepareGuestQuote ( )
protected

Prepare quote for guest checkout order submit

Returns
$this

Definition at line 1152 of file Checkout.php.

1153  {
1155  $quote->setCustomerId(null)
1156  ->setCustomerEmail($quote->getBillingAddress()->getEmail())
1157  ->setCustomerIsGuest(true)
1158  ->setCustomerGroupId(\Magento\Customer\Model\Group::NOT_LOGGED_IN_ID);
1159  return $this;
1160  }
$quote

◆ prepareOrderReview()

prepareOrderReview (   $token = null)

Check whether order review has enough data to initialize

Parameters
string | null$token
Returns
void
Exceptions

Definition at line 702 of file Checkout.php.

703  {
704  $payment = $this->_quote->getPayment();
705  if (!$payment || !$payment->getAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_PAYER_ID)) {
706  throw new \Magento\Framework\Exception\LocalizedException(__('A payer is not identified.'));
707  }
708  $this->_quote->setMayEditShippingAddress(
709  1 != $this->_quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_SHIPPING_OVERRIDDEN)
710  );
711  $this->_quote->setMayEditShippingMethod(
712  '' == $this->_quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_SHIPPING_METHOD)
713  );
714  $this->ignoreAddressValidation();
715  $this->_quote->collectTotals();
716  $this->quoteRepository->save($this->_quote);
717  }
__()
Definition: __.php:13
$payment
Definition: order.php:17

◆ returnFromPaypal()

returnFromPaypal (   $token)

Update quote when returned from PayPal

Rewrite billing address by paypal, save old billing address for new customer, and export shipping address in case address absence

Parameters
string$token
Returns
void @SuppressWarnings(PHPMD.CyclomaticComplexity)

Definition at line 612 of file Checkout.php.

613  {
614  $this->_getApi()
615  ->setToken($token)
616  ->callGetExpressCheckoutDetails();
618 
619  $this->ignoreAddressValidation();
620 
621  // check if we came from the Express Checkout button
622  $isButton = (bool)$quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_BUTTON);
623 
624  // import shipping address
625  $exportedShippingAddress = $this->_getApi()->getExportedShippingAddress();
626  if (!$quote->getIsVirtual()) {
627  $shippingAddress = $quote->getShippingAddress();
628  if ($shippingAddress) {
629  if ($exportedShippingAddress && $isButton) {
630  $this->_setExportedAddressData($shippingAddress, $exportedShippingAddress);
631  // PayPal doesn't provide detailed shipping info: prefix, middlename, lastname, suffix
632  $shippingAddress->setPrefix(null);
633  $shippingAddress->setMiddlename(null);
634  $shippingAddress->setLastname(null);
635  $shippingAddress->setSuffix(null);
636  $shippingAddress->setCollectShippingRates(true);
637  $shippingAddress->setSameAsBilling(0);
638  }
639 
640  // import shipping method
641  $code = '';
642  if ($this->_getApi()->getShippingRateCode()) {
643  $code = $this->_matchShippingMethodCode($shippingAddress, $this->_getApi()->getShippingRateCode());
644  if ($code) {
645  // possible bug of double collecting rates :-/
646  $shippingAddress->setShippingMethod($code)->setCollectShippingRates(true);
647  }
648  }
649  $quote->getPayment()->setAdditionalInformation(
650  self::PAYMENT_INFO_TRANSPORT_SHIPPING_METHOD,
651  $code
652  );
653  }
654  }
655 
656  // import billing address
657  $requireBillingAddress = (int)$this->_config->getValue(
658  'requireBillingAddress'
660 
661  if ($isButton && !$requireBillingAddress && !$quote->isVirtual()) {
663  $billingAddress->unsAddressId()->unsAddressType()->setCustomerAddressId(null);
664  $data = $billingAddress->getData();
665  $data['save_in_address_book'] = 0;
666  $quote->getBillingAddress()->addData($data);
667  $quote->getShippingAddress()->setSameAsBilling(1);
668  } else {
669  $billingAddress = $quote->getBillingAddress()->setCustomerAddressId(null);
670  }
671  $exportedBillingAddress = $this->_getApi()->getExportedBillingAddress();
672 
673  // Since country is required field for billing and shipping address,
674  // we consider the address information to be empty if country is empty.
675  $isEmptyAddress = ($billingAddress->getCountryId() === null);
676 
677  if ($requireBillingAddress || $isEmptyAddress) {
678  $this->_setExportedAddressData($billingAddress, $exportedBillingAddress);
679  }
680  $billingAddress->setCustomerNote($exportedBillingAddress->getData('note'));
681  $quote->setBillingAddress($billingAddress);
682  $quote->setCheckoutMethod($this->getCheckoutMethod());
683 
684  // import payment info
685  $payment = $quote->getPayment();
686  $payment->setMethod($this->_methodType);
687  $this->_paypalInfo->importToPayment($this->_getApi(), $payment);
688  $payment->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_PAYER_ID, $this->_getApi()->getPayerId())
689  ->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_TOKEN, $token);
690  $quote->collectTotals();
691  $this->quoteRepository->save($quote);
692  }
$billingAddress
Definition: order.php:25
$quote
$shippingAddress
Definition: order.php:40
$payment
Definition: order.php:17
_matchShippingMethodCode(Address $address, $selectedCode)
Definition: Checkout.php:1076
_setExportedAddressData($address, $exportedAddress)
Definition: Checkout.php:913
$code
Definition: info.phtml:12

◆ setCustomerData()

setCustomerData ( CustomerDataObject  $customerData)

Setter for customer

Parameters
CustomerDataObject$customerData
Returns
$this

Definition at line 449 of file Checkout.php.

450  {
451  $this->_quote->assignCustomer($customerData);
452  $this->_customerId = $customerData->getId();
453  return $this;
454  }
$customerData

◆ setCustomerWithAddressChange()

setCustomerWithAddressChange ( CustomerDataObject  $customerData,
  $billingAddress = null,
  $shippingAddress = null 
)

Setter for customer with billing and shipping address changing ability

Parameters
CustomerDataObject$customerData
Address | null$billingAddress
Address | null$shippingAddress
Returns
$this

Definition at line 464 of file Checkout.php.

468  {
469  $this->_quote->assignCustomerWithAddressChange($customerData, $billingAddress, $shippingAddress);
470  $this->_customerId = $customerData->getId();
471  return $this;
472  }
$customerData
$billingAddress
Definition: order.php:25
$shippingAddress
Definition: order.php:40

◆ setIsBillingAgreementRequested()

setIsBillingAgreementRequested (   $flag)

Set create billing agreement flag

Parameters
bool$flag
Returns
$this

Definition at line 425 of file Checkout.php.

426  {
427  $this->_isBARequested = $flag;
428  return $this;
429  }

◆ setIsBml()

setIsBml (   $isBml)

Set flag that forces to use BillMeLater

Parameters
bool$isBml
Returns
$this

Definition at line 437 of file Checkout.php.

438  {
439  $this->_isBml = $isBml;
440  return $this;
441  }

◆ updateShippingMethod()

updateShippingMethod (   $methodCode)

Set shipping method to quote, if needed

Parameters
string$methodCode
Returns
void

Definition at line 763 of file Checkout.php.

764  {
765  $shippingAddress = $this->_quote->getShippingAddress();
766  if (!$this->_quote->getIsVirtual() && $shippingAddress) {
767  if ($methodCode != $shippingAddress->getShippingMethod()) {
768  $this->ignoreAddressValidation();
769  $shippingAddress->setShippingMethod($methodCode)->setCollectShippingRates(true);
770  $cartExtension = $this->_quote->getExtensionAttributes();
771  if ($cartExtension && $cartExtension->getShippingAssignments()) {
772  $cartExtension->getShippingAssignments()[0]
773  ->getShipping()
774  ->setMethod($methodCode);
775  }
776  $this->_quote->collectTotals();
777  $this->quoteRepository->save($this->_quote);
778  }
779  }
780  }
$shippingAddress
Definition: order.php:40

Field Documentation

◆ $_accountManagement

$_accountManagement
protected

Definition at line 242 of file Checkout.php.

◆ $_agreementFactory

$_agreementFactory
protected

Definition at line 217 of file Checkout.php.

◆ $_api

$_api
protected

Definition at line 69 of file Checkout.php.

◆ $_apiType

$_apiType = \Magento\Paypal\Model\Api\Nvp::class
protected

Definition at line 76 of file Checkout.php.

◆ $_apiTypeFactory

$_apiTypeFactory
protected

Definition at line 222 of file Checkout.php.

◆ $_billingAgreement

$_billingAgreement
protected

Definition at line 144 of file Checkout.php.

◆ $_cartFactory

$_cartFactory
protected

Definition at line 207 of file Checkout.php.

◆ $_checkoutData

$_checkoutData
protected

Definition at line 163 of file Checkout.php.

◆ $_checkoutOnepageFactory

$_checkoutOnepageFactory
protected

Definition at line 212 of file Checkout.php.

◆ $_checkoutRedirectUrl

$_checkoutRedirectUrl = ''
protected

Definition at line 104 of file Checkout.php.

◆ $_checkoutSession

$_checkoutSession
protected

Definition at line 232 of file Checkout.php.

◆ $_config

$_config
protected

Definition at line 62 of file Checkout.php.

◆ $_configCacheType

$_configCacheType
protected

Definition at line 156 of file Checkout.php.

◆ $_coreUrl

$_coreUrl
protected

Definition at line 202 of file Checkout.php.

◆ $_customerId

$_customerId
protected

Definition at line 137 of file Checkout.php.

◆ $_customerRepository

$_customerRepository
protected

Definition at line 237 of file Checkout.php.

◆ $_customerSession

$_customerSession
protected

Definition at line 109 of file Checkout.php.

◆ $_customerUrl

$_customerUrl
protected

Definition at line 177 of file Checkout.php.

◆ $_encryptor

$_encryptor
protected

Definition at line 247 of file Checkout.php.

◆ $_giropayUrls

$_giropayUrls = []
protected

Definition at line 116 of file Checkout.php.

◆ $_isBARequested

$_isBARequested = false
protected

Definition at line 123 of file Checkout.php.

◆ $_isBml

$_isBml = false
protected

Definition at line 130 of file Checkout.php.

◆ $_localeResolver

$_localeResolver
protected

Definition at line 187 of file Checkout.php.

◆ $_logger

$_logger
protected

Definition at line 182 of file Checkout.php.

◆ $_messageManager

$_messageManager
protected

Definition at line 252 of file Checkout.php.

◆ $_methodType

$_methodType = PaypalConfig::METHOD_WPP_EXPRESS
protected

Definition at line 83 of file Checkout.php.

◆ $_objectCopyService

$_objectCopyService
protected

Definition at line 227 of file Checkout.php.

◆ $_order

$_order
protected

Definition at line 151 of file Checkout.php.

◆ $_paypalInfo

$_paypalInfo
protected

Definition at line 192 of file Checkout.php.

◆ $_pendingPaymentMessage

$_pendingPaymentMessage = ''
protected

Definition at line 97 of file Checkout.php.

◆ $_quote

$_quote
protected

Definition at line 55 of file Checkout.php.

◆ $_redirectUrl

$_redirectUrl = ''
protected

Definition at line 90 of file Checkout.php.

◆ $_storeManager

$_storeManager
protected

Definition at line 197 of file Checkout.php.

◆ $_taxData

$_taxData
protected

Definition at line 170 of file Checkout.php.

◆ $orderSender

$orderSender
protected

Definition at line 257 of file Checkout.php.

◆ $quoteManagement

$quoteManagement
protected

Definition at line 267 of file Checkout.php.

◆ $quoteRepository

$quoteRepository
protected

Definition at line 262 of file Checkout.php.

◆ $totalsCollector

$totalsCollector
protected

Definition at line 272 of file Checkout.php.

◆ PAL_CACHE_ID

const PAL_CACHE_ID = 'paypal_express_checkout_pal'

Definition at line 32 of file Checkout.php.

◆ PAYMENT_INFO_BUTTON

const PAYMENT_INFO_BUTTON = 'button'

Definition at line 50 of file Checkout.php.

◆ PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT

const PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT = 'paypal_ec_create_ba'

Definition at line 43 of file Checkout.php.

◆ PAYMENT_INFO_TRANSPORT_PAYER_ID

const PAYMENT_INFO_TRANSPORT_PAYER_ID = 'paypal_express_checkout_payer_id'

Definition at line 41 of file Checkout.php.

◆ PAYMENT_INFO_TRANSPORT_REDIRECT

const PAYMENT_INFO_TRANSPORT_REDIRECT = 'paypal_express_checkout_redirect_required'

Definition at line 42 of file Checkout.php.

◆ PAYMENT_INFO_TRANSPORT_SHIPPING_METHOD

const PAYMENT_INFO_TRANSPORT_SHIPPING_METHOD = 'paypal_express_checkout_shipping_method'

Definition at line 40 of file Checkout.php.

◆ PAYMENT_INFO_TRANSPORT_SHIPPING_OVERRIDDEN

const PAYMENT_INFO_TRANSPORT_SHIPPING_OVERRIDDEN = 'paypal_express_checkout_shipping_overridden'

Definition at line 39 of file Checkout.php.

◆ PAYMENT_INFO_TRANSPORT_TOKEN

const PAYMENT_INFO_TRANSPORT_TOKEN = 'paypal_express_checkout_token'

Keys for passthrough variables in sales/quote_payment and sales/order_payment Uses additional_information as storage

Definition at line 38 of file Checkout.php.


The documentation for this class was generated from the following file: