Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BillingAgreement.php
Go to the documentation of this file.
1 <?php
7 
14 use Magento\Paypal\Model\ConfigFactory;
15 
20 {
24  private $currentCustomer;
25 
31  private $paypalData;
32 
36  private $config;
37 
43  private $urlBuilder;
44 
50  private $escaper;
51 
57  private $startAction = 'paypal/express/start/button/1';
58 
66  public function __construct(
67  CurrentCustomer $currentCustomer,
68  Data $paypalData,
69  ConfigFactory $paypalConfigFactory,
70  UrlInterface $urlBuilder,
71  Escaper $escaper
72  ) {
73  $this->currentCustomer = $currentCustomer;
74  $this->paypalData = $paypalData;
75  $this->urlBuilder = $urlBuilder;
76  $this->escaper = $escaper;
77  $this->config = $paypalConfigFactory->create();
78  $this->config->setMethod(Config::METHOD_EXPRESS);
79  }
80 
84  public function getSectionData()
85  {
86  $customerId = $this->currentCustomer->getCustomerId();
87  if ($this->paypalData->shouldAskToCreateBillingAgreement($this->config, $customerId)) {
88  return [
89  'askToCreate' => true,
90  'confirmUrl' => $this->escaper->escapeUrl(
91  $this->urlBuilder->getUrl(
92  $this->startAction,
93  [\Magento\Paypal\Model\Express\Checkout::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT => 1]
94  )
95  ),
96  'confirmMessage' => $this->escaper->escapeJs(
97  __('Would you like to sign a billing agreement to streamline further purchases with PayPal?')
98  )
99  ];
100  }
101 
102  return [];
103  }
104 }
__construct(CurrentCustomer $currentCustomer, Data $paypalData, ConfigFactory $paypalConfigFactory, UrlInterface $urlBuilder, Escaper $escaper)
__()
Definition: __.php:13