Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Block/Adminhtml/Cryptocurrencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ protected function _prepareToRender()
'label' => __('Cryptocurrency'),
'renderer' => $this->getCryptosField(),
]);
$this->addColumn('cryptocurrency_address', ['label' => __('Cryptocurrency Address'), 'class' => 'required-entry']);
$this->addColumn('cryptocurrency_address', ['label' => __('Cryptocurrency Address'), 'class' => '']); // required-entry
$this->_addAfter = false;
$this->_addButtonLabel = __('Add More');
}
Expand Down
4 changes: 3 additions & 1 deletion Block/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ public function getTemplateValues()

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

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

$api = new CryptAPIHelper($selected, $address, $apiKey, $callbackUrl, $params, true);
$addressIn = $api->get_address();

$qrCode = $api->get_qrcode('', $qrCodeSize);
Expand Down
2 changes: 1 addition & 1 deletion Controller/Index/Callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function execute()

$history[$data['uuid']] = [
'timestamp' => time(),
'value_paid' => $paid,
'value_paid' => CryptAPIHelper::sig_fig($paid, 6),
'value_paid_fiat' => $fiat_conversion,
'pending' => $data['pending']
];
Expand Down
4 changes: 2 additions & 2 deletions Cron/CryptapiCronjob.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function execute()

$remaining = $calc['remaining'];
$remaining_pending = $calc['remaining_pending'];
$remaining_fiat = $calc['remaining_fiat'];
$already_paid = $calc['already_paid'];

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

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

if ($order_timeout !== 0 && ((int)strtotime($order->getCreatedAt()) + $order_timeout) <= time() && empty($metaData['cryptapi_pending']) && $remaining_fiat <= $order->getGrandTotal() && (string)$metaData['cryptapi_cancelled'] === '0') {
if ($order_timeout !== 0 && ((int)strtotime($order->getCreatedAt()) + $order_timeout) <= time() && empty($metaData['cryptapi_pending']) && $already_paid <= 0 && (string)$metaData['cryptapi_cancelled'] === '0') {
$state = \Magento\Sales\Model\Order::STATE_CANCELED;
$status = \Magento\Sales\Model\Order::STATE_CANCELED;
$order->setState($state);
Expand Down
24 changes: 22 additions & 2 deletions Model/Config/ConfigPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,30 @@ public function aroundSave(

if (!empty($groups)) {
$cryptocurrencies = $groups["cryptapi"]["groups"]["supported_cryptocurrencies"]["fields"]["cryptocurrencies"]["value"];
$apiKey = $groups["cryptapi"]["fields"]["api_key"]["value"];
$cryptocurrenciesArray = array_map(function ($val) {
return $val['cryptocurrency'];
}, array_filter($cryptocurrencies));

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

if (count($cryptocurrencies_array) !== count(array_unique($cryptocurrencies_array, SORT_STRING))) {
$c = 0;
foreach ($cryptocurrencies as $ticker => $addr) {
if($c < (count($cryptocurrencies) - 1)) {
if (empty($addr["cryptocurrency_address"])) {
$hasEmptyAddr = true;
}
}
$c++;
}

if ($hasEmptyAddr && empty($apiKey)) {
throw new \Magento\Framework\Exception\AlreadyExistsException(
__("Please make sure you enter either the cryptocurrency address or an API Key.")
);
}

if (count($cryptocurrenciesArray) !== count(array_unique($cryptocurrenciesArray, SORT_STRING))) {
throw new \Magento\Framework\Exception\AlreadyExistsException(
__('You can only add one address per cryptocurrency')
);
Expand Down
8 changes: 4 additions & 4 deletions Model/Config/Source/QrcodeOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ class QrcodeOptions implements \Magento\Framework\Data\OptionSourceInterface
public function toOptionArray()
{
return [
'without_ammount' => 'Default Without Ammount',
'ammount' => 'Default Ammount',
'hide_ammount' => 'Hide Ammount',
'hide_without_ammount' => 'Hide Without Ammount',
'without_ammount' => 'Default Without Amount',
'ammount' => 'Default Amount',
'hide_ammount' => 'Hide Amount',
'hide_without_ammount' => 'Hide Without Amount',
];
}
}
13 changes: 8 additions & 5 deletions Model/Ui/CryptapiConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function getCryptocurrencies()
}

$selected = json_decode($this->scopeConfig->getValue('payment/cryptapi/supported_cryptocurrencies/cryptocurrencies', \Magento\Store\Model\ScopeInterface::SCOPE_STORE), true);
$apiKey = $this->scopeConfig->getValue('payment/cryptapi/api_key', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);

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

Expand All @@ -67,11 +68,13 @@ public function getCryptocurrencies()
if (!empty($selected)) {
foreach (json_decode($available_cryptos) as $ticker => $coin) {
foreach ($selected as $uuid => $data) {
if ($ticker == $data['cryptocurrency'])
$output[] = [
'value' => $data['cryptocurrency'],
'type' => $coin,
];
if (!empty($data['cryptocurrency_address'] || !empty($apiKey))) { // Check for API Key / Address configuration. Prevents unexpected errors.
if ($ticker == $data['cryptocurrency'])
$output[] = [
'value' => $data['cryptocurrency'],
'type' => $coin,
];
}
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,12 @@ The easiest and fastest way is via our live chat on our [website](https://crypta
#### 3.0.3
* Minor fixes

#### 3.1
* Support CryptAPI Pro
* Minor fixes

#### 3.1.1
* Minor fixes

### Upgrade Notice
* No breaking changes.
22 changes: 16 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,24 @@
"name": "cryptapi/cryptapi",
"description": "CryptAPI's Magento extension",
"type": "magento2-module",
"version": "3.0.3",
"version": "3.1.1",
"keywords": [
"cryptapi",
"magento2_module",
"magento2_payment_module",
"payment_gateway",
"magento2_payment_gateway",
"payment_processing",
"magento2_payment_processing",
"cryptocurrency"
],
"require": {
"magento/module-payment": "100.1.*",
"magento/module-checkout": "100.1.*",
"magento/module-sales": "100.1.*",
"ext-bcmath": "*",
"magento/module-payment": "^100.0.0",
"magento/module-checkout": "^100.0.0",
"magento/module-sales": "^102.0.0|^103.0.0",
"ext-curl": "*",
"ext-json": "*"
"ext-json": "*",
"ext-bcmath": "*"
},
"autoload": {
"files": [ "registration.php" ],
Expand Down
38 changes: 27 additions & 11 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
</field>
<field id="fee_order_percentage" translate="label" type="select" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Service fee manager</label>
<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>
<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>
<source_model>Cryptapi\Cryptapi\Model\Config\Source\FeesList</source_model>
</field>
<field id="qrcode_default" translate="label" type="select" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="1">
Expand All @@ -47,39 +48,54 @@
</field>
<field id="refresh_value_interval" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Refresh converted value</label>
<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>
<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>
<source_model>Cryptapi\Cryptapi\Model\Config\Source\RefreshList</source_model>
</field>
<field id="order_cancelation_timeout" translate="label" type="select" sortOrder="11" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Order cancelation timeout</label>
<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>
<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>
<source_model>Cryptapi\Cryptapi\Model\Config\Source\CancellationList</source_model>
</field>
<group id="supported_cryptocurrencies" translate="label" type="text" sortOrder="12" showInDefault="1" showInWebsite="1"
<field id="api_key" translate="label" type="text" sortOrder="12" showInDefault="1" showInWebsite="1" showInStore="1">
<label>API Key</label>
<comment>
<![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>]]>
</comment>
</field>
<group id="supported_cryptocurrencies" translate="label" type="text" sortOrder="13" showInDefault="1" showInWebsite="1"
showInStore="1">
<label>Cryptocurrencies</label>
<field id="cryptocurrencies" translate="label" sortOrder="13" showInDefault="1" showInWebsite="1"
<field id="cryptocurrencies" translate="label" sortOrder="14" showInDefault="1" showInWebsite="1"
showInStore="1">
<label>Add you address here:</label>
<frontend_model>Cryptapi\Cryptapi\Block\Adminhtml\Cryptocurrencies</frontend_model>
<backend_model>Magento\Config\Model\Config\Backend\Serialized\ArraySerialized</backend_model>
<comment>Important: Add only 1 address per cryptocurrency!</comment>
<comment>
<![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.]]>
</comment>
</field>
</group>
<field id="allowspecific" translate="label" type="allowspecific" sortOrder="14" showInDefault="1" showInWebsite="1" showInStore="1">
<field id="allowspecific" translate="label" type="allowspecific" sortOrder="15" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Countries</label>
<source_model>Magento\Payment\Model\Config\Source\Allspecificcountries</source_model>
</field>
<field id="specificcountry" translate="label" type="multiselect" sortOrder="15" showInDefault="1" showInWebsite="1" showInStore="1">
<field id="specificcountry" translate="label" type="multiselect" sortOrder="16" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Specific Countries</label>
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
</field>
<field id="sort_order" translate="label" type="text" sortOrder="16" showInDefault="1" showInWebsite="1" showInStore="1">
<field id="sort_order" translate="label" type="text" sortOrder="17" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Sort Order</label>
</field>
<field id="disable_conversion" translate="label" type="select" sortOrder="17" showInDefault="1" showInWebsite="1" showInStore="1">
<field id="disable_conversion" translate="label" type="select" sortOrder="18" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Disable price conversion</label>
<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>
<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>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</group>
Expand Down
3 changes: 2 additions & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
<color_scheme>auto</color_scheme>
<refresh_value_interval>300</refresh_value_interval>
<order_cancelation_timeout>3600</order_cancelation_timeout>
<fee_order_percentage>none</fee_order_percentage>
<add_blockchain_fee>1</add_blockchain_fee>
<fee_order_percentage>0.01</fee_order_percentage>
<can_use_checkout>1</can_use_checkout>
</cryptapi>
</payment>
Expand Down
Loading