Skip to content

Commit 3d363dc

Browse files
committed
Magento2PG
1 parent 6500c27 commit 3d363dc

File tree

21 files changed

+898
-0
lines changed

21 files changed

+898
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace BlueHorse\Payu\Block\Form;
7+
8+
/**
9+
* Block for Bank Transfer payment method form
10+
*/
11+
class Payu extends \Magento\OfflinePayments\Block\Form\AbstractInstruction
12+
{
13+
/**
14+
* Bank transfer template
15+
*
16+
* @var string
17+
*/
18+
protected $_template = 'form/payu.phtml';
19+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace BlueHorse\Payu\Model;
7+
8+
use Magento\Checkout\Model\ConfigProviderInterface;
9+
use Magento\Framework\Escaper;
10+
use Magento\Payment\Helper\Data as PaymentHelper;
11+
12+
class InstructionsConfigProvider implements ConfigProviderInterface
13+
{
14+
/**
15+
* @var string[]
16+
*/
17+
18+
protected $methodCodes = [
19+
'payu'
20+
];
21+
22+
23+
/**
24+
* @var \Magento\Payment\Model\Method\AbstractMethod[]
25+
*/
26+
protected $methods = [];
27+
28+
/**
29+
* @var Escaper
30+
*/
31+
protected $escaper;
32+
33+
/**
34+
* @param PaymentHelper $paymentHelper
35+
* @param Escaper $escaper
36+
*/
37+
public function __construct(
38+
PaymentHelper $paymentHelper,
39+
Escaper $escaper
40+
) {
41+
$this->escaper = $escaper;
42+
foreach ($this->methodCodes as $code) {
43+
$this->methods[$code] = $paymentHelper->getMethodInstance($code);
44+
}
45+
}
46+
47+
/**
48+
* {@inheritdoc}
49+
*/
50+
public function getConfig()
51+
{
52+
$config = [];
53+
foreach ($this->methodCodes as $code) {
54+
if ($this->methods[$code]->isAvailable()) {
55+
$config['payment']['instructions'][$code] = $this->getInstructions($code);
56+
$config['payment']['redirectUrl'][$code] = $this->getMethodRedirectUrl($code);
57+
}
58+
}
59+
return $config;
60+
}
61+
62+
/**
63+
* Get instructions text from config
64+
*
65+
* @param string $code
66+
* @return string
67+
*/
68+
protected function getInstructions($code)
69+
{
70+
return nl2br($this->escaper->escapeHtml($this->methods[$code]->getInstructions()));
71+
}
72+
protected function getMethodRedirectUrl($code)
73+
{
74+
return $this->methods[$code]->getCheckoutRedirectUrl();
75+
}
76+
}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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

Comments
 (0)