Skip to content
OpenCart · User manual

Braintree Payments PRO

Version 1.0.1 Product page
Chapter 7

Recovery worker

A scheduled task asks Braintree about payments whose result is not final. This chapter explains why it is needed and how to schedule it with the exact URL and key.

Why there is a worker and no webhook

This version does not use Braintree webhooks. Do not register any URL of the extension as a webhook destination in the Braintree Control Panel.

Instead, the store itself asks Braintree for the state of a payment. Most payments are settled in the same request in which the customer pays. The worker deals with the rest:

  • The answer from Braintree was lost (a timeout, a server restart, a closed browser). The attempt is marked as uncertain and the worker looks for the original transaction.
  • The transaction was authorised but is not yet submitted for settlement.
  • A payment that was already confirmed changes later at Braintree, for example because you voided or refunded it. The worker rechecks confirmed payments about once an hour during the 31 days after they were created.

The worker only reads from Braintree. It never sends a charge. A card is charged at most once per attempt, when the customer submits the payment page.

The Payment notifications tab

Open the Payment notifications tab. It contains, from top to bottom:

  1. A six-step setup guide.
  2. A reminder that the URLs on this tab are worker endpoints, not Braintree webhooks.
  3. The Test worker URL and the Live worker URL of the store selected in Store.
  4. A link to Braintree's documentation, Read the official Braintree setup documentation.
  5. Reconciliation worker: the same URL without the mode. Called like this, the worker uses test mode.
  6. Private worker key: the 64-character key the worker requires. It is shown only to users with modify permission.

How the worker must be called

PartValue
MethodPOST. Any other method is rejected
URLThe Test or Live URL from the tab, copied exactly
store_idThe numeric id of the store. 0 is the default store
modetest or live. Without it, test is used
HeaderX-Devman-Worker-Key: followed by the private worker key

The route inside the URL depends on your OpenCart version, which is why you copy it from the tab. These are its shapes:

OpenCart 1.5 to 2.2
https://www.example.com/index.php?route=payment/braintree_payments_pro/worker&store_id=0&mode=live

OpenCart 2.3 and 3.x
https://www.example.com/index.php?route=extension/payment/braintree_payments_pro/worker&store_id=0&mode=live

OpenCart 4.0.2 and later
https://www.example.com/index.php?route=extension/devman_braintree_payments_pro/payment/braintree_payments_pro.worker&store_id=0&mode=live

The key travels in a header, never in the URL. One key serves every store of the installation.

Schedule it with cron

Run the worker once per minute. Keep the key in a small configuration file outside the public web folder, so it never appears in the process list or in your web space.

  1. Create a file outside your web root, for example /home/youruser/braintree-worker.conf, with this single line (replace the key with yours):
header = "X-Devman-Worker-Key: 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
  1. Restrict the file to your own user:
chmod 600 /home/youruser/braintree-worker.conf
  1. Add a cron job that runs every minute. Paste your own Live URL between the quotes:
* * * * * curl -fsS -X POST -K /home/youruser/braintree-worker.conf "https://www.example.com/index.php?route=extension/payment/braintree_payments_pro/worker&store_id=0&mode=live" >/dev/null 2>&1

In a hosting panel with a scheduled tasks screen, choose "every minute" and enter the command from curl onwards. If you cannot create cron jobs, ask your hosting provider to schedule this request.

To test it, run the request once by hand and read the answer:

curl -sS -i -X POST -K /home/youruser/braintree-worker.conf "https://www.example.com/index.php?route=extension/payment/braintree_payments_pro/worker&store_id=0&mode=live"

What the worker answers

AnswerMeaning
{"processed":true}The call was accepted and the due payments were checked
{"processed":false} with HTTP 400The call is wrong: not a POST, an invalid store_id or mode, a missing or wrong key, or the credentials of that mode are incomplete for that store
{"processed":false} with HTTP 503A temporary problem. The next run tries again

Each run checks up to five payments of the given store and mode, oldest first, and stops after about 25 seconds. A payment becomes due one minute after its last change.

One task per store and mode

The worker handles one store and one mode per call.

  • While you are testing, schedule the Test URL.
  • When you go live, schedule the Live URL. Keep the test task until no sandbox payments are left pending.
  • In a multi-store installation, schedule one task for each store that uses the method. Select the store in Store and copy its URLs. The header and key are the same.

Still need help?

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