Skip to content

Commit

Permalink
v1.0.1
Browse files Browse the repository at this point in the history
* Minor bugfixes and improvements.
  • Loading branch information
arianoangelo committed Apr 6, 2023
1 parent 143c725 commit 9708cd4
Show file tree
Hide file tree
Showing 25 changed files with 148 additions and 181 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ upload/

*/DS_STORE
.DS_Store

.idea
174 changes: 89 additions & 85 deletions Block/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,94 +37,98 @@ public function __construct(
public function getTemplateValues()
{

if ($this->productMetadata->getVersion() >= 2.3 && $this->productMetadata->getVersion() < 2.4) {
$order = $this->payment->getOrder();
} else {
$order_id = (int)$this->request->getParam('order_id');
$nonce = (string)$this->request->getParam('nonce');
$order = $this->orderRepository->get($order_id);
}

$total = $order->getGrandTotal();
$currencySymbol = $order->getOrderCurrencyCode();
$metaData = $this->helper->getPaymentResponse($order->getQuoteId());

if (empty($metaData)) {
throw new \Magento\Framework\Exception\AlreadyExistsException(
__('You can only add one address per cryptocurrency')
);
}

$qrCodeSize = $this->scopeConfig->getValue('payment/blockbee/qrcode_size', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);

$branding = $this->scopeConfig->getValue('payment/blockbee/show_branding', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);

$metaData = json_decode($metaData, true);

if ($nonce != $metaData['blockbee_nonce']) {
return false;
}
$cryptoValue = $metaData['blockbee_total'];
$cryptoCoin = $metaData['blockbee_currency'];

if (isset($metaData['blockbee_address']) && !empty($metaData['blockbee_address'])) {
$addressIn = $metaData['blockbee_address'];
} else {
/**
* Makes request to API and generates all the payment data needed
*/

$selected = $cryptoCoin;

$params = [
try {
if ($this->productMetadata->getVersion() >= 2.3 && $this->productMetadata->getVersion() < 2.4) {
$order = $this->payment->getOrder();
} else {
$order_id = (int)$this->request->getParam('order_id');
$nonce = (string)$this->request->getParam('nonce');
$order = $this->orderRepository->get($order_id);
}

$total = $order->getGrandTotal();
$currencySymbol = $order->getOrderCurrencyCode();
$metaData = $this->helper->getPaymentResponse($order->getQuoteId());

if (empty($metaData)) {
throw new \Magento\Framework\Exception\AlreadyExistsException(
__('You can only add one address per cryptocurrency')
);
}

$qrCodeSize = $this->scopeConfig->getValue('payment/blockbee/qrcode_size', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);

$branding = $this->scopeConfig->getValue('payment/blockbee/show_branding', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);

$metaData = json_decode($metaData, true);

if ($nonce != $metaData['blockbee_nonce']) {
return false;
}
$cryptoValue = $metaData['blockbee_total'];
$cryptoCoin = $metaData['blockbee_currency'];

if (isset($metaData['blockbee_address']) && !empty($metaData['blockbee_address'])) {
$addressIn = $metaData['blockbee_address'];
} else {
/**
* Makes request to API and generates all the payment data needed
*/

$selected = $cryptoCoin;

$params = [
'order_id' => $order->getId(),
'nonce' => $metaData['blockbee_nonce'],
];

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

$apiKey = $this->scopeConfig->getValue('payment/blockbee/api_key', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);

$api = new BlockbeeHelper($selected, $apiKey, $callbackUrl, $params, true);
$addressIn = $api->get_address();
$qrCode = $api->get_qrcode('', $qrCodeSize);
$qrCodeValue = $api->get_qrcode($cryptoValue, $qrCodeSize);
$this->helper->updatePaymentData($order->getQuoteId(), 'blockbee_address', $addressIn);
$this->helper->updatePaymentData($order->getQuoteId(), 'blockbee_qr_code_value', $qrCodeValue['qr_code']);
$this->helper->updatePaymentData($order->getQuoteId(), 'blockbee_qr_code', $qrCode['qr_code']);
$this->helper->updatePaymentData($order->getQuoteId(), 'blockbee_payment_url', $this->storeManager->getStore()->getUrl('blockbee/index/payment/order_id/' . $order->getId() . '/nonce/' . $metaData['blockbee_nonce']));

$metaData = json_decode($this->helper->getPaymentResponse($order->getQuoteId()), true);
$this->mail->sendMail($order, $metaData);
}

$ajaxParams = [
'order_id' => $order->getId(),
'nonce' => $metaData['blockbee_nonce'],
];

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

$apiKey = $this->scopeConfig->getValue('payment/blockbee/api_key', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);

$api = new BlockbeeHelper($selected, $apiKey, $callbackUrl, $params, true);
$addressIn = $api->get_address();
$qrCode = $api->get_qrcode('', $qrCodeSize);
$qrCodeValue = $api->get_qrcode($cryptoValue, $qrCodeSize);
$this->helper->updatePaymentData($order->getQuoteId(), 'blockbee_address', $addressIn);
$this->helper->updatePaymentData($order->getQuoteId(), 'blockbee_qr_code_value', $qrCodeValue['qr_code']);
$this->helper->updatePaymentData($order->getQuoteId(), 'blockbee_qr_code', $qrCode['qr_code']);
$this->helper->updatePaymentData($order->getQuoteId(), 'blockbee_payment_url', $this->storeManager->getStore()->getUrl('blockbee/index/payment/order_id/' . $order->getId(). '/nonce/' . $metaData['blockbee_nonce']));

$metaData = json_decode($this->helper->getPaymentResponse($order->getQuoteId()), true);
$this->mail->sendMail($order, $metaData);
$ajaxUrl = $this->payment->getAjaxStatusUrl($ajaxParams);

$metaData = $this->helper->getPaymentResponse($order->getQuoteId());
$metaData = json_decode($metaData, true);

return [
'crypto_value' => floatval($cryptoValue),
'currency_symbol' => $currencySymbol,
'total' => $total,
'address_in' => $addressIn,
'crypto_coin' => $cryptoCoin,
'ajax_url' => $ajaxUrl,
'qrcode_size' => $qrCodeSize,
'qrcode' => $metaData['blockbee_qr_code'],
'qrcode_value' => $metaData['blockbee_qr_code_value'],
'qrcode_default' => $this->scopeConfig->getValue('payment/blockbee/qrcode_default', \Magento\Store\Model\ScopeInterface::SCOPE_STORE),
'show_branding' => $branding,
'qr_code_setting' => $this->scopeConfig->getValue('payment/blockbee/qrcode_setting', \Magento\Store\Model\ScopeInterface::SCOPE_STORE),
'order_timestamp' => strtotime($order->getCreatedAt()),
'order_cancelation_timeout' => $this->scopeConfig->getValue('payment/blockbee/order_cancelation_timeout', \Magento\Store\Model\ScopeInterface::SCOPE_STORE),
'refresh_value_interval' => $this->scopeConfig->getValue('payment/blockbee/refresh_value_interval', \Magento\Store\Model\ScopeInterface::SCOPE_STORE),
'last_price_update' => $metaData['blockbee_last_price_update'],
'min_tx' => $metaData['blockbee_min'],
];
} catch (\Exception $exception) {
// Empty
}

$ajaxParams = [
'order_id' => $order->getId(),
];

$ajaxUrl = $this->payment->getAjaxStatusUrl($ajaxParams);

$metaData = $this->helper->getPaymentResponse($order->getQuoteId());
$metaData = json_decode($metaData, true);

return [
'crypto_value' => floatval($cryptoValue),
'currency_symbol' => $currencySymbol,
'total' => $total,
'address_in' => $addressIn,
'crypto_coin' => $cryptoCoin,
'ajax_url' => $ajaxUrl,
'qrcode_size' => $qrCodeSize,
'qrcode' => $metaData['blockbee_qr_code'],
'qrcode_value' => $metaData['blockbee_qr_code_value'],
'qrcode_default' => $this->scopeConfig->getValue('payment/blockbee/qrcode_default', \Magento\Store\Model\ScopeInterface::SCOPE_STORE),
'show_branding' => $branding,
'qr_code_setting' => $this->scopeConfig->getValue('payment/blockbee/qrcode_setting', \Magento\Store\Model\ScopeInterface::SCOPE_STORE),
'order_timestamp' => strtotime($order->getCreatedAt()),
'order_cancelation_timeout' => $this->scopeConfig->getValue('payment/blockbee/order_cancelation_timeout', \Magento\Store\Model\ScopeInterface::SCOPE_STORE),
'refresh_value_interval' => $this->scopeConfig->getValue('payment/blockbee/refresh_value_interval', \Magento\Store\Model\ScopeInterface::SCOPE_STORE),
'last_price_update' => $metaData['blockbee_last_price_update'],
'min_tx' => $metaData['blockbee_min'],
];
}
}
1 change: 0 additions & 1 deletion Cron/BlockbeeCronjob.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public function execute()
$qrcode_size = $this->scopeConfig->getValue('payment/blockbee/qrcode_size');

if (!empty($metaData['blockbee_address']) && $value_refresh !== 0 && $metaData['blockbee_cancelled'] !== '1' && (int)$metaData['blockbee_last_price_update'] + $value_refresh <= time() && $remaining_pending > 0) {

if ($remaining === $remaining_pending) {
$blockbee_coin = $metaData['blockbee_currency'];

Expand Down
6 changes: 3 additions & 3 deletions Model/Total/Fee.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public function collect(

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

$total->setTotalAmount('fee', $fee);
$total->setBaseTotalAmount('fee', $fee);
$total->setTotalAmount('blockbee_fee', $fee);
$total->setBaseTotalAmount('blockbee_fee', $fee);
$total->setFee($fee);
$total->setBaseFee($fee);
$total->setGrandTotal($total->getGrandTotal());
Expand Down Expand Up @@ -77,7 +77,7 @@ protected function clearValues(Total $total)
public function fetch(Quote $quote, Total $total)
{
return [
'code' => 'fee',
'code' => 'blockbee_fee',
'title' => __('Service Fee'),
'value' => $this->calculateFee($quote),
];
Expand Down
24 changes: 11 additions & 13 deletions Model/Ui/BlockbeeConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
class BlockbeeConfigProvider implements ConfigProviderInterface
{
const CODE = 'blockbee';

protected $logger;

public function __construct(
Expand All @@ -20,7 +19,7 @@ public function __construct(
\Magento\Framework\App\CacheInterface $cache,
\Magento\Framework\Serialize\SerializerInterface $serializer,
\Blockbee\Blockbee\Model\Method\BlockbeePayment $payment,
\Psr\Log\LoggerInterface $logger
\Psr\Log\LoggerInterface $logger
)
{
$this->escaper = $escaper;
Expand All @@ -32,32 +31,31 @@ public function __construct(
$this->logger = $logger;
}

public function getConfig()
public function getConfig(): array
{
$config = [
'payment' => array(
self::CODE => array(
return [
'payment' => [
self::CODE => [
'cryptocurrencies' => $this->getCryptocurrencies(),
'instructions' => $this->getInstructions(),
)
)
]
]
];
return $config;
}

public function getInstructions()
public function getInstructions(): \Magento\Framework\Phrase
{
return __('Pay with cryptocurrency');
}

public function getCryptocurrencies()
public function getCryptocurrencies(): array
{
$cacheKey = \Blockbee\Blockbee\Model\Cache\Type::TYPE_IDENTIFIER;
$cacheTag = \Blockbee\Blockbee\Model\Cache\Type::CACHE_TAG;

if (empty($this->cache->load($cacheKey)) || !json_decode($this->cache->load($cacheKey))) {
if (empty($this->cache->load($cacheKey)) || !$this->serializer->unserialize($this->cache->load($cacheKey))) {
$this->cache->save(
$this->serializer->serialize(json_encode(BlockbeeHelper::get_supported_coins())),
$this->serializer->serialize($this->serializer->serialize(BlockbeeHelper::get_supported_coins())),
$cacheKey,
[$cacheTag],
86400
Expand Down
3 changes: 1 addition & 2 deletions Observer/QuoteSubmitBefore.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public function execute(Observer $observer)

if ($paymentMethod === 'blockbee') {
$order =$observer->getOrder();
$order->setData('blockbee_fee', (float)$quote->getData('fee'));
$order->setData('blockbee_fee', (float)$quote->getData('blockbee_fee'));
}

}
}
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ For more info on our fees [click here](https://blockbee.io/fees/)
php bin/magento module:enable Blockbee_Blockbee
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy -f
php bin/magento cache:flush
php bin/magento cache:enable blockbee_cryptocurrencies
```

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

### Changelog

#### 1.0
#### 1.0.0
* Initial release.

#### 1.0.1
* Minor bugfixes and improvements.

### Upgrade Notice
* No breaking changes.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "blockbee/blockbee",
"description": "BlockBee's Magento extension",
"type": "magento2-module",
"version": "1.0.0",
"version": "1.0.1",
"keywords": [
"blockbee",
"magento2_module",
Expand Down
2 changes: 1 addition & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<payment>
<blockbee>
<model>Blockbee\Blockbee\Model\Method\BlockbeePayment</model>
<title>Cryptocurrency</title>
<title>Pay With BlockBee</title>
<active>0</active>
<show_branding>1</show_branding>
<disable_conversion>0</disable_conversion>
Expand Down
4 changes: 2 additions & 2 deletions etc/extension_attributes.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
<extension_attributes for="Magento\Quote\Api\Data\CartInterface">
<attribute code="fee" type="float" />
<attribute code="blockbee_fee" type="float" />
</extension_attributes>
<extension_attributes for="Magento\Sales\Api\Data\OrderInterface">
<attribute code="fee" type="float" />
<attribute code="blockbee_fee" type="float" />
</extension_attributes>
</config>
9 changes: 4 additions & 5 deletions etc/fieldset.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:DataObject/etc/fieldset.xsd">
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:DataObject/etc/fieldset.xsd">
<scope id="global">
<fieldset id="blockbee_sales_convert_quote">
<field name="fee">
<aspect name="to_order" targetField="fee" />
<fieldset id="blockbee_sales_convert_quote">
<field name="blockbee_fee">
<aspect name="to_order" targetField="blockbee_fee"/>
</field>
</fieldset>
</scope>
Expand Down
2 changes: 1 addition & 1 deletion etc/frontend/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<type name="Magento\Checkout\Model\CompositeConfigProvider">
<arguments>
<argument name="configProviders" xsi:type="array">
<item name="custom_payment_config_provider" xsi:type="object">Blockbee\Blockbee\Model\Ui\BlockbeeConfigProvider</item>
<item name="blockbee_blockbee_config_provider" xsi:type="object">Blockbee\Blockbee\Model\Ui\BlockbeeConfigProvider</item>
</argument>
</arguments>
</type>
Expand Down
2 changes: 1 addition & 1 deletion etc/sales.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Sales:etc/sales.xsd">
<section name="quote">
<group name="totals">
<item name="fee" instance="Blockbee\Blockbee\Model\Total\Fee" sort_order="150"/>
<item name="blockbee_fee" instance="Blockbee\Blockbee\Model\Total\Fee" sort_order="150"/>
</group>
</section>
</config>
Loading

0 comments on commit 9708cd4

Please sign in to comment.