Skip to content

Commit 0929c09

Browse files
committed
v3.2.4
- Minor fixes and improvements
1 parent 2665c28 commit 0929c09

File tree

4 files changed

+55
-20
lines changed

4 files changed

+55
-20
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Accept cryptocurrency payments on your OpenCart store
77

88
```
99
OpenCart >= 3.0
10+
OpenCart < 4.0
1011
```
1112

1213
### Description
@@ -164,5 +165,8 @@ The easiest and fastest way is via our live chat on our [website](https://crypta
164165
#### 3.2.3
165166
* Minor fixes
166167

168+
#### 3.2.4
169+
* Minor fixes and improvements
170+
167171
== Upgrade Notice ==
168172
* No breaking changes

catalog/controller/extension/payment/cryptapi.php

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ public function index()
6767

6868
public function confirm()
6969
{
70+
$this->load->language('extension/payment/cryptapi');
7071
$json = array();
72+
$err_coin = '';
7173

7274
if ($this->session->data['payment_method']['code'] == 'cryptapi') {
7375
$this->load->model('checkout/order');
@@ -78,12 +80,20 @@ public function confirm()
7880
$total = $this->currency->format($order_info['total'] + $cryptoFee, $order_info['currency_code'], 1.00000, false);
7981
$currency = $this->session->data['currency'];
8082

81-
$selected = $this->request->post['cryptapi_coin'];
82-
$address = $this->config->get('payment_cryptapi_cryptocurrencies_address_' . $selected);
83-
8483
$apiKey = $this->config->get('payment_cryptapi_api_key');
84+
if (empty($this->request->post['cryptapi_coin'])) {
85+
$err_coin = $this->language->get('error_coin');
86+
} else {
87+
$selected = $this->request->post['cryptapi_coin'];
88+
$address = $this->config->get('payment_cryptapi_cryptocurrencies_address_' . $selected);
89+
if (empty($address) && empty($apiKey)) {
90+
$err_coin = $this->language->get('error_apikey');
91+
}
92+
}
93+
94+
8595

86-
if (!empty($address) || !empty($apiKey)) {
96+
if (empty($err_coin) && (!empty($address) || !empty($apiKey))) {
8797
$nonce = $this->model_extension_payment_cryptapi->generateNonce();
8898

8999
require_once(DIR_SYSTEM . 'library/cryptapi.php');
@@ -95,19 +105,21 @@ public function confirm()
95105
$minTx = floatval($info->minimum_transaction_coin);
96106

97107
$cryptoTotal = CryptAPIHelper::get_conversion($order_info['currency_code'], $selected, $total, $disable_conversion);
108+
$callbackUrl = $this->url->link('extension/payment/cryptapi/callback', 'order_id=' . $this->session->data['order_id'] . '&nonce=' . $nonce, true);
109+
$callbackUrl = str_replace('&amp;', '&', $callbackUrl);
98110

99-
if ($cryptoTotal < $minTx) {
100-
$message = $this->module->l('Payment error: ', 'validation');
101-
$message .= $this->module->l('Value too low, minimum is', 'validation');
102-
$message .= ' ' . $minTx . ' ' . strtoupper($selected);
103-
$json['error'] = $message;
104-
} else {
105-
$callbackUrl = $this->url->link('extension/payment/cryptapi/callback', 'order_id=' . $this->session->data['order_id'] . '&nonce=' . $nonce, true);
106-
$callbackUrl = str_replace('&amp;', '&', $callbackUrl);
111+
$helper = new CryptAPIHelper($selected, $address, $apiKey, $callbackUrl, [], true);
112+
$addressIn = $helper->get_address();
107113

114+
if (!isset($addressIn)) {
115+
$err_coin = $this->language->get('error_adress');
116+
} else {
117+
if (($cryptoTotal < $minTx)) {
118+
$err_coin = $this->language->get('value_minim') . ' ' . $minTx . ' ' . strtoupper($selected);
119+
}
120+
}
108121

109-
$helper = new CryptAPIHelper($selected, $address, $apiKey, $callbackUrl, [], true);
110-
$addressIn = $helper->get_address();
122+
if (empty($err_coin)) {
111123

112124
$qrCodeDataValue = $helper->get_qrcode($cryptoTotal, $qr_code_size);
113125
$qrCodeData = $helper->get_qrcode('', $qr_code_size);
@@ -135,7 +147,11 @@ public function confirm()
135147

136148
$this->model_checkout_order->addOrderHistory($this->session->data['order_id'], $this->config->get('payment_cryptapi_order_status_id'));
137149
$json['redirect'] = $this->url->link('checkout/success', 'order_id=' . $this->session->data['order_id'] . 'nonce=' . $nonce, true);
150+
} else {
151+
$json['error']['warning'] = sprintf($this->language->get('error_payment'), $err_coin);
138152
}
153+
} else {
154+
$json['error']['warning'] = sprintf($this->language->get('error_payment'), $err_coin);
139155
}
140156
}
141157

@@ -242,7 +258,7 @@ public function pay()
242258
'qr_code' => $metaData['cryptapi_qrcode'],
243259
'qr_code_value' => $metaData['cryptapi_qrcode_value'],
244260
'show_branding' => $this->config->get('payment_cryptapi_branding'),
245-
'branding_logo' => HTTPS_SERVER. 'image/catalog/cryptapi/payment.png',
261+
'branding_logo' => HTTPS_SERVER . 'image/catalog/cryptapi/payment.png',
246262
'qr_code_setting' => $this->config->get('payment_cryptapi_qrcode'),
247263
'order_timestamp' => $order['total'],
248264
'order_cancelation_timeout' => $this->config->get('payment_cryptapi_order_cancelation_timeout'),
@@ -469,7 +485,7 @@ public function cron()
469485
$this->model_extension_payment_cryptapi->updatePaymentData($order_id, 'cryptapi_last_price_update', time());
470486
}
471487

472-
if ($order_timeout !== 0 && (strtotime($order['date_added']) + $order_timeout) <= time() && $already_paid <=0 && (int)$metaData['cryptapi_cancelled'] === 0) {
488+
if ($order_timeout !== 0 && (strtotime($order['date_added']) + $order_timeout) <= time() && $already_paid <= 0 && (int)$metaData['cryptapi_cancelled'] === 0) {
473489
$this->model_checkout_order->addOrderHistory($order['order_id'], 7);
474490
$this->model_extension_payment_cryptapi->updatePaymentData($order_id, 'cryptapi_cancelled', '1');
475491
}
@@ -523,7 +539,7 @@ public function callback()
523539

524540
$metaData = json_decode($this->model_extension_payment_cryptapi->getPaymentData($order['order_id']), true);
525541

526-
$history = json_decode($metaData['cryptapi_history'], true);// <<-something's wrong
542+
$history = json_decode($metaData['cryptapi_history'], true); // <<-something's wrong
527543

528544
$calc = CryptAPIHelper::calc_order($history, $metaData['cryptapi_total'], $metaData['cryptapi_total_fiat']);
529545

@@ -562,7 +578,7 @@ function order_pay_button(&$route, &$data, &$output)
562578

563579
$orderObj = isset($order['response']) ? json_decode($order['response']) : '';
564580

565-
if(!$orderObj) {
581+
if (!$orderObj) {
566582
return;
567583
}
568584

@@ -571,4 +587,4 @@ function order_pay_button(&$route, &$data, &$output)
571587
$data['continue'] = $orderObj->cryptapi_payment_url;
572588
}
573589
}
574-
}
590+
}

catalog/language/en-gb/extension/payment/cryptapi.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
$_['text_notice'] = 'Notice';
1515
$_['text_moment'] = 'a moment';
1616

17+
$_['error_payment'] = 'Payment error: %s!';
18+
$_['value_minim'] = 'Value too low, minimum is';
19+
$_['error_coin'] = 'No cryptocurrency selected for payment';
20+
$_['error_apikey'] = 'Insufficient store owner details for payment';
21+
$_['error_adress'] = 'This cryptocurrency cannot be used for payment at this time';
22+
1723
$_['button_pay'] = 'Pay now';
1824

1925
$_['branding_logo'] = '<img src="' . HTTPS_SERVER . 'image/catalog/cryptapi/payment_success.png" alt="cryptapi" style="width:122px;" />';
@@ -50,4 +56,4 @@
5056

5157
$_['order_subject'] = 'New Order %1$s. Please send a %2$s payment';
5258
$_['order_greeting'] = 'Hello. Order %1$s was created successfully and a payment address was generated for the cryptocurrency %2$s.';
53-
$_['order_send_payment'] = 'To complete your order or check payment status, use the button provided bellow:';
59+
$_['order_send_payment'] = 'To complete your order or check payment status, use the button provided bellow:';

catalog/view/theme/default/template/extension/payment/cryptapi.twig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,18 @@
6969
$('#button-confirm').button('reset');
7070
},
7171
success: function (json) {
72+
$('.alert-dismissible, .text-danger').remove();
7273
if (json['redirect']) {
7374
location = json['redirect'];
75+
} else if (json['error']) {
76+
$('#button-confirm').button('reset');
77+
78+
if (json['error']['warning']) {
79+
$('#collapse-checkout-confirm .form-horizontal').prepend('<div class="alert alert-danger alert-dismissible">' + json['error']['warning'] + '<button type="button" class="close" data-dismiss="alert">&times;</button></div>');
80+
7481
}
82+
}
83+
7584
},
7685
error: function (xhr, ajaxOptions, thrownError) {
7786
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);

0 commit comments

Comments
 (0)