GuestPaymentMethodManagement.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Quote\Model\GuestCart;
  7. use Magento\Quote\Api\PaymentMethodManagementInterface;
  8. use Magento\Quote\Api\GuestPaymentMethodManagementInterface;
  9. use Magento\Quote\Model\QuoteIdMask;
  10. use Magento\Quote\Model\QuoteIdMaskFactory;
  11. /**
  12. * Payment method management class for guest carts.
  13. */
  14. class GuestPaymentMethodManagement implements GuestPaymentMethodManagementInterface
  15. {
  16. /**
  17. * @var QuoteIdMaskFactory
  18. */
  19. protected $quoteIdMaskFactory;
  20. /**
  21. * @var PaymentMethodManagementInterface
  22. */
  23. protected $paymentMethodManagement;
  24. /**
  25. * Initialize dependencies.
  26. *
  27. * @param PaymentMethodManagementInterface $paymentMethodManagement
  28. * @param QuoteIdMaskFactory $quoteIdMaskFactory
  29. */
  30. public function __construct(
  31. PaymentMethodManagementInterface $paymentMethodManagement,
  32. QuoteIdMaskFactory $quoteIdMaskFactory
  33. ) {
  34. $this->quoteIdMaskFactory = $quoteIdMaskFactory;
  35. $this->paymentMethodManagement = $paymentMethodManagement;
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function set($cartId, \Magento\Quote\Api\Data\PaymentInterface $method)
  41. {
  42. /** @var $quoteIdMask QuoteIdMask */
  43. $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
  44. return $this->paymentMethodManagement->set($quoteIdMask->getQuoteId(), $method);
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. public function get($cartId)
  50. {
  51. /** @var $quoteIdMask QuoteIdMask */
  52. $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
  53. return $this->paymentMethodManagement->get($quoteIdMask->getQuoteId());
  54. }
  55. /**
  56. * {@inheritdoc}
  57. */
  58. public function getList($cartId)
  59. {
  60. /** @var $quoteIdMask QuoteIdMask */
  61. $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
  62. return $this->paymentMethodManagement->getList($quoteIdMask->getQuoteId());
  63. }
  64. }