Skip to content

Commit d4772b2

Browse files
authored
Merge pull request #2 from arianoangelo/master
v3.1
2 parents bb5aeba + ed2c1e3 commit d4772b2

File tree

15 files changed

+177
-83
lines changed

15 files changed

+177
-83
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
}

Block/Payment.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ public function getTemplateValues()
8585

8686
$callbackUrl = $this->payment->getCallbackUrl();
8787

88-
$api = new CryptAPIHelper($selected, $address, $callbackUrl, $params, true);
88+
$apiKey = $this->scopeConfig->getValue('payment/cryptapi/api_key', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
89+
90+
$api = new CryptAPIHelper($selected, $address, $apiKey, $callbackUrl, $params, true);
8991
$addressIn = $api->get_address();
9092

9193
$qrCode = $api->get_qrcode('', $qrCodeSize);

Controller/Index/Callback.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function execute()
6464

6565
$history[$data['uuid']] = [
6666
'timestamp' => time(),
67-
'value_paid' => $paid,
67+
'value_paid' => CryptAPIHelper::sig_fig($paid, 6),
6868
'value_paid_fiat' => $fiat_conversion,
6969
'pending' => $data['pending']
7070
];

Cron/CryptapiCronjob.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function execute()
5858

5959
$remaining = $calc['remaining'];
6060
$remaining_pending = $calc['remaining_pending'];
61-
$remaining_fiat = $calc['remaining_fiat'];
61+
$already_paid = $calc['already_paid'];
6262

6363
if (!empty($metaData['cryptapi_address']) && $value_refresh !== 0 && $metaData['cryptapi_cancelled'] !== '1' && (int)$metaData['cryptapi_last_price_update'] + $value_refresh <= time() && $remaining_pending > 0) {
6464

@@ -84,7 +84,7 @@ public function execute()
8484
$this->helper->updatePaymentData($orderQuoteId, 'cryptapi_last_price_update', time());
8585
}
8686

87-
if ($order_timeout !== 0 && ((int)strtotime($order->getCreatedAt()) + $order_timeout) <= time() && empty($metaData['cryptapi_pending']) && $remaining_fiat <= $order->getGrandTotal() && (string)$metaData['cryptapi_cancelled'] === '0') {
87+
if ($order_timeout !== 0 && ((int)strtotime($order->getCreatedAt()) + $order_timeout) <= time() && empty($metaData['cryptapi_pending']) && $already_paid <= 0 && (string)$metaData['cryptapi_cancelled'] === '0') {
8888
$state = \Magento\Sales\Model\Order::STATE_CANCELED;
8989
$status = \Magento\Sales\Model\Order::STATE_CANCELED;
9090
$order->setState($state);

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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,5 +144,12 @@ The easiest and fastest way is via our live chat on our [website](https://crypta
144144
#### 3.0.3
145145
* Minor fixes
146146

147+
#### 3.1
148+
* Support CryptAPI Pro
149+
* Minor fixes
150+
151+
#### 3.1.1
152+
* Minor fixes
153+
147154
### Upgrade Notice
148155
* 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.0.3",
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: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
</field>
2525
<field id="fee_order_percentage" translate="label" type="select" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1">
2626
<label>Service fee manager</label>
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)</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>
2829
<source_model>Cryptapi\Cryptapi\Model\Config\Source\FeesList</source_model>
2930
</field>
3031
<field id="qrcode_default" translate="label" type="select" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="1">
@@ -47,39 +48,54 @@
4748
</field>
4849
<field id="refresh_value_interval" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
4950
<label>Refresh converted value</label>
50-
<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>
5155
<source_model>Cryptapi\Cryptapi\Model\Config\Source\RefreshList</source_model>
5256
</field>
5357
<field id="order_cancelation_timeout" translate="label" type="select" sortOrder="11" showInDefault="1" showInWebsite="1" showInStore="1">
5458
<label>Order cancelation timeout</label>
55-
<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>
5662
<source_model>Cryptapi\Cryptapi\Model\Config\Source\CancellationList</source_model>
5763
</field>
58-
<group id="supported_cryptocurrencies" translate="label" type="text" sortOrder="12" showInDefault="1" showInWebsite="1"
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>
70+
<group id="supported_cryptocurrencies" translate="label" type="text" sortOrder="13" showInDefault="1" showInWebsite="1"
5971
showInStore="1">
6072
<label>Cryptocurrencies</label>
61-
<field id="cryptocurrencies" translate="label" sortOrder="13" showInDefault="1" showInWebsite="1"
73+
<field id="cryptocurrencies" translate="label" sortOrder="14" showInDefault="1" showInWebsite="1"
6274
showInStore="1">
6375
<label>Add you address here:</label>
6476
<frontend_model>Cryptapi\Cryptapi\Block\Adminhtml\Cryptocurrencies</frontend_model>
6577
<backend_model>Magento\Config\Model\Config\Backend\Serialized\ArraySerialized</backend_model>
66-
<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>
6781
</field>
6882
</group>
69-
<field id="allowspecific" translate="label" type="allowspecific" sortOrder="14" showInDefault="1" showInWebsite="1" showInStore="1">
83+
<field id="allowspecific" translate="label" type="allowspecific" sortOrder="15" showInDefault="1" showInWebsite="1" showInStore="1">
7084
<label>Countries</label>
7185
<source_model>Magento\Payment\Model\Config\Source\Allspecificcountries</source_model>
7286
</field>
73-
<field id="specificcountry" translate="label" type="multiselect" sortOrder="15" showInDefault="1" showInWebsite="1" showInStore="1">
87+
<field id="specificcountry" translate="label" type="multiselect" sortOrder="16" showInDefault="1" showInWebsite="1" showInStore="1">
7488
<label>Specific Countries</label>
7589
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
7690
</field>
77-
<field id="sort_order" translate="label" type="text" sortOrder="16" showInDefault="1" showInWebsite="1" showInStore="1">
91+
<field id="sort_order" translate="label" type="text" sortOrder="17" showInDefault="1" showInWebsite="1" showInStore="1">
7892
<label>Sort Order</label>
7993
</field>
80-
<field id="disable_conversion" translate="label" type="select" sortOrder="17" showInDefault="1" showInWebsite="1" showInStore="1">
94+
<field id="disable_conversion" translate="label" type="select" sortOrder="18" showInDefault="1" showInWebsite="1" showInStore="1">
8195
<label>Disable price conversion</label>
82-
<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>
8399
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
84100
</field>
85101
</group>

0 commit comments

Comments
 (0)