123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Paypal\CustomerData;
- use Magento\Customer\CustomerData\SectionSourceInterface;
- use Magento\Customer\Helper\Session\CurrentCustomer;
- use Magento\Framework\Escaper;
- use Magento\Framework\UrlInterface;
- use Magento\Paypal\Helper\Data;
- use Magento\Paypal\Model\Config;
- use Magento\Paypal\Model\ConfigFactory;
- /**
- * BillingAgreement section
- */
- class BillingAgreement implements SectionSourceInterface
- {
- /**
- * @var CurrentCustomer
- */
- private $currentCustomer;
- /**
- * Paypal data
- *
- * @var Data
- */
- private $paypalData;
- /**
- * @var Config
- */
- private $config;
- /**
- * Url Builder
- *
- * @var UrlInterface
- */
- private $urlBuilder;
- /**
- * Escaper
- *
- * @var Escaper
- */
- private $escaper;
- /**
- * Start express action
- *
- * @var string
- */
- private $startAction = 'paypal/express/start/button/1';
- /**
- * @param CurrentCustomer $currentCustomer
- * @param Data $paypalData
- * @param ConfigFactory $paypalConfigFactory
- * @param UrlInterface $urlBuilder
- * @param Escaper $escaper
- */
- public function __construct(
- CurrentCustomer $currentCustomer,
- Data $paypalData,
- ConfigFactory $paypalConfigFactory,
- UrlInterface $urlBuilder,
- Escaper $escaper
- ) {
- $this->currentCustomer = $currentCustomer;
- $this->paypalData = $paypalData;
- $this->urlBuilder = $urlBuilder;
- $this->escaper = $escaper;
- $this->config = $paypalConfigFactory->create();
- $this->config->setMethod(Config::METHOD_EXPRESS);
- }
- /**
- * @inheritdoc
- */
- public function getSectionData()
- {
- $customerId = $this->currentCustomer->getCustomerId();
- if ($this->paypalData->shouldAskToCreateBillingAgreement($this->config, $customerId)) {
- return [
- 'askToCreate' => true,
- 'confirmUrl' => $this->escaper->escapeUrl(
- $this->urlBuilder->getUrl(
- $this->startAction,
- [\Magento\Paypal\Model\Express\Checkout::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT => 1]
- )
- ),
- 'confirmMessage' => $this->escaper->escapeHtml(
- __('Would you like to sign a billing agreement to streamline further purchases with PayPal?')
- )
- ];
- }
- return [];
- }
- }
|