InstantPurchaseOptionFactory.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\InstantPurchase\Model;
  7. use Magento\Customer\Model\Address;
  8. use Magento\Framework\ObjectManagerInterface;
  9. use Magento\Quote\Api\Data\ShippingMethodInterface;
  10. use Magento\Vault\Api\Data\PaymentTokenInterface;
  11. /**
  12. * Create instances of instant purchase option.
  13. *
  14. * @api
  15. * @since 100.2.0
  16. */
  17. class InstantPurchaseOptionFactory
  18. {
  19. /**
  20. * @var ObjectManagerInterface
  21. */
  22. private $objectManager;
  23. /**
  24. * InstantPurchaseOptionFactory constructor.
  25. * @param ObjectManagerInterface $objectManager
  26. */
  27. public function __construct(ObjectManagerInterface $objectManager)
  28. {
  29. $this->objectManager = $objectManager;
  30. }
  31. /**
  32. * Creates new instance.
  33. *
  34. * @param PaymentTokenInterface|null $paymentToken
  35. * @param Address|null $shippingAddress
  36. * @param Address|null $billingAddress
  37. * @param ShippingMethodInterface|null $shippingMethod
  38. * @return InstantPurchaseOption
  39. * @since 100.2.0
  40. */
  41. public function create(
  42. PaymentTokenInterface $paymentToken = null,
  43. Address $shippingAddress = null,
  44. Address $billingAddress = null,
  45. ShippingMethodInterface $shippingMethod = null
  46. ): InstantPurchaseOption {
  47. return $this->objectManager->create(InstantPurchaseOption::class, [
  48. 'paymentToken' => $paymentToken,
  49. 'shippingAddress' => $shippingAddress,
  50. 'billingAddress' => $billingAddress,
  51. 'shippingMethod' => $shippingMethod,
  52. ]);
  53. }
  54. /**
  55. * Creates new empty instance (no option available).
  56. *
  57. * @return InstantPurchaseOption
  58. * @since 100.2.0
  59. */
  60. public function createDisabledOption(): InstantPurchaseOption
  61. {
  62. return $this->create(null, null, null, null);
  63. }
  64. }