Skip to content

Commit

Permalink
Merge pull request #15 from ndeet/session-check
Browse files Browse the repository at this point in the history
Fix checkout in case session contains outdated order id; bump version.
  • Loading branch information
ndeet authored Oct 19, 2023
2 parents 7aa2264 + 8d27778 commit 9e87e5e
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 2 deletions.
17 changes: 17 additions & 0 deletions catalog/controller/payment/btcpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ public function index(): string
true
);

if (isset($this->session->data['error_warning'])) {
$data['error_warning'] = $this->session->data['error_warning'];
unset($this->session->data['error_warning']);
} else {
$data['error_warning'] = '';
}

if ($useModal) {
$host = $this->config->get('payment_btcpay_url');
$data['btcpay_host'] = $host;
Expand Down Expand Up @@ -63,6 +70,16 @@ public function checkout(): void
$this->session->data['order_id']
);

if (empty($order_info)) {
if ($debug) {
$this->log->write('Could not load order passed by session, order id: ' . $this->session->data['order_id']);
}
$this->session->data['error_warning'] = $this->language->get('session_checkout_order_error');
$this->response->redirect(
$this->url->link('checkout/checkout', '', true)
);
}

$invoiceId = '';
$checkoutLink = '';

Expand Down
1 change: 1 addition & 0 deletions catalog/language/en-gb/payment/btcpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
$_['invoice_closed_text'] = 'Payment aborted. Please try again or choose a different payment method.';
$_['invoice_failed_text'] = 'Payment aborted. Error processing the request. Please contact store owner if the problem persists.';
$_['order_payment_link'] = 'You can check your payment status here: ';
$_['session_checkout_order_error'] = 'Your cart order id could not be found, please try to log out and in again.';
3 changes: 3 additions & 0 deletions catalog/view/template/payment/btcpay.twig
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{% if error_warning %}
<div class="alert alert-danger">{{ error_warning }}</div>
{% endif %}
<form action="{{ action }}" method="post">
<div class="buttons">
<div class="text-end">
Expand Down
2 changes: 2 additions & 0 deletions catalog/view/template/payment/btcpay_modal.twig
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
if (data.invoiceId !== undefined) {
window.btcpay.setApiUrlPrefix('{{ btcpay_host }}');
window.btcpay.showInvoice(data.invoiceId);
} else {
showError('{{ invoice_failed_text }}');
}
let invoice_paid = false;
window.btcpay.onModalReceiveMessage(function (event) {
Expand Down
2 changes: 1 addition & 1 deletion install.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "BTCPay Server payment gateway",
"version": "4.2.1",
"version": "4.2.2",
"license": "MIT",
"author": "BTCPay Server",
"link": "https://btcpayserver.org"
Expand Down
2 changes: 1 addition & 1 deletion system/library/btcpay/version.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php

define('BTCPAY_OPENCART_EXTENSION_VERSION', '4.2.1');
define('BTCPAY_OPENCART_EXTENSION_VERSION', '4.2.2');

0 comments on commit 9e87e5e

Please sign in to comment.