Skip to content

Commit b2c208b

Browse files
author
Ariano Fonseca Ângelo
committed
v3.2.0
- Support for BlockBee - Add e-mail with link for order payment - Minor fixes
1 parent 86b3efc commit b2c208b

File tree

11 files changed

+202
-9
lines changed

11 files changed

+202
-9
lines changed

Block/Payment.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public function __construct(
1818
\Magento\Sales\Api\OrderRepositoryInterface $orderRepository,
1919
\Magento\Framework\App\Request\Http $request,
2020
\Magento\Framework\App\ProductMetadataInterface $productMetadata,
21+
\Magento\Store\Model\StoreManagerInterface $storeManager,
22+
\Cryptapi\Cryptapi\Helper\Mail $mail,
2123
array $data = []
2224
)
2325
{
@@ -28,6 +30,9 @@ public function __construct(
2830
$this->request = $request;
2931
$this->orderRepository = $orderRepository;
3032
$this->productMetadata = $productMetadata;
33+
$this->mail = $mail;
34+
$this->storeManager = $storeManager;
35+
3136
}
3237

3338
public function getTemplateValues()
@@ -54,10 +59,8 @@ public function getTemplateValues()
5459

5560
$metaData = json_decode($metaData, true);
5661

57-
if (!$this->productMetadata->getVersion() >= 2.3 && $this->productMetadata->getVersion() < 2.4) {
58-
if ($nonce != $metaData['cryptapi_nonce']) {
59-
return false;
60-
}
62+
if ($nonce != $metaData['cryptapi_nonce']) {
63+
return false;
6164
}
6265

6366
$cryptoValue = $metaData['cryptapi_total'];
@@ -66,6 +69,10 @@ public function getTemplateValues()
6669
if (isset($metaData['cryptapi_address']) && !empty($metaData['cryptapi_address'])) {
6770
$addressIn = $metaData['cryptapi_address'];
6871
} else {
72+
/*
73+
* Makes request to API and generates all the payment data needed
74+
*/
75+
6976
$selected = $cryptoCoin;
7077

7178
$address = '';
@@ -96,6 +103,10 @@ public function getTemplateValues()
96103
$this->helper->updatePaymentData($order->getQuoteId(), 'cryptapi_address', $addressIn);
97104
$this->helper->updatePaymentData($order->getQuoteId(), 'cryptapi_qr_code_value', $qrCodeValue['qr_code']);
98105
$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']));
107+
108+
$metaData = json_decode($this->helper->getPaymentResponse($order->getQuoteId()), true);
109+
$this->mail->sendMail($order, $metaData);
99110
}
100111

101112
$ajaxParams = [

Controller/Index/Status.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function execute()
8282
'qr_code_value' => $metaData['cryptapi_qr_code_value'],
8383
'cancelled' => $metaData['cryptapi_cancelled'],
8484
'remaining' => $remaining_pending <= 0 ? 0 : $remaining_pending,
85-
'fiat_remaining' => $this->priceHelper->currency($remaining_fiat, true, false),
85+
'fiat_remaining' => $this->priceHelper->currency(($remaining_fiat <= 0 ? 0 : $remaining_fiat), true, false),
8686
'coin' => strtoupper($metaData['cryptapi_currency']),
8787
'show_min_fee' => $showMinFee,
8888
'order_history' => $history,

Helper/Mail.php

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
<?php
2+
3+
namespace Cryptapi\Cryptapi\Helper;
4+
5+
use Psr\Log\LoggerInterface;
6+
use Magento\Framework\App\Area;
7+
use Magento\Store\Model\ScopeInterface;
8+
use Magento\Framework\App\Helper\Context;
9+
use Magento\Store\Model\StoreManagerInterface;
10+
use Magento\Framework\Exception\MailException;
11+
use Magento\Framework\App\Helper\AbstractHelper;
12+
use Magento\Framework\Exception\LocalizedException;
13+
use Magento\Framework\Mail\Template\TransportBuilder;
14+
use Magento\Framework\Translate\Inline\StateInterface;
15+
16+
class Mail extends AbstractHelper
17+
{
18+
/**
19+
* @var StateInterface
20+
*/
21+
private $inlineTranslation;
22+
23+
/**
24+
* @var TransportBuilder
25+
*/
26+
private $transportBuilder;
27+
28+
/**
29+
* @var StoreManagerInterface
30+
*/
31+
private $storeManager;
32+
33+
/**
34+
* @var LoggerInterface
35+
*/
36+
private $logger;
37+
38+
/**
39+
* Data constructor.
40+
* @param Context $context
41+
* @param StoreManagerInterface $storeManager
42+
* @param TransportBuilder $transportBuilder
43+
* @param StateInterface $inlineTranslation
44+
* @param LoggerInterface $logger
45+
*/
46+
public function __construct(
47+
Context $context,
48+
StoreManagerInterface $storeManager,
49+
TransportBuilder $transportBuilder,
50+
StateInterface $inlineTranslation,
51+
LoggerInterface $logger
52+
)
53+
{
54+
$this->storeManager = $storeManager;
55+
$this->transportBuilder = $transportBuilder;
56+
$this->inlineTranslation = $inlineTranslation;
57+
$this->logger = $logger;
58+
parent::__construct($context);
59+
}
60+
61+
/**
62+
* Send Mail
63+
*
64+
* @return $this
65+
*
66+
* @throws LocalizedException
67+
* @throws MailException
68+
*/
69+
public function sendMail($order, $metadata)
70+
{
71+
$customerId = $order->getCustomerId();
72+
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
73+
$scopeConfig = $objectManager->create('\Magento\Framework\App\Config\ScopeConfigInterface');
74+
75+
$customerData = $objectManager->create('Magento\Customer\Model\Customer')->load($customerId);
76+
77+
$email = $customerData->getEmail();
78+
79+
$storeId = $this->getStoreId();
80+
$orderId = $order->getId();
81+
$coin = $metadata['cryptapi_currency'];
82+
$url = $metadata['cryptapi_payment_url'];
83+
84+
$sender = [
85+
'email' => $scopeConfig->getValue('trans_email/ident_sales/email', ScopeInterface::SCOPE_STORE),
86+
'name' => $scopeConfig->getValue('trans_email/ident_sales/name', ScopeInterface::SCOPE_STORE)
87+
];
88+
89+
$this->inlineTranslation->suspend();
90+
91+
$vars = [
92+
'order' => $orderId,
93+
'coin' => strtoupper($coin),
94+
'url' => $url,
95+
];
96+
97+
$postObject = new \Magento\Framework\DataObject();
98+
$postObject->setData($vars);
99+
100+
$transport = $this->transportBuilder->setTemplateIdentifier(
101+
'cryptapi_email_link'
102+
)->
103+
setTemplateVars(['data' => $postObject])->
104+
setTemplateOptions([
105+
'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
106+
'store' => $storeId,
107+
])->
108+
setFromByScope($sender)->
109+
addTo($email)->
110+
getTransport();
111+
112+
try {
113+
$transport->sendMessage();
114+
} catch (\Exception $exception) {
115+
$this->logger->critical($exception->getMessage());
116+
}
117+
$this->inlineTranslation->resume();
118+
119+
return $this;
120+
}
121+
122+
/*
123+
* get Current store id
124+
*/
125+
public function getStoreId()
126+
{
127+
return $this->storeManager->getStore()->getId();
128+
}
129+
130+
/*
131+
* get Current store Info
132+
*/
133+
public function getStore()
134+
{
135+
return $this->storeManager->getStore();
136+
}
137+
}
138+
139+

Model/Method/CryptapiPayment.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ public function validate()
161161
'cryptapi_min' => $minTx,
162162
'cryptapi_qr_code_value' => '',
163163
'cryptapi_qr_code' => '',
164+
'cryptapi_payment_url' => ''
164165
];
165166

166167
$paymentData = json_encode($paymentData);

Model/Ui/CryptapiConfigProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function getCryptocurrencies()
4949
$cacheKey = \Cryptapi\Cryptapi\Model\Cache\Type::TYPE_IDENTIFIER;
5050
$cacheTag = \Cryptapi\Cryptapi\Model\Cache\Type::CACHE_TAG;
5151

52-
if (empty($this->cache->load($cacheKey))) {
52+
if (empty($this->cache->load($cacheKey)) || !json_decode($this->cache->load($cacheKey))) {
5353
$this->cache->save(
5454
$this->serializer->serialize(json_encode(CryptAPIHelper::get_supported_coins())),
5555
$cacheKey,

Observer/AfterSuccess.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Magento\Framework\Event\Observer;
66
use Magento\Framework\Event\ObserverInterface;
7+
use Cryptapi\Cryptapi\Helper\Mail;
78

89
class AfterSuccess implements ObserverInterface
910
{
@@ -16,7 +17,6 @@ public function __construct(
1617
\Psr\Log\LoggerInterface $logger,
1718
\Magento\Framework\App\ProductMetadataInterface $productMetadata,
1819
\Magento\Framework\App\Response\Http $redirect
19-
2020
)
2121
{
2222
$this->helper = $helper;

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,5 +151,10 @@ The easiest and fastest way is via our live chat on our [website](https://crypta
151151
#### 3.1.1
152152
* Minor fixes
153153

154+
#### 3.2.0
155+
* Support for BlockBee
156+
* Add e-mail with link for order payment
157+
* Minor fixes
158+
154159
### Upgrade Notice
155160
* 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.1.1",
5+
"version": "3.2.0",
66
"keywords": [
77
"cryptapi",
88
"magento2_module",

etc/email_templates.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Email:etc/email_templates.xsd">
2+
<template id="cryptapi_email_link"
3+
label="CryptAPI E-mail Link"
4+
file="cryptapi_email_link.html"
5+
type="html"
6+
module="Cryptapi_Cryptapi"
7+
area="frontend"
8+
/>
9+
</config>

lib/CryptAPIHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
class CryptAPIHelper
66
{
77
private static $base_url = "https://api.cryptapi.io";
8-
private static $pro_url = "https://pro-api.cryptapi.io";
8+
private static $pro_url = "https://api.blockbee.io";
99
private $own_address = null;
1010
private $payment_address = null;
1111
private $callback_url = null;

0 commit comments

Comments
 (0)