CcForm.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Paypal\Block\Adminhtml\Payflowpro;
  7. use Magento\Checkout\Model\Session;
  8. use Magento\Framework\App\ObjectManager;
  9. use Magento\Framework\View\Element\Template\Context;
  10. use Magento\Payment\Helper\Data;
  11. use Magento\Payment\Model\Config;
  12. use Magento\Paypal\Model\Payflow\Transparent;
  13. use Magento\Store\Model\StoreManagerInterface;
  14. use Magento\Vault\Model\VaultPaymentInterface;
  15. class CcForm extends \Magento\Payment\Block\Transparent\Form
  16. {
  17. /**
  18. * @var string
  19. */
  20. protected $_template = 'Magento_Paypal::transparent/form.phtml';
  21. /**
  22. * @var Data
  23. */
  24. private $paymentDataHelper;
  25. /**
  26. * @param Context $context
  27. * @param Config $paymentConfig
  28. * @param Session $checkoutSession
  29. * @param array $data
  30. */
  31. public function __construct(
  32. Context $context,
  33. Config $paymentConfig,
  34. Session $checkoutSession,
  35. array $data = []
  36. ) {
  37. parent::__construct($context, $paymentConfig, $checkoutSession, $data);
  38. }
  39. /**
  40. * Check if vault enabled
  41. * @return bool
  42. */
  43. public function isVaultEnabled()
  44. {
  45. $storeId = $this->_storeManager->getStore()->getId();
  46. $vaultPayment = $this->getVaultPayment();
  47. return $vaultPayment->isActive($storeId);
  48. }
  49. /**
  50. * On backend this block does not have any conditional checks
  51. *
  52. * @return bool
  53. */
  54. protected function shouldRender()
  55. {
  56. return true;
  57. }
  58. /**
  59. * {inheritdoc}
  60. */
  61. protected function initializeMethod()
  62. {
  63. return;
  64. }
  65. /**
  66. * Get configured vault payment for PayflowPro
  67. * @return VaultPaymentInterface
  68. */
  69. private function getVaultPayment()
  70. {
  71. return $this->getPaymentDataHelper()->getMethodInstance(Transparent::CC_VAULT_CODE);
  72. }
  73. /**
  74. * Get payment data helper instance
  75. * @return Data
  76. * @deprecated 100.1.0
  77. */
  78. private function getPaymentDataHelper()
  79. {
  80. if ($this->paymentDataHelper === null) {
  81. $this->paymentDataHelper = ObjectManager::getInstance()->get(Data::class);
  82. }
  83. return $this->paymentDataHelper;
  84. }
  85. }