Skip to content

Commit 1eb1a2c

Browse files
committed
v3.2.1
* Minor bugfixes and improvements.
1 parent b2c208b commit 1eb1a2c

File tree

24 files changed

+179
-171
lines changed

24 files changed

+179
-171
lines changed

.gitignore

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Private files
2+
# The following files contain your database credentials and other personal data.
3+
4+
config/settings.*.php
5+
6+
# Cache, temp and generated files
7+
# The following files are generated by PrestaShop.
8+
9+
admin-dev/autoupgrade/
10+
/cache/*
11+
!/cache/index.php
12+
!/cache/*/
13+
/cache/*/*
14+
!/cache/cachefs/index.php
15+
!/cache/purifier/index.php
16+
!/cache/push/index.php
17+
!/cache/sandbox/index.php
18+
!/cache/smarty/index.php
19+
!/cache/tcpdf/index.php
20+
config/xml/*.xml
21+
/log/*
22+
*sitemap.xml
23+
themes/*/cache/
24+
modules/*/config*.xml
25+
26+
# Site content
27+
# The following folders contain product images, virtual products, CSV's, etc.
28+
29+
admin-dev/backups/
30+
admin-dev/export/
31+
admin-dev/import/
32+
download/
33+
/img/*
34+
upload/
35+
36+
*/DS_STORE
37+
.DS_Store
38+
39+
.idea

Block/Payment.php

Lines changed: 83 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -37,105 +37,109 @@ public function __construct(
3737

3838
public function getTemplateValues()
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-
}
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+
}
4748

48-
$total = $order->getGrandTotal();
49-
$currencySymbol = $order->getOrderCurrencyCode();
50-
$metaData = $this->helper->getPaymentResponse($order->getQuoteId());
49+
$total = $order->getGrandTotal();
50+
$currencySymbol = $order->getOrderCurrencyCode();
51+
$metaData = $this->helper->getPaymentResponse($order->getQuoteId());
5152

52-
if (empty($metaData)) {
53-
return false;
54-
}
53+
if (empty($metaData)) {
54+
return false;
55+
}
5556

56-
$qrCodeSize = $this->scopeConfig->getValue('payment/cryptapi/qrcode_size', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
57+
$qrCodeSize = $this->scopeConfig->getValue('payment/cryptapi/qrcode_size', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
5758

58-
$branding = $this->scopeConfig->getValue('payment/cryptapi/show_branding', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
59+
$branding = $this->scopeConfig->getValue('payment/cryptapi/show_branding', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
5960

60-
$metaData = json_decode($metaData, true);
61+
$metaData = json_decode($metaData, true);
6162

62-
if ($nonce != $metaData['cryptapi_nonce']) {
63-
return false;
64-
}
63+
if ($nonce != $metaData['cryptapi_nonce']) {
64+
return false;
65+
}
6566

66-
$cryptoValue = $metaData['cryptapi_total'];
67-
$cryptoCoin = $metaData['cryptapi_currency'];
67+
$cryptoValue = $metaData['cryptapi_total'];
68+
$cryptoCoin = $metaData['cryptapi_currency'];
6869

69-
if (isset($metaData['cryptapi_address']) && !empty($metaData['cryptapi_address'])) {
70-
$addressIn = $metaData['cryptapi_address'];
71-
} else {
72-
/*
73-
* Makes request to API and generates all the payment data needed
74-
*/
70+
if (isset($metaData['cryptapi_address']) && !empty($metaData['cryptapi_address'])) {
71+
$addressIn = $metaData['cryptapi_address'];
72+
} else {
73+
/*
74+
* Makes request to API and generates all the payment data needed
75+
*/
7576

76-
$selected = $cryptoCoin;
77+
$selected = $cryptoCoin;
7778

78-
$address = '';
79+
$address = '';
7980

80-
$allCryptocurrencies = json_decode($this->scopeConfig->getValue('payment/cryptapi/supported_cryptocurrencies/cryptocurrencies', \Magento\Store\Model\ScopeInterface::SCOPE_STORE), true);
81+
$allCryptocurrencies = json_decode($this->scopeConfig->getValue('payment/cryptapi/supported_cryptocurrencies/cryptocurrencies', \Magento\Store\Model\ScopeInterface::SCOPE_STORE), true);
8182

82-
foreach ($allCryptocurrencies as $uid => $data) {
83-
if ($data['cryptocurrency'] === $selected) {
84-
$address = $data['cryptocurrency_address'];
83+
foreach ($allCryptocurrencies as $uid => $data) {
84+
if ($data['cryptocurrency'] === $selected) {
85+
$address = $data['cryptocurrency_address'];
86+
}
8587
}
86-
}
8788

88-
$params = [
89-
'order_id' => $order->getId(),
90-
'nonce' => $metaData['cryptapi_nonce'],
91-
];
89+
$params = [
90+
'order_id' => $order->getId(),
91+
'nonce' => $metaData['cryptapi_nonce'],
92+
];
9293

93-
$callbackUrl = $this->payment->getCallbackUrl();
94+
$callbackUrl = $this->payment->getCallbackUrl();
9495

95-
$apiKey = $this->scopeConfig->getValue('payment/cryptapi/api_key', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
96+
$apiKey = $this->scopeConfig->getValue('payment/cryptapi/api_key', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
9697

97-
$api = new CryptAPIHelper($selected, $address, $apiKey, $callbackUrl, $params, true);
98-
$addressIn = $api->get_address();
98+
$api = new CryptAPIHelper($selected, $address, $apiKey, $callbackUrl, $params, true);
99+
$addressIn = $api->get_address();
99100

100-
$qrCode = $api->get_qrcode('', $qrCodeSize);
101-
$qrCodeValue = $api->get_qrcode($cryptoValue, $qrCodeSize);
101+
$qrCode = $api->get_qrcode('', $qrCodeSize);
102+
$qrCodeValue = $api->get_qrcode($cryptoValue, $qrCodeSize);
102103

103-
$this->helper->updatePaymentData($order->getQuoteId(), 'cryptapi_address', $addressIn);
104-
$this->helper->updatePaymentData($order->getQuoteId(), 'cryptapi_qr_code_value', $qrCodeValue['qr_code']);
105-
$this->helper->updatePaymentData($order->getQuoteId(), 'cryptapi_qr_code', $qrCode['qr_code']);
106-
$this->helper->updatePaymentData($order->getQuoteId(), 'cryptapi_payment_url', $this->storeManager->getStore()->getUrl('cryptapi/index/payment/order_id/' . $order->getId() . '/nonce/' . $metaData['cryptapi_nonce']));
104+
$this->helper->updatePaymentData($order->getQuoteId(), 'cryptapi_address', $addressIn);
105+
$this->helper->updatePaymentData($order->getQuoteId(), 'cryptapi_qr_code_value', $qrCodeValue['qr_code']);
106+
$this->helper->updatePaymentData($order->getQuoteId(), 'cryptapi_qr_code', $qrCode['qr_code']);
107+
$this->helper->updatePaymentData($order->getQuoteId(), 'cryptapi_payment_url', $this->storeManager->getStore()->getUrl('cryptapi/index/payment/order_id/' . $order->getId() . '/nonce/' . $metaData['cryptapi_nonce']));
107108

108-
$metaData = json_decode($this->helper->getPaymentResponse($order->getQuoteId()), true);
109-
$this->mail->sendMail($order, $metaData);
110-
}
109+
$metaData = json_decode($this->helper->getPaymentResponse($order->getQuoteId()), true);
110+
$this->mail->sendMail($order, $metaData);
111+
}
112+
113+
$ajaxParams = [
114+
'order_id' => $order->getId(),
115+
];
111116

112-
$ajaxParams = [
113-
'order_id' => $order->getId(),
114-
];
115-
116-
$ajaxUrl = $this->payment->getAjaxStatusUrl($ajaxParams);
117-
118-
$metaData = $this->helper->getPaymentResponse($order->getQuoteId());
119-
$metaData = json_decode($metaData, true);
120-
121-
return [
122-
'crypto_value' => floatval($cryptoValue),
123-
'currency_symbol' => $currencySymbol,
124-
'total' => $total,
125-
'address_in' => $addressIn,
126-
'crypto_coin' => $cryptoCoin,
127-
'ajax_url' => $ajaxUrl,
128-
'qrcode_size' => $qrCodeSize,
129-
'qrcode' => $metaData['cryptapi_qr_code'],
130-
'qrcode_value' => $metaData['cryptapi_qr_code_value'],
131-
'qrcode_default' => $this->scopeConfig->getValue('payment/cryptapi/qrcode_default', \Magento\Store\Model\ScopeInterface::SCOPE_STORE),
132-
'show_branding' => $branding,
133-
'qr_code_setting' => $this->scopeConfig->getValue('payment/cryptapi/qrcode_setting', \Magento\Store\Model\ScopeInterface::SCOPE_STORE),
134-
'order_timestamp' => strtotime($order->getCreatedAt()),
135-
'order_cancelation_timeout' => $this->scopeConfig->getValue('payment/cryptapi/order_cancelation_timeout', \Magento\Store\Model\ScopeInterface::SCOPE_STORE),
136-
'refresh_value_interval' => $this->scopeConfig->getValue('payment/cryptapi/refresh_value_interval', \Magento\Store\Model\ScopeInterface::SCOPE_STORE),
137-
'last_price_update' => $metaData['cryptapi_last_price_update'],
138-
'min_tx' => $metaData['cryptapi_min'],
139-
];
117+
$ajaxUrl = $this->payment->getAjaxStatusUrl($ajaxParams);
118+
119+
$metaData = $this->helper->getPaymentResponse($order->getQuoteId());
120+
$metaData = json_decode($metaData, true);
121+
122+
return [
123+
'crypto_value' => floatval($cryptoValue),
124+
'currency_symbol' => $currencySymbol,
125+
'total' => $total,
126+
'address_in' => $addressIn,
127+
'crypto_coin' => $cryptoCoin,
128+
'ajax_url' => $ajaxUrl,
129+
'qrcode_size' => $qrCodeSize,
130+
'qrcode' => $metaData['cryptapi_qr_code'],
131+
'qrcode_value' => $metaData['cryptapi_qr_code_value'],
132+
'qrcode_default' => $this->scopeConfig->getValue('payment/cryptapi/qrcode_default', \Magento\Store\Model\ScopeInterface::SCOPE_STORE),
133+
'show_branding' => $branding,
134+
'qr_code_setting' => $this->scopeConfig->getValue('payment/cryptapi/qrcode_setting', \Magento\Store\Model\ScopeInterface::SCOPE_STORE),
135+
'order_timestamp' => strtotime($order->getCreatedAt()),
136+
'order_cancelation_timeout' => $this->scopeConfig->getValue('payment/cryptapi/order_cancelation_timeout', \Magento\Store\Model\ScopeInterface::SCOPE_STORE),
137+
'refresh_value_interval' => $this->scopeConfig->getValue('payment/cryptapi/refresh_value_interval', \Magento\Store\Model\ScopeInterface::SCOPE_STORE),
138+
'last_price_update' => $metaData['cryptapi_last_price_update'],
139+
'min_tx' => $metaData['cryptapi_min'],
140+
];
141+
} catch (\Exception $exception) {
142+
// Empty
143+
}
140144
}
141145
}

Model/Total/Fee.php

Lines changed: 4 additions & 4 deletions
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('cryptapi_fee', $fee);
52+
$total->setBaseTotalAmount('cryptapi_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' => 'cryptapi_fee',
8181
'title' => __('Service Fee'),
8282
'value' => $this->calculateFee($quote),
8383
];
@@ -107,7 +107,7 @@ private function calculateFee(Quote $quote)
107107

108108
return $totalPrice + $conv;
109109
}
110-
} catch (\Exception $ex) {
110+
} catch (\Exception $e) {
111111
return 0;
112112
}
113113

Model/Ui/CryptapiConfigProvider.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,42 +26,42 @@ public function __construct(
2626
$this->serializer = $serializer;
2727
}
2828

29-
public function getConfig()
29+
public function getConfig() : array
3030
{
31-
$config = [
32-
'payment' => array(
33-
self::CODE => array(
31+
return [
32+
'payment' => [
33+
self::CODE => [
3434
'cryptocurrencies' => $this->getCryptocurrencies(),
3535
'instructions' => $this->getInstructions(),
36-
)
37-
)
36+
]
37+
]
3838
];
39-
return $config;
4039
}
4140

42-
public function getInstructions()
41+
public function getInstructions(): \Magento\Framework\Phrase
4342
{
4443
return __('Pay with cryptocurrency');
4544
}
4645

47-
public function getCryptocurrencies()
46+
public function getCryptocurrencies(): array
4847
{
4948
$cacheKey = \Cryptapi\Cryptapi\Model\Cache\Type::TYPE_IDENTIFIER;
5049
$cacheTag = \Cryptapi\Cryptapi\Model\Cache\Type::CACHE_TAG;
5150

52-
if (empty($this->cache->load($cacheKey)) || !json_decode($this->cache->load($cacheKey))) {
51+
if (empty($this->cache->load($cacheKey)) || !$this->serializer->unserialize($this->cache->load($cacheKey))) {
5352
$this->cache->save(
54-
$this->serializer->serialize(json_encode(CryptAPIHelper::get_supported_coins())),
53+
$this->serializer->serialize($this->serializer->serialize(CryptAPIHelper::get_supported_coins())),
5554
$cacheKey,
5655
[$cacheTag],
5756
86400
5857
);
5958
}
6059

60+
$available_cryptos = $this->serializer->unserialize($this->cache->load($cacheKey));
61+
6162
$selected = json_decode($this->scopeConfig->getValue('payment/cryptapi/supported_cryptocurrencies/cryptocurrencies', \Magento\Store\Model\ScopeInterface::SCOPE_STORE), true);
62-
$apiKey = $this->scopeConfig->getValue('payment/cryptapi/api_key', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
6363

64-
$available_cryptos = $this->serializer->unserialize($this->cache->load($cacheKey));
64+
$apiKey = $this->scopeConfig->getValue('payment/cryptapi/api_key', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
6565

6666
$output = [];
6767

Observer/QuoteSubmitBefore.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function execute(Observer $observer)
3434

3535
if ($paymentMethod === 'cryptapi') {
3636
$order =$observer->getOrder();
37-
$order->setData('cryptapi_fee', (float)$quote->getData('fee'));
37+
$order->setData('cryptapi_fee', (float)$quote->getData('cryptapi_fee'));
3838
}
3939

4040
}

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ For more info on our fees [click here](https://cryptapi.io/get_started/#fees)
6868
php bin/magento module:enable Cryptapi_Cryptapi
6969
php bin/magento setup:upgrade
7070
php bin/magento setup:di:compile
71-
php bin/magento setup:static-content:deploy -f
72-
php bin/magento cache:flush
7371
php bin/magento cache:enable cryptapi_cryptocurrencies
7472
```
7573

@@ -156,5 +154,8 @@ The easiest and fastest way is via our live chat on our [website](https://crypta
156154
* Add e-mail with link for order payment
157155
* Minor fixes
158156

157+
#### 3.2.1
158+
* Minor bugfixes and improvements.
159+
159160
### Upgrade Notice
160161
* No breaking changes.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "cryptapi/cryptapi",
33
"description": "CryptAPI's Magento extension",
44
"type": "magento2-module",
5-
"version": "3.2.0",
5+
"version": "3.2.1",
66
"keywords": [
77
"cryptapi",
88
"magento2_module",

etc/adminhtml/system.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<field id="api_key" translate="label" type="text" sortOrder="12" showInDefault="1" showInWebsite="1" showInStore="1">
6565
<label>API Key</label>
6666
<comment>
67-
<![CDATA[Insert here your CryptAPI Pro API Key. You can get one here: <a href="https://pro.cryptapi.io/" target="_blank">https://pro.cryptapi.io/</a>. <strong>This field is optional.</strong>]]>
67+
<![CDATA[Insert here your BlockBee API Key. You can get one here: <a href="https://dash.blockbee.io/" target="_blank">https://dash.blockbee.io/</a>. <strong>This field is optional.</strong>]]>
6868
</comment>
6969
</field>
7070
<group id="supported_cryptocurrencies" translate="label" type="text" sortOrder="13" showInDefault="1" showInWebsite="1"
@@ -76,7 +76,7 @@
7676
<frontend_model>Cryptapi\Cryptapi\Block\Adminhtml\Cryptocurrencies</frontend_model>
7777
<backend_model>Magento\Config\Model\Config\Backend\Serialized\ArraySerialized</backend_model>
7878
<comment>
79-
<![CDATA[Add only 1 address per cryptocurrency!<br/><strong>Important:</strong> If you are using CryptAPI Pro you can choose if setting the receiving addresses here bellow or in your CryptAPI Pro settings page.<br/> - In order to set the addresses on plugin settings, you need to select “Address Override” while creating the API key.<br/> - In order to set the addresses on CryptAPI Pro settings, you need to NOT select “Address Override” while creating the API key.]]>
79+
<![CDATA[Add only 1 address per cryptocurrency!<br/><strong>Important:</strong> If you are using BlockBee you can choose if setting the receiving addresses here bellow or in your BlockBee settings page.<br/> - In order to set the addresses on plugin settings, you need to select “Address Override” while creating the API key.<br/> - In order to set the addresses on BlockBee settings, you need to NOT select “Address Override” while creating the API key.]]>
8080
</comment>
8181
</field>
8282
</group>

etc/config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<payment>
66
<cryptapi>
77
<model>Cryptapi\Cryptapi\Model\Method\CryptapiPayment</model>
8-
<title>Cryptocurrency</title>
8+
<title>Pay With CryptAPI</title>
99
<active>0</active>
1010
<show_branding>1</show_branding>
1111
<disable_conversion>0</disable_conversion>

etc/extension_attributes.xml

Lines changed: 2 additions & 2 deletions
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="cryptapi_fee" type="float" />
44
</extension_attributes>
55
<extension_attributes for="Magento\Sales\Api\Data\OrderInterface">
6-
<attribute code="fee" type="float" />
6+
<attribute code="cryptapi_fee" type="float" />
77
</extension_attributes>
88
</config>

0 commit comments

Comments
 (0)