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

Webhook is not getting the store_id from the request. #528

Open
kpitn opened this issue Sep 12, 2023 · 1 comment
Open

Webhook is not getting the store_id from the request. #528

kpitn opened this issue Sep 12, 2023 · 1 comment

Comments

@kpitn
Copy link

kpitn commented Sep 12, 2023

Hi,

Currently, when a request comes from checkout.com to the /checkout_com/webhook/callback page, the store code is the defaut store code from the website.

//File : Controller/Webhook/Callback.php
// Get the store code
$storeCode = $this->storeManager->getStore()->getCode();

The problem arises if we have secret keys per store but only one webhook configured in the Checkout.com back office. In this case, the request doesn't work and returns "The endpoint did not accept the request. (Code: 404)."

Here is a simple and effective fix that retrieves the store code from the request content:

--- Controller/Webhook/Callback.php
+++ Controller/Webhook/Callback.php
@@ -178,6 +178,15 @@
                         // Get the store code
                         $storeCode = $this->storeManager->getStore()->getCode();

+			             if ($payload &&
+			                 isset($payload->data->metadata->quote_data) &&
+			                 ($quoteData = json_decode($payload->data->metadata->quote_data, true)) &&
+			                 isset($quoteData['store_id'])
+			             ) {
+			                 $storeCode = $quoteData['store_id'];
+			             }
+
+
                         // Initialize the API handler
                         $api = $this->apiHandler->init($storeCode, ScopeInterface::SCOPE_STORE);

2nd Problem:
Moreover, you encounter the same issue in the back office when attempting to refund an invoice. It looks for the default secret key instead of the one associated with the invoice's store.

Again, this results in the same error: "The endpoint did not accept the request. (Code: 404)."

@manuel-EGO
Copy link

We had the same issue, we fixed it by creating different webhooks per store/website on checkout.com dashboard, each webhook, using the correct base url.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants