CountryProvider.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Payment\Model\Checks\CanUseForCountry;
  7. use Magento\Quote\Model\Quote;
  8. use Magento\Directory\Helper\Data as DirectoryHelper;
  9. /**
  10. * Select country which will be used for payment.
  11. *
  12. * This class may be extended if logic fo country selection should be modified.
  13. *
  14. * @api
  15. * @since 100.0.2
  16. */
  17. class CountryProvider
  18. {
  19. /**
  20. * @var DirectoryHelper
  21. */
  22. protected $directoryHelper;
  23. /**
  24. * @param DirectoryHelper $directoryHelper
  25. */
  26. public function __construct(DirectoryHelper $directoryHelper)
  27. {
  28. $this->directoryHelper = $directoryHelper;
  29. }
  30. /**
  31. * Get payment country
  32. *
  33. * @param Quote $quote
  34. * @return int
  35. */
  36. public function getCountry(Quote $quote)
  37. {
  38. $address = $quote->getBillingAddress() ? : $quote->getShippingAddress();
  39. return (!empty($address) && !empty($address->getCountry()))
  40. ? $address->getCountry()
  41. : $this->directoryHelper->getDefaultCountry();
  42. }
  43. }