Integration to import WooCommerce orders as Sales Invoices
Phase 1 now includes optional real‑time syncing for Customers and Orders.
Configure in WooCommerce (WP Admin > WooCommerce > Settings > Advanced > Webhooks):
- Create (or edit) a webhook:
- Status: Active
- Topic: Order created (repeat separately for Order updated) OR use Order updated only (covers creation + changes depending on store setup)
- Delivery URL:
https://YOUR-ERP-HOST/api/method/jarz_woocommerce_integration.jarz_woocommerce_integration.api.orders.woo_order_webhook
- Delivery URL:
- Secret: (paste the same secret you store in WooCommerce Settings inside ERPNext)
- Repeat for Customer created / updated using endpoint:
-
https://YOUR-ERP-HOST/api/method/jarz_woocommerce_integration.jarz_woocommerce_integration.api.webhooks.woo_customer_webhook - Save.
ERPNext Setup:
- Open "WooCommerce Settings" DocType
- Set Base URL, Consumer Key & Secret (for REST fallback/pulls)
- Enter Webhook Secret (Password field)
- Save.
Security / Signature:
- Both endpoints validate
X-WC-Webhook-Signature(base64 HMAC-SHA256 of raw body) using the shared secret. - Empty payloads during WooCommerce webhook creation are ACKed (
{"ack": true}) without signature failure so you can finish setup.
Processing Model:
- Webhook request enqueues a background job and returns immediately (
{"queued": true}) - The job fetches the full order via REST (
pull_single_order_phase1) ensuring consistent transform rules with manual pulls. - Idempotent: existing Sales Invoices matched by
woo_order_idare updated (lines replaced if still Draft; selective field updates if Submitted as allowed). - Sync outcomes are recorded in
WooCommerce Sync Logwith operation =Webhook.
Fallback / Manual Pull:
- Continue to use manual pull endpoints if needed:
/api/method/jarz_woocommerce_integration.jarz_woocommerce_integration.api.orders.pull_recent_phase1/api/method/jarz_woocommerce_integration.jarz_woocommerce_integration.api.orders.pull_order_phase1?order_id=123
Troubleshooting:
- Signature mismatch (403): ensure secret identical, no whitespace, and that your site is reachable via HTTPS.
- Webhook shows delivered but invoice not created: check
WooCommerce Sync Logand server logs forwoo_order_webhook_*events. - To test locally, POST an order JSON with header
X-WC-Webhook-Signatureusing the computed signature (see developer helper inapi/webhooks.py).
Limitations (current phase):
- Refunds / cancellations beyond status mapping not yet implemented.
- Inventory push-back not yet enabled.
- Partial update of already submitted invoices limited to selected fields (status, custom state, POS profile, delivery fields).
Use the new endpoint to import or refresh all WooCommerce customers:
/api/method/jarz_woocommerce_integration.jarz_woocommerce_integration.api.customers.sync_all?per_page=100
Parameters:
per_page(default 100, Woo max usually 100)max_pages(optional safety cap)
Response sample:
{
"success": true,
"data": {
"processed": 245,
"approx_created_or_updated": 245,
"sample": [ {"customer": "Cust 1", "billing": "ADDR-..." } ]
}
}Behavior:
- Idempotent: existing customers matched by email or display name.
- Adds Billing / Shipping addresses if a matching line1 not already linked.
- Does not delete stale customers.
Run again any time to backfill new Woo signups.
Assumptions:
- You are already inside the Frappe container shell (bash)
- For local development, site name is
development.localhost
Tip: The --kwargs is evaluated as a Python expression by bench; using dict(...) avoids quoting issues.
First, switch to the bench folder:
cd /workspace/development/frappe-benchCustomers (one page example):
bench --site development.localhost execute jarz_woocommerce_integration.api.customers.sync_all --kwargs "dict(per_page=100,max_pages=1)"Territories (full sync):
bench --site development.localhost execute jarz_woocommerce_integration.api.territories.sync_allOrders – recent (Phase 1, 100 orders):
bench --site development.localhost execute jarz_woocommerce_integration.services.order_sync.pull_recent_orders_phase1 --kwargs "dict(limit=100,allow_update=True,force=True)"Single Order (replace 12345):
bench --site development.localhost execute jarz_woocommerce_integration.services.order_sync.pull_single_order_phase1 --kwargs "dict(order_id=12345,allow_update=True)"Endpoint: /api/method/jarz_woocommerce_integration.api.territories.sync_all
Behavior:
- Pulls Woo delivery areas/zones (per your store configuration) into ERPNext
Territoryrecords. - Updates
Territory.pos_profileandcustom_woo_codewhen provided. - Idempotent; safe to re-run.
Troubleshooting:
- Ensure
WooCommerce Settingshas correct Base URL and credentials. - Run
bench restartif you deploy new code and don’t see endpoints.
You can install this app using the bench CLI:
cd $PATH_TO_YOUR_BENCH
bench get-app $URL_OF_THIS_REPO --branch develop
bench install-app jarz_woocommerce_integrationThis app uses pre-commit for code formatting and linting. Please install pre-commit and enable it for this repository:
cd apps/jarz_woocommerce_integration
pre-commit installPre-commit is configured to use the following tools for checking and formatting your code:
- ruff
- eslint
- prettier
- pyupgrade
This app can use GitHub Actions for CI. The following workflows are configured:
- CI: Installs this app and runs unit tests on every push to
developbranch. - Linters: Runs Frappe Semgrep Rules and pip-audit on every pull request.
mit