/b2c:b2c-orderingfrom b2c
Manages B2C Commerce order lifecycle: creation, status transitions, failure handling, and checkout completion. Covers OrderMgr API, synchronous and SCAPI flows, payment authorization, and async processing.
Ships in b2c. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
The OrderMgr API provides order creation, status management, and querying. Understanding the order lifecycle is essential for checkout implementation and order processing.
Orders progress through these statuses:
Basket → CREATED → NEW → (COMPLETED or CANCELLED or FAILED)
| Status | Description | Can Transition To |
|---|---|---|
CREATED | Order created, not yet placed | NEW, FAILED |
NEW | Order placed, awaiting fulfillment | OPEN, COMPLETED, CANCELLED, FAILED |
OPEN | Order in processing | COMPLETED, CANCELLED |
COMPLETED | Order fulfilled | - |
CANCELLED | Order cancelled | NEW (via undoCancel) |
FAILED | Order failed (payment, validation) | - (cannot be reopened) |
Important: Once an order reaches FAILED status, it cannot be reopened or cancelled. Use failOrder(order, true) to reopen the basket for retry instead.
var OrderMgr = require('dw/order/OrderMgr');
var Transaction = require('dw/system/Transaction');
var Status = require('dw/system/Status');
function createOrder(basket) {
var order;
Transaction.wrap(function() {
// Create order from basket (status: CREATED)
order = OrderMgr.createOrder(basket);
});
if (!order) {
return { error: true, message: 'Order creation failed' };
}
// Authorize payment
var paymentResult = authorizePayment(order);
if (!paymentResult.success) {
Transaction.wrap(function() {
OrderMgr.failOrder(order, true); // Reopen basket
});
return { error: true, message: 'Payment failed' };
}
// Place the order (status: CREATED → NEW)
var placeResult;
Transaction.wrap(function() {
placeResult = OrderMgr.placeOrder(order);
});
if (placeResult.error) {
return { error: true, message: 'Order placement failed' };
}
// Set confirmation status
Transaction.wrap(function() {
order.setConfirmationStatus(order.CONFIRMATION_STATUS_CONFIRMED);
});
return { error: false, order: order };
}
Lead with the Shopper Orders state machine instead of manually placing from order.afterPOST:
POST /checkout/shopper-orders/v1/organizations/{orgId}/orders
-> commits order in CREATED
PATCH /checkout/shopper-orders/v1/organizations/{orgId}/orders/{orderNo}/payment-instruments/{piId}
-> invokes dw.order.payment.authorizeCreditCard or dw.order.payment.authorize
-> passes successfullyAuthorized to order.payment_instrument.afterPATCH
-> default afterPATCH places when authorized coverage reaches the order total
NEW -> success
CREATED -> not fully placed; authorize remaining PIs, fail safely, or reconcile
Return undefined from a successful custom order-PI afterPATCH implementation so the platform's
default coverage-based placement behavior runs. A non-null Status ends execution and suppresses
that implementation.
On a deterministic payment failure, use the Shopper Orders fail action with reopenBasket=true.
On an indeterminate gateway result, retain the CREATED order for reconciliation rather than
risking a duplicate authorization.
Use dw.ocapi.shop.order.afterPOST as the alternative when checkout deliberately needs a single
server-side phase that creates, authorizes, and performs the Commerce-side place-or-fail transition,
or when the processor cannot participate in order-PI authorization. That hook runs inside order
creation's transaction: do not add a nested Transaction.wrap, and understand that Status.ERROR
rolls back the Commerce order but not an external gateway side effect. See
"Alternative: Authorize and Place in order.afterPOST" in the b2c-hooks skill.
| Method | Description |
|---|---|
createOrder(basket) | Create order with auto-generated number |
createOrder(basket, orderNo) | Create order with specific number |
createOrderNo() | Generate next order number |
createOrderSequenceNo() | Get next sequence number (for custom formatting) |
| Method | Description |
|---|---|
placeOrder(order) | Place order (CREATED → NEW) |
failOrder(order, reopenBasket) | Fail order (set to FAILED status) |
cancelOrder(order) | Cancel order (set to CANCELLED status) |
undoCancelOrder(order) | Revert cancelled order to NEW |
Note: There is no undoFailOrder() method. Failed orders cannot be reopened. Use failOrder(order, true) to reopen the basket for retry.
| Method | Description |
|---|---|
getOrder(orderNo) | Get order by number |
searchOrder(query, ...args) | Search for single order |
searchOrders(query, sortString, ...args) | Search for multiple orders |
queryOrder(query, ...args) | Query single order |
queryOrders(query, sortString, ...args) | Query multiple orders |
var OrderMgr = require('dw/order/OrderMgr');
var order = OrderMgr.getOrder('00001234');
if (order) {
var status = order.status.value;
var total = order.totalGrossPrice;
}
var OrderMgr = require('dw/order/OrderMgr');
// Search by customer email
var orders = OrderMgr.searchOrders(
'customerEmail = {0} AND status != {1}',
'creationDate desc',
'[email protected]',
dw.order.Order.ORDER_STATUS_FAILED
);
while (orders.hasNext()) {
var order = orders.next();
// Process order
}
orders.close();
var OrderMgr = require('dw/order/OrderMgr');
var Calendar = require('dw/util/Calendar');
var startDate = new Calendar();
startDate.add(Calendar.DAY_OF_YEAR, -7);
var orders = OrderMgr.searchOrders(
'creationDate >= {0} AND status = {1}',
'creationDate desc',
startDate.time,
dw.order.Order.ORDER_STATUS_NEW
);
while (orders.hasNext()) {
var order = orders.next();
// Process order
}
orders.close();
var OrderMgr = require('dw/order/OrderMgr');
var Transaction = require('dw/system/Transaction');
var Order = require('dw/order/Order');
function cancelOrder(orderNo) {
var order = OrderMgr.getOrder(orderNo);
if (!order) {
return { error: true, message: 'Order not found' };
}
// Can only cancel NEW or OPEN orders
if (order.status.value !== Order.ORDER_STATUS_NEW &&
order.status.value !== Order.ORDER_STATUS_OPEN) {
return { error: true, message: 'Order cannot be cancelled' };
}
Transaction.wrap(function() {
OrderMgr.cancelOrder(order);
});
return { error: false };
}
var OrderMgr = require('dw/order/OrderMgr');
var Transaction = require('dw/system/Transaction');
function failOrder(order, reopenBasket) {
// reopenBasket: true = customer can retry checkout
// false = basket is lost
Transaction.wrap(function() {
OrderMgr.failOrder(order, reopenBasket);
});
}
Failed orders cannot be reopened. Instead, use failOrder(order, true) to reopen the basket:
var OrderMgr = require('dw/order/OrderMgr');
var Transaction = require('dw/system/Transaction');
// When payment fails, fail the order and reopen basket
function handlePaymentFailure(order) {
Transaction.wrap(function() {
// reopenBasket=true allows customer to retry checkout
OrderMgr.failOrder(order, true);
});
// Basket is now available again for the customer
return { error: true, message: 'Payment failed. Please try again.' };
}
For SCAPI integrations, use the Shopper Orders fail action after a deterministic payment failure:
POST /checkout/shopper-orders/v1/organizations/{orgId}/orders/{orderNo}/actions/fail?siteId={siteId}&reopenBasket=true
Authorization: Bearer {token}
Content-Type: application/json
{
"reasonCode": "payment_auth_failure"
}
The current payment-oriented reason codes are payment_auth_failure, payment_confirm_failure, and
payment_capture_failure. The endpoint returns 409 when the order is no longer in a state that can
be failed. Confirm the current Shopper Orders schema before generating version-specific code.
Cancelled orders can be reopened using undoCancelOrder():
var OrderMgr = require('dw/order/OrderMgr');
var Transaction = require('dw/system/Transaction');
var Order = require('dw/order/Order');
function reopenCancelledOrder(orderNo) {
var order = OrderMgr.getOrder(orderNo);
if (order.status.value !== Order.ORDER_STATUS_CANCELLED) {
return { error: true, message: 'Order is not cancelled' };
}
Transaction.wrap(function() {
// Revert to NEW status
OrderMgr.undoCancelOrder(order);
});
return { error: false, order: order };
}
| Property | Description |
|---|---|
orderNo | Order number |
status | Current order status |
confirmationStatus | Confirmation status |
exportStatus | Export status for OMS |
paymentStatus | Payment status |
shippingStatus | Shipping status |
customerEmail | Customer email |
customerName | Customer name |
totalGrossPrice | Order total (with tax) |
totalNetPrice | Order total (without tax) |
totalTax | Total tax amount |
creationDate | Order creation date |
productLineItems | Line items in order |
shipments | Order shipments |
paymentInstruments | Payment instruments |
Use the dw.order.createOrderNo hook for custom order number generation:
// hooks.json
{
"hooks": [
{
"name": "dw.order.createOrderNo",
"script": "./hooks/orderNo.js"
}
]
}
// hooks/orderNo.js
var OrderMgr = require('dw/order/OrderMgr');
var Site = require('dw/system/Site');
exports.createOrderNo = function() {
var seqNo = OrderMgr.createOrderSequenceNo();
var prefix = Site.current.ID.toUpperCase();
var year = new Date().getFullYear();
return prefix + '-' + year + '-' + seqNo;
};
failOrder(order, true) to let customers retry| Scenario | Solution |
|---|---|
| Basket is empty | Validate basket before createOrder() |
| Invalid basket | Check for missing shipping/billing addresses |
| Payment failed | Use failOrder(order, true) to reopen basket |
| Order number exists | Use auto-generated numbers or validate uniqueness |
| Status transition invalid | Check current status before calling status methods |
b2c-hooks skill - Order hooks (calculate, payment, createOrderNo)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
20 skills in this plugin
/b2c-business-manager-extensionsBuild Business Manager extension cartridges with custom admin tools, menu items, and dialog actions. Use this skill whenever the user needs to create bm_* cartridges, add menu actions or dialog buttons in BM, configure bm_extensions.xml, or extend admin pages with form overlays. Also use when customizing the BM interface for back-office workflows -- even if they just say 'add a button to BM' or 'custom admin page'./b2c-controllersCreate storefront controllers using SFRA or classic patterns with server.get/post, middleware chains, and res.render/json. Use this skill whenever the user needs to build a page route, handle form submissions, create AJAX endpoints, extend or override existing controllers, or add middleware to a request pipeline. Also use when debugging route registration or response rendering -- even if they just say 'new page endpoint' or 'handle a POST request'./b2c-custom-api-developmentDevelop Custom SCAPI REST endpoints with api.json routes, schema.yaml definitions, and OAuth scope configuration. Use this skill whenever the user needs to create a custom API on the Commerce platform, define OpenAPI 3.0 schemas for request/response, structure the rest-apis cartridge folder, or debug endpoint registration and 404 issues. Also use when building headless commerce integrations, choosing between Shopper (`ShopperToken`) and Admin (`AmOAuth2`) APIs, or troubleshooting why a Custom API endpoint isn't appearing or returning 404 in `b2c scapi custom status` — even if they just say 'custom REST endpoint', 'expose my script as an API', or 'my admin custom API isn't registering'./b2c-custom-cachesImplement custom caching with CacheMgr, caches.json definitions, and cache region configuration. Use this skill whenever the user needs to cache expensive computations or API responses server-side, define cache regions with TTL and size limits, invalidate cache entries, or debug disappearing cache data. Also use when optimizing script performance with application-level caching -- even if they just say 'cache this data' or 'my cached values keep disappearing'./b2c-custom-job-stepsCreate custom job steps for B2C Commerce batch processing. Use this skill whenever the user needs to write a batch job, data export script, scheduled cleanup task, or any server-side processing that runs on a schedule. Also use when they ask about steptypes.json, chunk-oriented vs task-oriented job steps, read/process/write patterns, how to get a custom job to appear in Business Manager, or how to author and import a jobs.xml job definition (job/flow/step structure, step type, the required triggers element) so a step type becomes a runnable, schedulable job — even if they just say "I need a script that runs nightly" or "batch process orders"./b2c-custom-objectsStore and query custom business data using CustomObjectMgr, OCAPI Data API, and Shopper Custom Objects API. Use this skill whenever the user needs to create, read, update, or search custom object instances, build processing queues with status fields, choose between site-scoped and organization-scoped storage, or query custom objects with bool/term filters. Also use when persisting non-standard data -- even if they just say 'store config per site' or 'query my custom data'.npx claudepluginhub salesforcecommercecloud/b2c-developer-tooling --plugin b2cOther plugins' skills for the same job