Skip to content
OpenCart · User manual

Square Payments PRO

Version 1.0.1 Product page
Chapter 7

Notifications and worker

Square notifications and a scheduled task let the store confirm payments even when the customer never returns from Square. This chapter sets up both.

How the two parts work together

  • A notification (webhook) is a message Square sends to your store when a payment is created or changes. The store checks its signature and marks the payment as needing a new check. It does not confirm the order by itself.
  • The scheduled worker is a task on your hosting account that calls the store every minute. Each run re-checks with Square the payments that were notified and those still awaiting payment or pending, and confirms the paid ones.

Without the worker, an order is confirmed only when the customer returns to the store after paying. Set up both before taking real payments.

The notification URL

Open the Payment notifications tab. Under Register the exact notification URL it shows two URLs for the selected store, Test and Live, each with a Copy URL button. The URL has this shape on OpenCart 2.3 and 3.x:

https://www.example.com/index.php?route=extension/payment/square_payments_pro/webhook&store_id=0&mode=test

The route part differs by OpenCart version, store_id is the number of the store and mode is test or live:

OpenCartRoute
1.5.5 to 2.2payment/square_payments_pro/webhook
2.3 and 3.xextension/payment/square_payments_pro/webhook
4.0.2 and laterextension/devman_square_payments_pro/payment/square_payments_pro.webhook

On OpenCart 4.0.0 and 4.0.1 the route is the same as on 4.0.2 with a vertical bar in place of the final dot before webhook. The worker URL follows the same pattern with worker in place of webhook.

Always copy the URL from the screen instead of typing it. The address uses the main domain of the installation, also for the other stores of a multi-store setup.

Create the subscription in Square

  1. Open your application in the Square Developer Console.
  2. For testing, choose the sandbox view, then Webhooks > Subscriptions, and add a subscription. Use the same application and location as the access token saved in the extension.
  3. Paste the Test URL into the notification URL field, without adding or removing any character.
  4. Select only these two events:
payment.created
payment.updated
  1. Save the subscription, open it and copy its Signature key.
  2. In the extension, paste it into Sandbox webhook signing key on the Square connection tab and press Save settings.

For real payments repeat the steps in the production view with the Live URL, and save the key in Production webhook signing key.

The signature key is not the access token and not the location ID.

The scheduled worker

Step Configure recovery with your hosting provider on the same tab shows the worker URL of the selected store. Users with modify permission can also open Show private worker key to see the key.

The task must send an HTTPS POST request:

  • to the worker URL shown on screen, with &mode=test or &mode=live added at the end. Without the mode parameter the worker processes test payments;
  • with the header X-Devman-Worker-Key containing the private worker key;
  • every minute.

The worker key has 64 characters, is created when the extension is installed and is the same for all stores of the installation. Never put it in a URL.

Example for a Linux cron job

Create a file outside the public web folder, for example /home/youruser/square-worker.conf, readable only by your user, with this single line:

header = "X-Devman-Worker-Key: PASTE_YOUR_PRIVATE_WORKER_KEY_HERE"

Then add this line to the cron jobs of your hosting account, on one line, replacing the address with the worker URL from your screen:

* * * * * curl -fsS -X POST -K /home/youruser/square-worker.conf "https://www.example.com/index.php?route=extension/payment/square_payments_pro/worker&store_id=0&mode=live" >/dev/null 2>&1

Notes:

  • Keep the quotation marks around the URL; it contains & characters.
  • While you test, use mode=test. When both modes have unsettled payments, create one task per mode.
  • In a multi-store installation, create one task per store, each with the store_id shown for that store.
  • If you cannot create cron jobs yourself, send these instructions to your hosting provider.

What the worker answers

AnswerMeaning
{"processed":true}The run finished.
HTTP 400 with {"processed":false}The request was not accepted: it is not a POST, the key header is missing or wrong, mode is not test or live, or no credentials are saved for that store and mode.
HTTP 503 with {"processed":false}A temporary problem on the server. The next run tries again.

Each run handles a few payments and stops after about 25 seconds, so a run every minute keeps up without loading the server.

Still need help?

Open a support ticket from your account and our team will look at your store with you.