ContextHelper.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Payment\Gateway\Helper;
  7. use Magento\Payment\Model\InfoInterface;
  8. /**
  9. * Shortcut for methods that can be used to verify payment context.
  10. * Usage of this class should be avoided. This class introduced for supporting backward compatibility.
  11. *
  12. * @api
  13. * @since 100.0.2
  14. */
  15. class ContextHelper
  16. {
  17. /**
  18. * Asserts is an Order payment
  19. *
  20. * @param InfoInterface $paymentInfo
  21. * @throws \LogicException
  22. * @return null
  23. */
  24. public static function assertOrderPayment(InfoInterface $paymentInfo)
  25. {
  26. if (!$paymentInfo instanceof \Magento\Sales\Api\Data\OrderPaymentInterface) {
  27. throw new \LogicException('Order payment should be provided.');
  28. }
  29. }
  30. /**
  31. * Asserts is an Quote payment
  32. *
  33. * @param InfoInterface $paymentInfo
  34. * @throws \LogicException
  35. * @return null
  36. */
  37. public static function assertQuotePayment(InfoInterface $paymentInfo)
  38. {
  39. if (!$paymentInfo instanceof \Magento\Quote\Api\Data\PaymentInterface) {
  40. throw new \LogicException('Quote payment should be provided.');
  41. }
  42. }
  43. }