Skip to content

Commit ed2c1e3

Browse files
author
Ariano Fonseca Ângelo
committed
v3.1.1
- Minor fixes
1 parent e2b416e commit ed2c1e3

File tree

11 files changed

+109
-43
lines changed

11 files changed

+109
-43
lines changed

Block/Adminhtml/Cryptocurrencies.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ protected function _prepareToRender()
1515
'label' => __('Cryptocurrency'),
1616
'renderer' => $this->getCryptosField(),
1717
]);
18-
$this->addColumn('cryptocurrency_address', ['label' => __('Cryptocurrency Address'), 'class' => 'required-entry']);
18+
$this->addColumn('cryptocurrency_address', ['label' => __('Cryptocurrency Address'), 'class' => '']); // required-entry
1919
$this->_addAfter = false;
2020
$this->_addButtonLabel = __('Add More');
2121
}

Model/Config/ConfigPlugin.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,30 @@ public function aroundSave(
4747

4848
if (!empty($groups)) {
4949
$cryptocurrencies = $groups["cryptapi"]["groups"]["supported_cryptocurrencies"]["fields"]["cryptocurrencies"]["value"];
50+
$apiKey = $groups["cryptapi"]["fields"]["api_key"]["value"];
51+
$cryptocurrenciesArray = array_map(function ($val) {
52+
return $val['cryptocurrency'];
53+
}, array_filter($cryptocurrencies));
5054

51-
$cryptocurrencies_array = array_map(function($val){return $val['cryptocurrency'];}, array_filter($cryptocurrencies));
55+
$hasEmptyAddr = false;
5256

53-
if (count($cryptocurrencies_array) !== count(array_unique($cryptocurrencies_array, SORT_STRING))) {
57+
$c = 0;
58+
foreach ($cryptocurrencies as $ticker => $addr) {
59+
if($c < (count($cryptocurrencies) - 1)) {
60+
if (empty($addr["cryptocurrency_address"])) {
61+
$hasEmptyAddr = true;
62+
}
63+
}
64+
$c++;
65+
}
66+
67+
if ($hasEmptyAddr && empty($apiKey)) {
68+
throw new \Magento\Framework\Exception\AlreadyExistsException(
69+
__("Please make sure you enter either the cryptocurrency address or an API Key.")
70+
);
71+
}
72+
73+
if (count($cryptocurrenciesArray) !== count(array_unique($cryptocurrenciesArray, SORT_STRING))) {
5474
throw new \Magento\Framework\Exception\AlreadyExistsException(
5575
__('You can only add one address per cryptocurrency')
5676
);

Model/Config/Source/QrcodeOptions.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ class QrcodeOptions implements \Magento\Framework\Data\OptionSourceInterface
77
public function toOptionArray()
88
{
99
return [
10-
'without_ammount' => 'Default Without Ammount',
11-
'ammount' => 'Default Ammount',
12-
'hide_ammount' => 'Hide Ammount',
13-
'hide_without_ammount' => 'Hide Without Ammount',
10+
'without_ammount' => 'Default Without Amount',
11+
'ammount' => 'Default Amount',
12+
'hide_ammount' => 'Hide Amount',
13+
'hide_without_ammount' => 'Hide Without Amount',
1414
];
1515
}
1616
}

Model/Ui/CryptapiConfigProvider.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public function getCryptocurrencies()
5959
}
6060

6161
$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);
6263

6364
$available_cryptos = $this->serializer->unserialize($this->cache->load($cacheKey));
6465

@@ -67,11 +68,13 @@ public function getCryptocurrencies()
6768
if (!empty($selected)) {
6869
foreach (json_decode($available_cryptos) as $ticker => $coin) {
6970
foreach ($selected as $uuid => $data) {
70-
if ($ticker == $data['cryptocurrency'])
71-
$output[] = [
72-
'value' => $data['cryptocurrency'],
73-
'type' => $coin,
74-
];
71+
if (!empty($data['cryptocurrency_address'] || !empty($apiKey))) { // Check for API Key / Address configuration. Prevents unexpected errors.
72+
if ($ticker == $data['cryptocurrency'])
73+
$output[] = [
74+
'value' => $data['cryptocurrency'],
75+
'type' => $coin,
76+
];
77+
}
7578
}
7679
}
7780
}

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,5 +148,8 @@ The easiest and fastest way is via our live chat on our [website](https://crypta
148148
* Support CryptAPI Pro
149149
* Minor fixes
150150

151+
#### 3.1.1
152+
* Minor fixes
153+
151154
### Upgrade Notice
152155
* No breaking changes.

composer.json

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,24 @@
22
"name": "cryptapi/cryptapi",
33
"description": "CryptAPI's Magento extension",
44
"type": "magento2-module",
5-
"version": "3.1",
5+
"version": "3.1.1",
6+
"keywords": [
7+
"cryptapi",
8+
"magento2_module",
9+
"magento2_payment_module",
10+
"payment_gateway",
11+
"magento2_payment_gateway",
12+
"payment_processing",
13+
"magento2_payment_processing",
14+
"cryptocurrency"
15+
],
616
"require": {
7-
"magento/module-payment": "100.1.*",
8-
"magento/module-checkout": "100.1.*",
9-
"magento/module-sales": "100.1.*",
10-
"ext-bcmath": "*",
17+
"magento/module-payment": "^100.0.0",
18+
"magento/module-checkout": "^100.0.0",
19+
"magento/module-sales": "^102.0.0|^103.0.0",
1120
"ext-curl": "*",
12-
"ext-json": "*"
21+
"ext-json": "*",
22+
"ext-bcmath": "*"
1323
},
1424
"autoload": {
1525
"files": [ "registration.php" ],

etc/adminhtml/system.xml

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,52 +12,61 @@
1212
<field id="title" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
1313
<label>Title</label>
1414
</field>
15-
<field id="api_key" translate="label" type="text" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1">
16-
<label>API Key</label>
17-
</field>
18-
<field id="show_branding" translate="label" type="select" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1">
15+
<field id="show_branding" translate="label" type="select" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1">
1916
<label>Show CryptAPI branding</label>
2017
<comment>Show CryptAPI Logo</comment>
2118
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
2219
</field>
23-
<field id="add_blockchain_fee" translate="label" type="select" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1">
20+
<field id="add_blockchain_fee" translate="label" type="select" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1">
2421
<label>Add the blockchain fee to the order</label>
2522
<comment>This will add an estimation of the blockchain fee to the order value</comment>
2623
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
2724
</field>
28-
<field id="fee_order_percentage" translate="label" type="select" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="1">
25+
<field id="fee_order_percentage" translate="label" type="select" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1">
2926
<label>Service fee manager</label>
30-
<comment>Set the CryptAPI service fee you want to charge the costumer. Note: Fee you want to charge your costumers (to cover CryptAPI\'s fees fully or partially)</comment>
27+
<comment>Set the CryptAPI service fee you want to charge the costumer. Note: Fee you want to charge your costumers (to cover CryptAPI\'s fees fully or partially)
28+
</comment>
3129
<source_model>Cryptapi\Cryptapi\Model\Config\Source\FeesList</source_model>
3230
</field>
33-
<field id="qrcode_default" translate="label" type="select" sortOrder="7" showInDefault="1" showInWebsite="1" showInStore="1">
31+
<field id="qrcode_default" translate="label" type="select" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="1">
3432
<label>QR Code by default</label>
3533
<comment>Show the QR Code by default</comment>
3634
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
3735
</field>
38-
<field id="qrcode_size" translate="label" type="text" sortOrder="8" showInDefault="1" showInWebsite="1" showInStore="1">
36+
<field id="qrcode_size" translate="label" type="text" sortOrder="7" showInDefault="1" showInWebsite="1" showInStore="1">
3937
<label>QR Code size</label>
4038
</field>
41-
<field id="qrcode_setting" translate="label" type="select" sortOrder="9" showInDefault="1" showInWebsite="1" showInStore="1">
39+
<field id="qrcode_setting" translate="label" type="select" sortOrder="8" showInDefault="1" showInWebsite="1" showInStore="1">
4240
<label>Color Scheme</label>
4341
<comment>Selects the color scheme of the plugin to match your website (Light, Dark and Auto to automatically detect it).</comment>
4442
<source_model>Cryptapi\Cryptapi\Model\Config\Source\QrcodeOptions</source_model>
4543
</field>
46-
<field id="color_scheme" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
44+
<field id="color_scheme" translate="label" type="select" sortOrder="9" showInDefault="1" showInWebsite="1" showInStore="1">
4745
<label>QR Code to show</label>
4846
<comment>Select how you want to show the QR Code to the user. Either select a default to show first, or hide one of them.</comment>
4947
<source_model>Cryptapi\Cryptapi\Model\Config\Source\SchemeList</source_model>
5048
</field>
51-
<field id="refresh_value_interval" translate="label" type="select" sortOrder="11" showInDefault="1" showInWebsite="1" showInStore="1">
49+
<field id="refresh_value_interval" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
5250
<label>Refresh converted value</label>
53-
<comment>The system will automatically update the conversion value of the invoices (with real-time data), every X minutes. This feature is helpful whenever a customer takes long time to pay a generated invoice and the selected crypto a volatile coin/token (not stable coin). Warning: Setting this setting to none might create conversion issues, as we advise you to keep it at 5 minutes.</comment>
51+
<comment>The system will automatically update the conversion value of the invoices (with real-time data), every X minutes. This feature is helpful whenever a customer
52+
takes long time to pay a generated invoice and the selected crypto a volatile coin/token (not stable coin). Warning: Setting this setting to none might create
53+
conversion issues, as we advise you to keep it at 5 minutes.
54+
</comment>
5455
<source_model>Cryptapi\Cryptapi\Model\Config\Source\RefreshList</source_model>
5556
</field>
56-
<field id="order_cancelation_timeout" translate="label" type="select" sortOrder="12" showInDefault="1" showInWebsite="1" showInStore="1">
57+
<field id="order_cancelation_timeout" translate="label" type="select" sortOrder="11" showInDefault="1" showInWebsite="1" showInStore="1">
5758
<label>Order cancelation timeout</label>
58-
<comment>Selects the ammount of time the user has to pay for the order. When this time is over, order will be marked as 'Cancelled' and every paid value will be ignored. Notice: If the user still sends money to the generated address, value will still be redirected to you. Warning: We do not advice more than 1 Hour.</comment>
59+
<comment>Selects the ammount of time the user has to pay for the order. When this time is over, order will be marked as 'Cancelled' and every paid value will be ignored.
60+
Notice: If the user still sends money to the generated address, value will still be redirected to you. Warning: We do not advice more than 1 Hour.
61+
</comment>
5962
<source_model>Cryptapi\Cryptapi\Model\Config\Source\CancellationList</source_model>
6063
</field>
64+
<field id="api_key" translate="label" type="text" sortOrder="12" showInDefault="1" showInWebsite="1" showInStore="1">
65+
<label>API Key</label>
66+
<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>]]>
68+
</comment>
69+
</field>
6170
<group id="supported_cryptocurrencies" translate="label" type="text" sortOrder="13" showInDefault="1" showInWebsite="1"
6271
showInStore="1">
6372
<label>Cryptocurrencies</label>
@@ -66,7 +75,9 @@
6675
<label>Add you address here:</label>
6776
<frontend_model>Cryptapi\Cryptapi\Block\Adminhtml\Cryptocurrencies</frontend_model>
6877
<backend_model>Magento\Config\Model\Config\Backend\Serialized\ArraySerialized</backend_model>
69-
<comment>Important: Add only 1 address per cryptocurrency!</comment>
78+
<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.]]>
80+
</comment>
7081
</field>
7182
</group>
7283
<field id="allowspecific" translate="label" type="allowspecific" sortOrder="15" showInDefault="1" showInWebsite="1" showInStore="1">
@@ -82,7 +93,9 @@
8293
</field>
8394
<field id="disable_conversion" translate="label" type="select" sortOrder="18" showInDefault="1" showInWebsite="1" showInStore="1">
8495
<label>Disable price conversion</label>
85-
<comment>Attention: This option will disable the price conversion for ALL cryptocurrencies! If you check this, pricing will not be converted from the currency of your shop to the cryptocurrency selected by the user, and users will be requested to pay the same value as shown on your shop, regardless of the cryptocurrency selected</comment>
96+
<comment>Attention: This option will disable the price conversion for ALL cryptocurrencies! If you check this, pricing will not be converted from the currency of your
97+
shop to the cryptocurrency selected by the user, and users will be requested to pay the same value as shown on your shop, regardless of the cryptocurrency selected
98+
</comment>
8699
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
87100
</field>
88101
</group>

lib/CryptAPIHelper.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,35 @@ public function __construct($coin, $own_address, $api_key, $callback_url, $param
2727
public function get_address()
2828
{
2929

30-
if (empty($this->own_address) || empty($this->coin) || empty($this->callback_url)) return null;
30+
if (empty($this->coin) || empty($this->callback_url)) {
31+
return null;
32+
}
3133

3234
$api_key = $this->api_key;
3335

36+
if (empty($api_key) && empty($this->own_address)) {
37+
return null;
38+
}
39+
3440
$callback_url = $this->callback_url;
3541
if (!empty($this->parameters)) {
3642
$req_parameters = http_build_query($this->parameters);
3743
$callback_url = "{$this->callback_url}?{$req_parameters}";
3844
}
3945

40-
if (empty($api_key)) {
46+
if (!empty($api_key) && empty($this->own_address)) {
47+
$ca_params = [
48+
'apikey' => $api_key,
49+
'callback' => $callback_url,
50+
'pending' => $this->pending,
51+
];
52+
} elseif (empty($api_key) && !empty($this->own_address)) {
4153
$ca_params = [
4254
'callback' => $callback_url,
4355
'address' => $this->own_address,
4456
'pending' => $this->pending,
4557
];
46-
} else {
58+
} elseif(!empty($api_key) && !empty($this->own_address)) {
4759
$ca_params = [
4860
'apikey' => $api_key,
4961
'callback' => $callback_url,

0 commit comments

Comments
 (0)