|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2015 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace BlueHorse\Payu\Model; |
| 8 | +use Magento\Framework\Pricing\PriceCurrencyInterface; |
| 9 | +class Payu extends \Magento\Payment\Model\Method\AbstractMethod |
| 10 | +{ |
| 11 | + /** |
| 12 | + * Payment method code |
| 13 | + * @var string |
| 14 | + */ |
| 15 | + protected $_code ='payu'; |
| 16 | + |
| 17 | + /** |
| 18 | + * @var \Magento\Store\Model\StoreManagerInterface |
| 19 | + */ |
| 20 | + protected $_storeManager; |
| 21 | + |
| 22 | + /** |
| 23 | + * @var \Magento\Framework\UrlInterface |
| 24 | + */ |
| 25 | + protected $_urlBuilder; |
| 26 | + |
| 27 | + /** |
| 28 | + * @var \Magento\Paypal\Model\CartFactory |
| 29 | + */ |
| 30 | + protected $_cartFactory; |
| 31 | + |
| 32 | + /** |
| 33 | + * @var \Magento\Checkout\Model\Session |
| 34 | + */ |
| 35 | + protected $_checkoutSession; |
| 36 | + /** |
| 37 | + * Checkout payment form |
| 38 | + * @var string |
| 39 | + */ |
| 40 | + |
| 41 | + protected $priceCurrency; |
| 42 | + |
| 43 | + /** |
| 44 | + * @param \Magento\Framework\Model\Context $context |
| 45 | + * @param \Magento\Framework\Registry $registry |
| 46 | + * @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory |
| 47 | + * @param \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory |
| 48 | + * @param \Magento\Payment\Helper\Data $paymentData |
| 49 | + * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig |
| 50 | + * @param Logger $logger |
| 51 | + * @param PriceCurrencyInterface $priceCurrency |
| 52 | + * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource |
| 53 | + * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection |
| 54 | + * @param array $data |
| 55 | + * @SuppressWarnings(PHPMD.ExcessiveParameterList) |
| 56 | + */ |
| 57 | + public function __construct( |
| 58 | + \Magento\Framework\Model\Context $context, |
| 59 | + \Magento\Framework\Registry $registry, |
| 60 | + \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, |
| 61 | + \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory, |
| 62 | + \Magento\Payment\Helper\Data $paymentData, |
| 63 | + \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, |
| 64 | + \Magento\Payment\Model\Method\Logger $logger, |
| 65 | + PriceCurrencyInterface $priceCurrency, |
| 66 | + \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, |
| 67 | + \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, |
| 68 | + \Magento\Checkout\Model\Session $checkoutSession, |
| 69 | + \Magento\Framework\UrlInterface $urlBuilder, |
| 70 | + \Magento\Store\Model\StoreManagerInterface $storeManager, |
| 71 | + array $data = [] |
| 72 | + ) { |
| 73 | + parent::__construct( |
| 74 | + $context, |
| 75 | + $registry, |
| 76 | + $extensionFactory, |
| 77 | + $customAttributeFactory, |
| 78 | + $paymentData, |
| 79 | + $scopeConfig, |
| 80 | + $logger, |
| 81 | + $resource, |
| 82 | + $resourceCollection, |
| 83 | + $data |
| 84 | + ); |
| 85 | + $this->priceCurrency = $priceCurrency; |
| 86 | + $this->_storeManager = $storeManager; |
| 87 | + $this->_urlBuilder = $urlBuilder; |
| 88 | + $this->_checkoutSession = $checkoutSession; |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * Check whether method is available |
| 93 | + * |
| 94 | + * @param \Magento\Quote\Api\Data\CartInterface|\Magento\Quote\Model\Quote|null $quote |
| 95 | + * @return bool |
| 96 | + */ |
| 97 | + public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null) |
| 98 | + { |
| 99 | + return parent::isAvailable( |
| 100 | + $quote |
| 101 | + ) && null !== $quote; |
| 102 | + } |
| 103 | + |
| 104 | + /** |
| 105 | + * Check whether method is enabled in config |
| 106 | + * |
| 107 | + * @param \Magento\Quote\Model\Quote|null $quote |
| 108 | + * @return bool |
| 109 | + */ |
| 110 | + public function isAvailableInConfig($quote = null) |
| 111 | + { |
| 112 | + return parent::isAvailable($quote); |
| 113 | + } |
| 114 | + |
| 115 | + |
| 116 | + /** |
| 117 | + * Checkout redirect URL getter for onepage checkout |
| 118 | + * |
| 119 | + * @return string |
| 120 | + */ |
| 121 | + public function getCheckoutRedirectUrl() |
| 122 | + { |
| 123 | + return $this->_urlBuilder->getUrl('payu/bml/start'); |
| 124 | + } |
| 125 | + |
| 126 | + |
| 127 | +} |
0 commit comments