Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure client is available in validation.php #87

Merged
merged 1 commit into from
Nov 15, 2023
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 modules/btcpay/btcpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function __construct()
{
$this->name = 'btcpay';
$this->tab = 'payments_gateways';
$this->version = '6.0.0';
$this->version = '6.0.1';
$this->author = 'BTCPay Server';
$this->ps_versions_compliancy = ['min' => Constants::MINIMUM_PS_VERSION, 'max' => _PS_VERSION_];
$this->controllers = ['payment', 'validation', 'webhook'];
Expand Down
17 changes: 9 additions & 8 deletions modules/btcpay/controllers/front/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use BTCPay\Constants;
use BTCPay\Invoice\Processor;
use BTCPay\LegacyBitcoinPaymentRepository;
use BTCPay\Server\Client;
use PrestaShop\PrestaShop\Adapter\Configuration;

class BTCPayValidationModuleFrontController extends ModuleFrontController
Expand All @@ -29,18 +30,12 @@ class BTCPayValidationModuleFrontController extends ModuleFrontController
*/
private $repository;

/**
* @var Processor
*/
private $processor;

public function __construct()
{
parent::__construct();

$this->configuration = new Configuration();
$this->repository = new LegacyBitcoinPaymentRepository();
$this->processor = new Processor($this->module, $this->configuration, $this->client);
}

/**
Expand Down Expand Up @@ -104,8 +99,14 @@ public function postProcess(): void
return;
}

// User was quicker than the callback, deal with the actual invoice now
$this->processor->paymentReceivedCreateAfter($bitcoinPayment);
// Ensure the client is ready for use
if (null === ($client = Client::createFromConfiguration($this->configuration)) || false === $client->isValid()) {
throw new RuntimeException('Expected the client to be available');
}

// User was quicker than the callback, so we deal with the actual invoice now
$processor = new Processor($this->module, $this->configuration, $client);
$processor->paymentReceivedCreateAfter($bitcoinPayment);

// Grab the (now existing) order
$order = Order::getByCartId($bitcoinPayment->getCartId());
Expand Down