PHP Models = API Interface — The PHP models provide a fluent, Laravel-like interface to the SureCart REST API. Each model corresponds directly to an API resource.For complete details on available properties, query parameters, and expandable relations, refer to the API Reference.
Blocking HTTP requests — Each model query makes a synchronous HTTP request to the SureCart API. This means PHP execution will wait for the response before continuing.Use these methods in contexts where blocking is acceptable:
- AJAX/REST handlers.
- Admin dashboard pages and requests.
- WP-CLI commands.
- Cron jobs and background tasks.
Retrieving
SureCart’s PHP models allow you to fetch data from the SureCart API using a familiar, Laravel-like syntax. You can retrieve single records by ID, query collections with filters, paginate results, and refresh stale data — all with clean, expressive methods.Retrieving a model by id
The model’sall method will retrieve a record with a specific ID.
Retrieving several models.
The model’sall method will retrieve the first 10 records from the model’s associated database table:
Building queries
To query by specific parameters, you can use thewhere method. This method sends query parameters over the API and returns the matching records.
Pagination
You can paginate and get subsquent pages of results by using thepaginate method. This method takes 2 parameters, page and per_page. The default pagination per_page limit is 100.
Refreshing Models
If you already have an instance of a model that was retrieved, you can “refresh” the model using thefresh method. The fresh method will re-retrieve the model from the database. The existing model instance will not be affected:
refresh method will re-hydrate the existing model using fresh data from the database:
Expanding Relations
Many models allow you to request additional information from relational models by using thewith method. This parameter is available on all models and applies to the response of that model only. Model relations can be expanded in two ways.
Expanding a single relation
In many cases, an object contains the ID of a related object in its response properties. For example, a price has an associated product ID. Those models can be queried together in one call. ID fields that can be expanded into models are noted in this documentation with the “expandable” label. Here’s an example:Expanding list relations
In some cases, such as a list of all prices for a product, there are available fields that are not included in responses by default. You can request these fields as an expanded response by using thewith method. Fields that can be included in an expanded response are noted in this documentation with the “expandable” label.
Recursively expanding relations
You can expand recursively by specifying nested fields after a dot (.). For example, requestingcustomer and customer.billing_address on an order will expand the customer and the customer’s billing address.
with method on any endpoint that returns expandable fields, including list, create, and update endpoints.
Expanding list requests are plural, but expanding objects within a list is singular. For example, if you wanted to retrieve an order’s line items and each line item’s price, you would pass checkout, checkout.line_items and line_item.price as expand parameters.
Example:
with array. Expansions have a maximum depth of two levels, and you can expand up to 10 objects.
This is not only limited to get or paginate. You can use this on create or update requests as well. This will allow you to create or update a model and fetch its relations all in one request.
Inserting, Updating, and Deleting
Creating a Model
To create a new model, instantiate it with attributes and call thesave method:
save:
Updating a Model
Use the staticupdate method directly by passing an id in the attributes:
update with the new attributes:
save:
Deleting a Model
Use thedelete method to remove a model:
Error Handling
All model methods can return a\WP_Error object if the API request fails. Always check for errors when working with models:
find, get, save, and delete:
Utility Methods
Getting the First Result
Use thefirst method to retrieve a single record from a query:
Converting to Array or Object
Models can be converted to arrays or standard objects:Array Access
Models implementArrayAccess, so you can access attributes using array syntax:
Dirty Checking
You can check if a model’s attributes have been modified since it was retrieved:Available Models
SureCart provides PHP models for interacting with the following resources. Each model maps directly to an API resource — see the API Reference for full property details, query parameters, and expandable fields.Products
| Model | API Reference | Description |
|---|---|---|
Product | Products | Physical or digital products |
Price | Prices | Pricing options for products |
ProductCollection | Product Collections | Product collections/categories |
ProductGroup | Product Groups | Product groupings |
ProductMedia | Product Medias | Media attached to products |
Variant | Variants | Product variants |
VariantOption | Variant Options | Variant option definitions |
Bump | Bumps | Order bumps |
Upsell | Upsells | Upsell offers |
UpsellFunnel | Upsell Funnels | Upsell funnel configurations |
Swap | Swaps | Product swap configurations |
Download | Downloads | Downloadable files |
Coupon | Coupons | Discount coupons |
Promotion | Promotions | Applied promotions |
Customers
| Model | API Reference | Description |
|---|---|---|
Customer | Customers | Customer records |
BalanceTransaction | Balance Transactions | Balance transaction records |
Orders & Payments
| Model | API Reference | Description |
|---|---|---|
Order | Orders | Completed orders |
Checkout | Checkouts | Checkout sessions |
AbandonedCheckout | Abandoned Checkouts | Abandoned checkout recovery |
LineItem | Line Items | Order line items |
Purchase | Purchases | Individual purchase records |
Charge | Charges | Payment charges |
Invoice | Invoices | Invoices for orders |
Refund | Refunds | Refund records |
PaymentIntent | Payment Intents | Payment intent records |
PaymentMethod | Payment Methods | Stored payment methods |
ManualPaymentMethod | Manual Payment Methods | Manual payment method configs |
Processor | Processors | Payment processors |
Fee | Fees | Order fees |
Dispute | Disputes | Payment disputes |
Subscriptions
| Model | API Reference | Description |
|---|---|---|
Subscription | Subscriptions | Recurring subscriptions |
Period | Periods | Subscription billing periods |
CancellationAct | Cancellation Acts | Subscription cancellations |
CancellationReason | Cancellation Reasons | Cancellation reason options |
Shipping & Fulfillment
| Model | API Reference | Description |
|---|---|---|
Fulfillment | Fulfillments | Order fulfillments |
FulfillmentItem | Fulfillment Items | Fulfillment line items |
ShippingMethod | Shipping Methods | Shipping method configurations |
ShippingProfile | Shipping Profiles | Shipping profile settings |
ShippingRate | Shipping Rates | Shipping rate definitions |
ShippingZone | Shipping Zones | Shipping zone configurations |
ReturnRequest | Return Requests | Return request records |
ReturnItem | Return Items | Return request items |
Tax
| Model | API Reference | Description |
|---|---|---|
TaxRegistration | Tax Registrations | Tax registration records |
TaxZone | Tax Zones | Tax zone configurations |
Licensing
| Model | API Reference | Description |
|---|---|---|
License | Licenses | Software licenses |
Activation | Activations | License activations |
Affiliates
| Model | API Reference | Description |
|---|---|---|
Affiliation | Affiliations | Affiliate accounts |
AffiliationRequest | Affiliation Requests | Affiliate application requests |
AffiliationProduct | Affiliation Products | Affiliate product associations |
Referral | Referrals | Affiliate referral records |
ReferralItem | Referral Items | Referral line items |
Payout | Payouts | Affiliate payouts |
PayoutGroup | Payout Groups | Grouped payout batches |
Click | Clicks | Affiliate click tracking |
Media
| Model | API Reference | Description |
|---|---|---|
Media | Medias | Media files |
Account & Settings
| Model | API Reference | Description |
|---|---|---|
Account | Account | Store account settings |
Brand | Brand | Branding configurations |
Webhook | Webhook Endpoints | Webhook endpoint configurations |
Reviews
| Model | API Reference | Description |
|---|---|---|
Review | Reviews | Product reviews |
Other
All models are located in theSureCart\Models namespace: