Skip to content

Commit 9708cd4

Browse files
committed
v1.0.1
* Minor bugfixes and improvements.
1 parent 143c725 commit 9708cd4

25 files changed

+148
-181
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ upload/
3535

3636
*/DS_STORE
3737
.DS_Store
38+
39+
.idea

Block/Payment.php

+89-85
Original file line numberDiff line numberDiff line change
@@ -37,94 +37,98 @@ public function __construct(
3737
public function getTemplateValues()
3838
{
3939

40-
if ($this->productMetadata->getVersion() >= 2.3 && $this->productMetadata->getVersion() < 2.4) {
41-
$order = $this->payment->getOrder();
42-
} else {
43-
$order_id = (int)$this->request->getParam('order_id');
44-
$nonce = (string)$this->request->getParam('nonce');
45-
$order = $this->orderRepository->get($order_id);
46-
}
47-
48-
$total = $order->getGrandTotal();
49-
$currencySymbol = $order->getOrderCurrencyCode();
50-
$metaData = $this->helper->getPaymentResponse($order->getQuoteId());
51-
52-
if (empty($metaData)) {
53-
throw new \Magento\Framework\Exception\AlreadyExistsException(
54-
__('You can only add one address per cryptocurrency')
55-
);
56-
}
57-
58-
$qrCodeSize = $this->scopeConfig->getValue('payment/blockbee/qrcode_size', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
59-
60-
$branding = $this->scopeConfig->getValue('payment/blockbee/show_branding', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
61-
62-
$metaData = json_decode($metaData, true);
63-
64-
if ($nonce != $metaData['blockbee_nonce']) {
65-
return false;
66-
}
67-
$cryptoValue = $metaData['blockbee_total'];
68-
$cryptoCoin = $metaData['blockbee_currency'];
69-
70-
if (isset($metaData['blockbee_address']) && !empty($metaData['blockbee_address'])) {
71-
$addressIn = $metaData['blockbee_address'];
72-
} else {
73-
/**
74-
* Makes request to API and generates all the payment data needed
75-
*/
76-
77-
$selected = $cryptoCoin;
78-
79-
$params = [
40+
try {
41+
if ($this->productMetadata->getVersion() >= 2.3 && $this->productMetadata->getVersion() < 2.4) {
42+
$order = $this->payment->getOrder();
43+
} else {
44+
$order_id = (int)$this->request->getParam('order_id');
45+
$nonce = (string)$this->request->getParam('nonce');
46+
$order = $this->orderRepository->get($order_id);
47+
}
48+
49+
$total = $order->getGrandTotal();
50+
$currencySymbol = $order->getOrderCurrencyCode();
51+
$metaData = $this->helper->getPaymentResponse($order->getQuoteId());
52+
53+
if (empty($metaData)) {
54+
throw new \Magento\Framework\Exception\AlreadyExistsException(
55+
__('You can only add one address per cryptocurrency')
56+
);
57+
}
58+
59+
$qrCodeSize = $this->scopeConfig->getValue('payment/blockbee/qrcode_size', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
60+
61+
$branding = $this->scopeConfig->getValue('payment/blockbee/show_branding', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
62+
63+
$metaData = json_decode($metaData, true);
64+
65+
if ($nonce != $metaData['blockbee_nonce']) {
66+
return false;
67+
}
68+
$cryptoValue = $metaData['blockbee_total'];
69+
$cryptoCoin = $metaData['blockbee_currency'];
70+
71+
if (isset($metaData['blockbee_address']) && !empty($metaData['blockbee_address'])) {
72+
$addressIn = $metaData['blockbee_address'];
73+
} else {
74+
/**
75+
* Makes request to API and generates all the payment data needed
76+
*/
77+
78+
$selected = $cryptoCoin;
79+
80+
$params = [
81+
'order_id' => $order->getId(),
82+
'nonce' => $metaData['blockbee_nonce'],
83+
];
84+
85+
$callbackUrl = $this->payment->getCallbackUrl();
86+
87+
$apiKey = $this->scopeConfig->getValue('payment/blockbee/api_key', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
88+
89+
$api = new BlockbeeHelper($selected, $apiKey, $callbackUrl, $params, true);
90+
$addressIn = $api->get_address();
91+
$qrCode = $api->get_qrcode('', $qrCodeSize);
92+
$qrCodeValue = $api->get_qrcode($cryptoValue, $qrCodeSize);
93+
$this->helper->updatePaymentData($order->getQuoteId(), 'blockbee_address', $addressIn);
94+
$this->helper->updatePaymentData($order->getQuoteId(), 'blockbee_qr_code_value', $qrCodeValue['qr_code']);
95+
$this->helper->updatePaymentData($order->getQuoteId(), 'blockbee_qr_code', $qrCode['qr_code']);
96+
$this->helper->updatePaymentData($order->getQuoteId(), 'blockbee_payment_url', $this->storeManager->getStore()->getUrl('blockbee/index/payment/order_id/' . $order->getId() . '/nonce/' . $metaData['blockbee_nonce']));
97+
98+
$metaData = json_decode($this->helper->getPaymentResponse($order->getQuoteId()), true);
99+
$this->mail->sendMail($order, $metaData);
100+
}
101+
102+
$ajaxParams = [
80103
'order_id' => $order->getId(),
81-
'nonce' => $metaData['blockbee_nonce'],
82104
];
83105

84-
$callbackUrl = $this->payment->getCallbackUrl();
85-
86-
$apiKey = $this->scopeConfig->getValue('payment/blockbee/api_key', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
87-
88-
$api = new BlockbeeHelper($selected, $apiKey, $callbackUrl, $params, true);
89-
$addressIn = $api->get_address();
90-
$qrCode = $api->get_qrcode('', $qrCodeSize);
91-
$qrCodeValue = $api->get_qrcode($cryptoValue, $qrCodeSize);
92-
$this->helper->updatePaymentData($order->getQuoteId(), 'blockbee_address', $addressIn);
93-
$this->helper->updatePaymentData($order->getQuoteId(), 'blockbee_qr_code_value', $qrCodeValue['qr_code']);
94-
$this->helper->updatePaymentData($order->getQuoteId(), 'blockbee_qr_code', $qrCode['qr_code']);
95-
$this->helper->updatePaymentData($order->getQuoteId(), 'blockbee_payment_url', $this->storeManager->getStore()->getUrl('blockbee/index/payment/order_id/' . $order->getId(). '/nonce/' . $metaData['blockbee_nonce']));
96-
97-
$metaData = json_decode($this->helper->getPaymentResponse($order->getQuoteId()), true);
98-
$this->mail->sendMail($order, $metaData);
106+
$ajaxUrl = $this->payment->getAjaxStatusUrl($ajaxParams);
107+
108+
$metaData = $this->helper->getPaymentResponse($order->getQuoteId());
109+
$metaData = json_decode($metaData, true);
110+
111+
return [
112+
'crypto_value' => floatval($cryptoValue),
113+
'currency_symbol' => $currencySymbol,
114+
'total' => $total,
115+
'address_in' => $addressIn,
116+
'crypto_coin' => $cryptoCoin,
117+
'ajax_url' => $ajaxUrl,
118+
'qrcode_size' => $qrCodeSize,
119+
'qrcode' => $metaData['blockbee_qr_code'],
120+
'qrcode_value' => $metaData['blockbee_qr_code_value'],
121+
'qrcode_default' => $this->scopeConfig->getValue('payment/blockbee/qrcode_default', \Magento\Store\Model\ScopeInterface::SCOPE_STORE),
122+
'show_branding' => $branding,
123+
'qr_code_setting' => $this->scopeConfig->getValue('payment/blockbee/qrcode_setting', \Magento\Store\Model\ScopeInterface::SCOPE_STORE),
124+
'order_timestamp' => strtotime($order->getCreatedAt()),
125+
'order_cancelation_timeout' => $this->scopeConfig->getValue('payment/blockbee/order_cancelation_timeout', \Magento\Store\Model\ScopeInterface::SCOPE_STORE),
126+
'refresh_value_interval' => $this->scopeConfig->getValue('payment/blockbee/refresh_value_interval', \Magento\Store\Model\ScopeInterface::SCOPE_STORE),
127+
'last_price_update' => $metaData['blockbee_last_price_update'],
128+
'min_tx' => $metaData['blockbee_min'],
129+
];
130+
} catch (\Exception $exception) {
131+
// Empty
99132
}
100-
101-
$ajaxParams = [
102-
'order_id' => $order->getId(),
103-
];
104-
105-
$ajaxUrl = $this->payment->getAjaxStatusUrl($ajaxParams);
106-
107-
$metaData = $this->helper->getPaymentResponse($order->getQuoteId());
108-
$metaData = json_decode($metaData, true);
109-
110-
return [
111-
'crypto_value' => floatval($cryptoValue),
112-
'currency_symbol' => $currencySymbol,
113-
'total' => $total,
114-
'address_in' => $addressIn,
115-
'crypto_coin' => $cryptoCoin,
116-
'ajax_url' => $ajaxUrl,
117-
'qrcode_size' => $qrCodeSize,
118-
'qrcode' => $metaData['blockbee_qr_code'],
119-
'qrcode_value' => $metaData['blockbee_qr_code_value'],
120-
'qrcode_default' => $this->scopeConfig->getValue('payment/blockbee/qrcode_default', \Magento\Store\Model\ScopeInterface::SCOPE_STORE),
121-
'show_branding' => $branding,
122-
'qr_code_setting' => $this->scopeConfig->getValue('payment/blockbee/qrcode_setting', \Magento\Store\Model\ScopeInterface::SCOPE_STORE),
123-
'order_timestamp' => strtotime($order->getCreatedAt()),
124-
'order_cancelation_timeout' => $this->scopeConfig->getValue('payment/blockbee/order_cancelation_timeout', \Magento\Store\Model\ScopeInterface::SCOPE_STORE),
125-
'refresh_value_interval' => $this->scopeConfig->getValue('payment/blockbee/refresh_value_interval', \Magento\Store\Model\ScopeInterface::SCOPE_STORE),
126-
'last_price_update' => $metaData['blockbee_last_price_update'],
127-
'min_tx' => $metaData['blockbee_min'],
128-
];
129133
}
130134
}

Cron/BlockbeeCronjob.php

-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ public function execute()
6565
$qrcode_size = $this->scopeConfig->getValue('payment/blockbee/qrcode_size');
6666

6767
if (!empty($metaData['blockbee_address']) && $value_refresh !== 0 && $metaData['blockbee_cancelled'] !== '1' && (int)$metaData['blockbee_last_price_update'] + $value_refresh <= time() && $remaining_pending > 0) {
68-
6968
if ($remaining === $remaining_pending) {
7069
$blockbee_coin = $metaData['blockbee_currency'];
7170

Model/Total/Fee.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ public function collect(
4848

4949
$fee = $this->calculateFee($quote);
5050

51-
$total->setTotalAmount('fee', $fee);
52-
$total->setBaseTotalAmount('fee', $fee);
51+
$total->setTotalAmount('blockbee_fee', $fee);
52+
$total->setBaseTotalAmount('blockbee_fee', $fee);
5353
$total->setFee($fee);
5454
$total->setBaseFee($fee);
5555
$total->setGrandTotal($total->getGrandTotal());
@@ -77,7 +77,7 @@ protected function clearValues(Total $total)
7777
public function fetch(Quote $quote, Total $total)
7878
{
7979
return [
80-
'code' => 'fee',
80+
'code' => 'blockbee_fee',
8181
'title' => __('Service Fee'),
8282
'value' => $this->calculateFee($quote),
8383
];

Model/Ui/BlockbeeConfigProvider.php

+11-13
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
class BlockbeeConfigProvider implements ConfigProviderInterface
1111
{
1212
const CODE = 'blockbee';
13-
1413
protected $logger;
1514

1615
public function __construct(
@@ -20,7 +19,7 @@ public function __construct(
2019
\Magento\Framework\App\CacheInterface $cache,
2120
\Magento\Framework\Serialize\SerializerInterface $serializer,
2221
\Blockbee\Blockbee\Model\Method\BlockbeePayment $payment,
23-
\Psr\Log\LoggerInterface $logger
22+
\Psr\Log\LoggerInterface $logger
2423
)
2524
{
2625
$this->escaper = $escaper;
@@ -32,32 +31,31 @@ public function __construct(
3231
$this->logger = $logger;
3332
}
3433

35-
public function getConfig()
34+
public function getConfig(): array
3635
{
37-
$config = [
38-
'payment' => array(
39-
self::CODE => array(
36+
return [
37+
'payment' => [
38+
self::CODE => [
4039
'cryptocurrencies' => $this->getCryptocurrencies(),
4140
'instructions' => $this->getInstructions(),
42-
)
43-
)
41+
]
42+
]
4443
];
45-
return $config;
4644
}
4745

48-
public function getInstructions()
46+
public function getInstructions(): \Magento\Framework\Phrase
4947
{
5048
return __('Pay with cryptocurrency');
5149
}
5250

53-
public function getCryptocurrencies()
51+
public function getCryptocurrencies(): array
5452
{
5553
$cacheKey = \Blockbee\Blockbee\Model\Cache\Type::TYPE_IDENTIFIER;
5654
$cacheTag = \Blockbee\Blockbee\Model\Cache\Type::CACHE_TAG;
5755

58-
if (empty($this->cache->load($cacheKey)) || !json_decode($this->cache->load($cacheKey))) {
56+
if (empty($this->cache->load($cacheKey)) || !$this->serializer->unserialize($this->cache->load($cacheKey))) {
5957
$this->cache->save(
60-
$this->serializer->serialize(json_encode(BlockbeeHelper::get_supported_coins())),
58+
$this->serializer->serialize($this->serializer->serialize(BlockbeeHelper::get_supported_coins())),
6159
$cacheKey,
6260
[$cacheTag],
6361
86400

Observer/QuoteSubmitBefore.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ public function execute(Observer $observer)
3434

3535
if ($paymentMethod === 'blockbee') {
3636
$order =$observer->getOrder();
37-
$order->setData('blockbee_fee', (float)$quote->getData('fee'));
37+
$order->setData('blockbee_fee', (float)$quote->getData('blockbee_fee'));
3838
}
39-
4039
}
4140
}

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ For more info on our fees [click here](https://blockbee.io/fees/)
6565
php bin/magento module:enable Blockbee_Blockbee
6666
php bin/magento setup:upgrade
6767
php bin/magento setup:di:compile
68-
php bin/magento setup:static-content:deploy -f
69-
php bin/magento cache:flush
7068
php bin/magento cache:enable blockbee_cryptocurrencies
7169
```
7270

@@ -113,8 +111,11 @@ The easiest and fastest way is via our live chat on our [website](https://blockb
113111

114112
### Changelog
115113

116-
#### 1.0
114+
#### 1.0.0
117115
* Initial release.
118116

117+
#### 1.0.1
118+
* Minor bugfixes and improvements.
119+
119120
### Upgrade Notice
120121
* No breaking changes.

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "blockbee/blockbee",
33
"description": "BlockBee's Magento extension",
44
"type": "magento2-module",
5-
"version": "1.0.0",
5+
"version": "1.0.1",
66
"keywords": [
77
"blockbee",
88
"magento2_module",

etc/config.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<payment>
66
<blockbee>
77
<model>Blockbee\Blockbee\Model\Method\BlockbeePayment</model>
8-
<title>Cryptocurrency</title>
8+
<title>Pay With BlockBee</title>
99
<active>0</active>
1010
<show_branding>1</show_branding>
1111
<disable_conversion>0</disable_conversion>

etc/extension_attributes.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
22
<extension_attributes for="Magento\Quote\Api\Data\CartInterface">
3-
<attribute code="fee" type="float" />
3+
<attribute code="blockbee_fee" type="float" />
44
</extension_attributes>
55
<extension_attributes for="Magento\Sales\Api\Data\OrderInterface">
6-
<attribute code="fee" type="float" />
6+
<attribute code="blockbee_fee" type="float" />
77
</extension_attributes>
88
</config>

etc/fieldset.xml

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
<?xml version="1.0"?>
2-
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="urn:magento:framework:DataObject/etc/fieldset.xsd">
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:DataObject/etc/fieldset.xsd">
43
<scope id="global">
5-
<fieldset id="blockbee_sales_convert_quote">
6-
<field name="fee">
7-
<aspect name="to_order" targetField="fee" />
4+
<fieldset id="blockbee_sales_convert_quote">
5+
<field name="blockbee_fee">
6+
<aspect name="to_order" targetField="blockbee_fee"/>
87
</field>
98
</fieldset>
109
</scope>

etc/frontend/di.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<type name="Magento\Checkout\Model\CompositeConfigProvider">
66
<arguments>
77
<argument name="configProviders" xsi:type="array">
8-
<item name="custom_payment_config_provider" xsi:type="object">Blockbee\Blockbee\Model\Ui\BlockbeeConfigProvider</item>
8+
<item name="blockbee_blockbee_config_provider" xsi:type="object">Blockbee\Blockbee\Model\Ui\BlockbeeConfigProvider</item>
99
</argument>
1010
</arguments>
1111
</type>

etc/sales.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Sales:etc/sales.xsd">
33
<section name="quote">
44
<group name="totals">
5-
<item name="fee" instance="Blockbee\Blockbee\Model\Total\Fee" sort_order="150"/>
5+
<item name="blockbee_fee" instance="Blockbee\Blockbee\Model\Total\Fee" sort_order="150"/>
66
</group>
77
</section>
88
</config>

0 commit comments

Comments
 (0)