Agreement.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Paypal\Block\Payment\Form\Billing;
  7. /**
  8. * Paypal Billing Agreement form block
  9. */
  10. class Agreement extends \Magento\Payment\Block\Form
  11. {
  12. /**
  13. * @var string
  14. */
  15. protected $_template = 'Magento_Paypal::payment/form/billing/agreement.phtml';
  16. /**
  17. * @var \Magento\Paypal\Model\Billing\AgreementFactory
  18. */
  19. protected $_agreementFactory;
  20. /**
  21. * @param \Magento\Framework\View\Element\Template\Context $context
  22. * @param \Magento\Paypal\Model\Billing\AgreementFactory $agreementFactory
  23. * @param array $data
  24. */
  25. public function __construct(
  26. \Magento\Framework\View\Element\Template\Context $context,
  27. \Magento\Paypal\Model\Billing\AgreementFactory $agreementFactory,
  28. array $data = []
  29. ) {
  30. $this->_agreementFactory = $agreementFactory;
  31. parent::__construct($context, $data);
  32. $this->_isScopePrivate = true;
  33. }
  34. /**
  35. * @return void
  36. */
  37. protected function _construct()
  38. {
  39. parent::_construct();
  40. $this->setTransportName(
  41. \Magento\Paypal\Model\Payment\Method\Billing\AbstractAgreement::TRANSPORT_BILLING_AGREEMENT_ID
  42. );
  43. }
  44. /**
  45. * Retrieve available customer billing agreements
  46. *
  47. * @return array
  48. */
  49. public function getBillingAgreements()
  50. {
  51. $data = [];
  52. /** @var \Magento\Quote\Model\Quote $quote */
  53. $quote = $this->getParentBlock()->getQuote();
  54. if (!$quote || !$quote->getCustomerId()) {
  55. return $data;
  56. }
  57. $collection = $this->_agreementFactory->create()->getAvailableCustomerBillingAgreements(
  58. $quote->getCustomerId()
  59. );
  60. foreach ($collection as $item) {
  61. $data[$item->getId()] = $item->getReferenceId();
  62. }
  63. return $data;
  64. }
  65. }