123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Paypal\Model\Payflow\Service\Request;
- use Magento\Framework\Math\Random;
- use Magento\Framework\DataObject;
- use Magento\Framework\UrlInterface;
- use Magento\Paypal\Model\Payflow\Transparent;
- use Magento\Paypal\Model\Payflowpro;
- use Magento\Quote\Model\Quote;
- /**
- * Class SecureToken
- */
- class SecureToken
- {
- /**
- * @var UrlInterface
- */
- private $url;
- /**
- * @var Random
- */
- private $mathRandom;
- /**
- * @var Transparent
- */
- private $transparent;
- /**
- * @param UrlInterface $url
- * @param Random $mathRandom
- * @param Transparent $transparent
- */
- public function __construct(
- UrlInterface $url,
- Random $mathRandom,
- Transparent $transparent
- ) {
- $this->url = $url;
- $this->mathRandom = $mathRandom;
- $this->transparent = $transparent;
- }
- /**
- * Get the Secure Token from Paypal for TR
- *
- * @param Quote $quote
- *
- * @return DataObject
- * @throws \Exception
- */
- public function requestToken(Quote $quote)
- {
- $this->transparent->setStore($quote->getStoreId());
- $request = $this->transparent->buildBasicRequest();
- $request->setTrxtype(Payflowpro::TRXTYPE_AUTH_ONLY);
- $request->setVerbosity('HIGH');
- $request->setAmt(0);
- $request->setCreatesecuretoken('Y');
- $request->setSecuretokenid($this->mathRandom->getUniqueHash());
- $request->setReturnurl($this->url->getUrl('paypal/transparent/response'));
- $request->setErrorurl($this->url->getUrl('paypal/transparent/response'));
- $request->setCancelurl($this->url->getUrl('paypal/transparent/cancel'));
- $request->setDisablereceipt('TRUE');
- $request->setSilenttran('TRUE');
- $this->transparent->fillCustomerContacts($quote, $request);
- $result = $this->transparent->postRequest($request, $this->transparent->getConfig());
- return $result;
- }
- }
|