SecureToken.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Paypal\Model\Payflow\Service\Request;
  7. use Magento\Framework\Math\Random;
  8. use Magento\Framework\DataObject;
  9. use Magento\Framework\UrlInterface;
  10. use Magento\Paypal\Model\Payflow\Transparent;
  11. use Magento\Paypal\Model\Payflowpro;
  12. use Magento\Quote\Model\Quote;
  13. /**
  14. * Class SecureToken
  15. */
  16. class SecureToken
  17. {
  18. /**
  19. * @var UrlInterface
  20. */
  21. private $url;
  22. /**
  23. * @var Random
  24. */
  25. private $mathRandom;
  26. /**
  27. * @var Transparent
  28. */
  29. private $transparent;
  30. /**
  31. * @param UrlInterface $url
  32. * @param Random $mathRandom
  33. * @param Transparent $transparent
  34. */
  35. public function __construct(
  36. UrlInterface $url,
  37. Random $mathRandom,
  38. Transparent $transparent
  39. ) {
  40. $this->url = $url;
  41. $this->mathRandom = $mathRandom;
  42. $this->transparent = $transparent;
  43. }
  44. /**
  45. * Get the Secure Token from Paypal for TR
  46. *
  47. * @param Quote $quote
  48. *
  49. * @return DataObject
  50. * @throws \Exception
  51. */
  52. public function requestToken(Quote $quote)
  53. {
  54. $this->transparent->setStore($quote->getStoreId());
  55. $request = $this->transparent->buildBasicRequest();
  56. $request->setTrxtype(Payflowpro::TRXTYPE_AUTH_ONLY);
  57. $request->setVerbosity('HIGH');
  58. $request->setAmt(0);
  59. $request->setCreatesecuretoken('Y');
  60. $request->setSecuretokenid($this->mathRandom->getUniqueHash());
  61. $request->setReturnurl($this->url->getUrl('paypal/transparent/response'));
  62. $request->setErrorurl($this->url->getUrl('paypal/transparent/response'));
  63. $request->setCancelurl($this->url->getUrl('paypal/transparent/cancel'));
  64. $request->setDisablereceipt('TRUE');
  65. $request->setSilenttran('TRUE');
  66. $this->transparent->fillCustomerContacts($quote, $request);
  67. $result = $this->transparent->postRequest($request, $this->transparent->getConfig());
  68. return $result;
  69. }
  70. }