Form.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Payment\Block;
  7. use Magento\Payment\Model\MethodInterface;
  8. /**
  9. * Payment method form base block
  10. *
  11. * @api
  12. * @since 100.0.2
  13. */
  14. class Form extends \Magento\Framework\View\Element\Template
  15. {
  16. /**
  17. * Retrieve payment method model
  18. *
  19. * @return MethodInterface
  20. * @throws \Magento\Framework\Exception\LocalizedException
  21. */
  22. public function getMethod()
  23. {
  24. $method = $this->getData('method');
  25. if (!$method instanceof MethodInterface) {
  26. throw new \Magento\Framework\Exception\LocalizedException(
  27. __('We cannot retrieve the payment method model object.')
  28. );
  29. }
  30. return $method;
  31. }
  32. /**
  33. * Sets payment method instance to form
  34. *
  35. * @param MethodInterface $method
  36. * @return $this
  37. */
  38. public function setMethod(MethodInterface $method)
  39. {
  40. $this->setData('method', $method);
  41. return $this;
  42. }
  43. /**
  44. * Retrieve payment method code
  45. *
  46. * @return string
  47. */
  48. public function getMethodCode()
  49. {
  50. return $this->getMethod()->getCode();
  51. }
  52. /**
  53. * Retrieve field value data from payment info object
  54. *
  55. * @param string $field
  56. * @return mixed
  57. */
  58. public function getInfoData($field)
  59. {
  60. return $this->escapeHtml($this->getMethod()->getInfoInstance()->getData($field));
  61. }
  62. }