Skip to content

Add checkout data and user orders REST APIs - #3034

Open
syedgalib wants to merge 2 commits into
sovware:developmentfrom
syedgalib:feature/user-orders-rest-api
Open

syedgalib wants to merge 2 commits into
sovware:developmentfrom
syedgalib:feature/user-orders-rest-api

Conversation

@syedgalib

Copy link
Copy Markdown
Collaborator

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Security fix
  • Improvement
  • New Feature
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Text changes
  • Other... Please describe:

Description

Why this PR is needed

Clients need a provider-aware checkout URL and authenticated order APIs that never accept an arbitrary user ID. Extensions also need a safe way to replace order operations before Directorist writes data.

What is done in this PR

  • Adds GET /directorist/v2/checkout with filterable provider data.
  • Adds authenticated create, single-order, and paginated collection operations under /directorist/v2/orders.
  • Uses the current session user for every user order operation and enforces order and listing ownership.
  • Wraps order results with the Directorist provider type and exposes pagination totals through WordPress REST headers.
  • Adds short-circuit hooks for alternate order providers and fixes one-item pagination in the order repository.

How to test the PR

  1. Activate Directorist, authenticate as a user, and request GET /wp-json/directorist/v2/checkout; verify the response type is directorist and the URL is the configured checkout page.
  2. POST an order to /wp-json/directorist/v2/orders without a user ID; verify the created order belongs to the authenticated user and the response has order_type directorist.
  3. GET /wp-json/directorist/v2/orders/{id}; verify users can read only their own order.
  4. GET /wp-json/directorist/v2/orders?page=1&per_page=1; verify one order is returned and X-WP-Total and X-WP-TotalPages are correct.

Any linked issues

N/A

Checklist

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant