=== Checkout Service Bridge ===
Contributors: checkoutservice
Tags: woocommerce, checkout, cod, razorpay, india
Requires at least: 6.0
Tested up to: 6.7
Requires PHP: 7.4
Stable tag: 1.1.12
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

One-click Indian checkout for WooCommerce — OTP login, address book, COD / prepaid / COD advance, order sync. Buyer prepaid uses merchant Razorpay keys set in ParcelIQ admin (this plugin never stores payment secrets).

== Description ==

Checkout Service Bridge embeds a Shadow DOM checkout widget on product and cart pages and accepts authenticated order + customer pushes from ParcelIQ (Checkout Service).

* HPOS (custom order tables) compatible
* Cart & checkout blocks compatibility declared
* Bridge secret auth for order intake REST routes
* Admin connection test against ParcelIQ API (publishable key + bridge secret)
* Public health endpoint at `/wp-json/csb/v1/health`
* COD advance settings sync to ParcelIQ
* Prefill checkout address from existing Woo customer by phone (optional)
* Theme-adaptive Buy now button (matches store Add to cart styles)
* When enabled, replaces cart / mini-cart / checkout / block checkout buttons
* Options to hide Add to cart and quantity on product pages
* Creates real WooCommerce orders; buyers redirect to Woo thank-you after sync

Buyer **Pay online** / COD advance charge through the merchant’s own Razorpay account configured in **ParcelIQ admin → Merchants → Razorpay**. Do not paste Razorpay Key ID/secret into this plugin.

== Installation ==

1. Upload the `checkout-service-bridge` folder to `/wp-content/plugins/` (or install the zip from ParcelIQ).
2. Activate via the Plugins screen.
3. In ParcelIQ: create merchant + Woo store (`/onboard` or `/admin`), copy publishable key + bridge secret, and (for prepaid) set merchant Razorpay keys in admin.
4. Open **WooCommerce → Checkout Service** and paste publishable key, API/CDN bases, and bridge secret.
   Production (parceliq.in): API `https://parceliq.in/api`, CDN `https://parceliq.in` — not `…/checkout/api`.
5. Click **Test connection** (saves on success), or Save settings.
6. Optionally hide Add to cart / quantity under **Storefront display**, and keep **Prefill address from WooCommerce customer** enabled if you want OTP → address form filled from Woo shipping/billing when the phone matches.
7. Place a test order from a product page or cart.

From the Checkout Service repo you can also run:

`php scripts/sync-woo-plugin.php`
`php scripts/package-woo-plugin.php`

== Frequently Asked Questions ==

= Does this use the WooCommerce Store API? =

Order creation uses `wc_create_order` and is HPOS-compatible. A Store API path may follow later; it is not required for go-live.

= Where do I put Razorpay keys? =

In **ParcelIQ admin → Merchants → Razorpay (buyer checkout)**, not in this plugin. Platform Razorpay env keys are only for ParcelIQ SaaS billing invoices.

= Is OTP always 123456? =

No. A fixed OTP (when configured on the API) applies only to the ParcelIQ **demo** publishable key. Real merchant stores receive normal SMS OTPs.

= Is Shopify supported? =

Not in this plugin. See Checkout Service `integrations/shopify/` and `docs/07-shopify-mode-a.md` for Shopify Mode A (theme embed + draft orders).

= Can I hide the default WooCommerce buttons? =

When the plugin is **enabled**, all WooCommerce checkout buttons (cart, mini-cart, checkout page, blocks) are replaced with one-click automatically. Under **Storefront display** you can also hide Add to cart and quantity on product pages.

== Changelog ==

= 1.1.12 =
* Fix connection test: use /v1/bridge/ping (no longer fails on trial when COD advance is on)
* Fix settings save for Shop Manager (register_setting capability = manage_woocommerce)
* Persist form values after a successful Test connection
* Clearer API errors (HTTP status + body message); reject …/checkout/api base on parceliq.in
* Docs: production API/CDN are https://parceliq.in/api and https://parceliq.in

= 1.1.11 =
* In-checkout abandon nudge settings (synced to ParcelIQ; not a product-page exit-intent popup)
* Checkout Customers admin screen — Woo + ParcelIQ buyers merged by phone
* GET /csb/v1/customers lists Woo customers; cart coupons map into ParcelIQ session
* Apply ParcelIQ discount_paise on Woo order create (fee line)

= 1.1.10 =
* Settings/docs: merchant BYO Razorpay in ParcelIQ admin (plugin never stores payment secrets)
* Clarify connection test checks keys/bridge only; thank-you stays on Woo order-received
* FAQ: fixed OTP is demo publishable key only; Shopify Mode A is a separate integration

= 1.1.9 =
* Send store URL with sessions + bridge settings so orders sync to the correct shop
* Sync site logo/name for dual branding in the checkout header

= 1.1.8 =
* Self-hosted plugin updates from ParcelIQ CDN (WP Admin + Check for updates)
* Update notice when a newer bridge zip is published

= 1.1.7 =
* Test connection now posts the form values (no longer ignores unsaved keys)
* Requires real JSON success from sessions + bridge settings (rejects HTML 200s)

= 1.1.6 =
* Test connection validates publishable key via /v1/sessions (catches 401 invalid_key)
* Blocks local demo publishable key when API base is remote

= 1.1.5 =
* Restore reliable Buy now / one-click handlers (onclick + deferred open)
* Avoid mutation-observer re-entry wiping click handlers

= 1.1.4 =
* Buy now no longer uses Add to cart CSS class hooks that pixels bind to
* Clone/re-wire one-click buttons so third-party click listeners cannot block checkout

= 1.1.3 =
* Isolate Buy now / one-click clicks from store tracking scripts (e.g. snaptr) that throw on local/staging

= 1.1.2 =
* Prefill address from WooCommerce customer by phone (admin toggle)
* `GET /csb/v1/customers/by-phone` for Checkout Service OTP verify

= 1.1.1 =
* Enabled mode replaces all WooCommerce checkout buttons with one-click
* Covers classic cart, mini-cart, checkout Place order, and cart/checkout blocks

= 1.1.0 =
* Buy now inherits theme Add to cart / checkout button styles
* Settings to hide Add to cart, quantity, and Proceed to checkout
* Cleaner card-based admin settings UI
* Customizable Buy now label

= 1.0.0 =
* Phase 4 complete — installable Woo bridge for merchant go-live
* Activation notice + setup checklist
* Uninstall cleanup, LICENSE, package/sync scripts

= 0.4.1 =
* Public `/csb/v1/health` endpoint
* Admin "Test connection"

= 0.4.0 =
* Declare HPOS and cart/checkout blocks compatibility
* Prepare wp.org readme

= 0.3.0 =
* COD advance sync, customer upsert, thank-you redirect
