Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ReturnWizard.php
Go to the documentation of this file.
1 <?php
8 
10 
12 {
18  public function execute()
19  {
21  $agreement = $this->_objectManager->create(\Magento\Paypal\Model\Billing\Agreement::class);
22  $paymentCode = $this->getRequest()->getParam('payment_method');
23  $token = $this->getRequest()->getParam('token');
24 
26  $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
27 
28  if ($token && $paymentCode) {
29  try {
30  $agreement->setStoreId(
31  $this->_objectManager->get(\Magento\Store\Model\StoreManager::class)->getStore()->getId()
32  )->setToken(
33  $token
34  )->setMethodCode(
35  $paymentCode
36  )->setCustomerId(
37  $this->_getSession()->getCustomerId()
38  )->place();
39 
40  $this->messageManager->addSuccessMessage(
41  __('The billing agreement "%1" has been created.', $agreement->getReferenceId())
42  );
43  return $resultRedirect->setPath('*/*/view', ['agreement' => $agreement->getId()]);
44  } catch (\Magento\Framework\Exception\LocalizedException $e) {
45  $this->messageManager->addExceptionMessage(
46  $e,
47  $e->getMessage()
48  );
49  } catch (\Exception $e) {
50  $this->messageManager->addExceptionMessage(
51  $e,
52  __('We couldn\'t finish the billing agreement wizard.')
53  );
54  }
55 
56  return $resultRedirect->setPath('*/*/index');
57  }
58  }
59 }
__()
Definition: __.php:13