Skip to content

Commit

Permalink
Merge pull request #1139 from PrestaShopCorp/fix/PAYSHIP-2363-webhook…
Browse files Browse the repository at this point in the history
…-url-ps7

PAYSHIP-2363 change Webhook url generation - PS1.7
  • Loading branch information
Matt75 authored Sep 25, 2023
2 parents a482501 + 14cff8d commit 22d05c8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/Api/Payment/Client/PaymentClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

namespace PrestaShop\Module\PrestashopCheckout\Api\Payment\Client;

use Configuration;
use Context;
use GuzzleHttp\Event\Emitter;
use GuzzleHttp\HandlerStack;
Expand All @@ -34,6 +33,7 @@
use PrestaShop\Module\PrestashopCheckout\Exception\HttpTimeoutException;
use PrestaShop\Module\PrestashopCheckout\Exception\PsCheckoutException;
use PrestaShop\Module\PrestashopCheckout\Logger\LoggerConfiguration;
use PrestaShop\Module\PrestashopCheckout\Routing\Router;
use PrestaShop\Module\PrestashopCheckout\ShopContext;
use PrestaShop\Module\PrestashopCheckout\Version\Version;
use Prestashop\ModuleLibGuzzleAdapter\ClientFactory;
Expand Down Expand Up @@ -69,6 +69,9 @@ public function __construct(Link $link, $client = null)
/** @var LoggerInterface $logger */
$logger = $module->getService('ps_checkout.logger');

/** @var Router $router */
$router = $module->getService('ps_checkout.prestashop.router');

$clientConfiguration = [
'base_url' => (new PaymentEnv())->getPaymentApiUrl(),
'verify' => $this->getVerify(),
Expand All @@ -79,14 +82,7 @@ public function __construct(Link $link, $client = null)
'Accept' => 'application/json',
'Authorization' => 'Bearer ' . $this->token, // Token we get from PsAccounts
'Shop-Id' => $this->shopUid, // Shop UUID we get from PsAccounts
'Hook-Url' => $this->link->getModuleLink(
'ps_checkout',
'DispatchWebHook',
[],
true,
(int) Configuration::get('PS_LANG_DEFAULT'),
(int) Context::getContext()->shop->id
),
'Hook-Url' => $router->getDispatchWebhookLink((int) Context::getContext()->shop->id),
'Bn-Code' => (new ShopContext())->getBnCode(),
'Module-Version' => $version->getSemVersion(), // version of the module
'Prestashop-Version' => _PS_VERSION_, // prestashop version
Expand Down
29 changes: 29 additions & 0 deletions src/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

namespace PrestaShop\Module\PrestashopCheckout\Routing;

use Configuration;
use Context;
use Shop;

class Router
{
Expand All @@ -35,10 +37,37 @@ public function __construct()
}

/**
* @param int|null $orderId
*
* @return string
*/
public function getContactLink($orderId = null)
{
return $this->context->link->getPageLink('contact', true, $this->context->language->id, ['id_order' => (int) $orderId]);
}

/**
* @param int $idShop
*
* @return string
*/
public function getDispatchWebhookLink($idShop)
{
$idLang = Configuration::get('PS_LANG_DEFAULT');

return $this->getBaseLink($idShop) . 'index.php?controller=DispatchWebHook&module=ps_checkout&fc=module&id_lang=' . (int) $idLang . '&id_shop=' . (int) $idShop;
}

/**
* @param int $idShop
*
* @return string
*/
private function getBaseLink($idShop)
{
$shop = new Shop($idShop);
$base = Configuration::get('PS_SSL_ENABLED') ? 'https://' . $shop->domain_ssl : 'http://' . $shop->domain;

return $base . $shop->physical_uri;
}
}

0 comments on commit 22d05c8

Please sign in to comment.