AddOns for Partners - Creating an Order
Creating an Order
INSTEAD
-
WHEN TO USE
You need to use this add-on when you need to create an order in a Partner System. -
ADDING TO MY COMMERCE (TECH)
mutation CreateAddOn($data: AddOnInput!, $storefrontName: String!) { createAddOn(data: $data, storefrontName: $storefrontName) { id type config status callback } }
We will are have { "data": { "type": "CREATE_ORDER" || "CREATE_ORDERS", "flavor": "REST", "config": { "method": "POST", "url": "https://www....", "authMethod": "BASIC", "token": "string", "headers": {}, "updateCart": false, "updatePrice": false }, "executionTime": "INSTEAD" }, "storefrontName": "STOREFRONTNAME" }
-
DATA SENT TO THE ADD-ON (TECH)
This would be the payload sent to the endpoint at the time an order confirmation is made from the commerce ecosystem:
{ "args":{ "sessionUId": string, "storefrontName": string }, "artifacts": { "session":{ "id": string, "customerUid": string, "customerAlias": string, // this is the value used to validate session on session create "cartUid": string, "configuration": { // configuration give by storefront object in commerce } "startedAt": string, "finishedAt": string, "status": string, "customFields": object, "createdAt": date, "updatedAt": date }, "orders": [] } ]
Description of the data sent in the payload:
Name Type Description args.sessionUId string The ID of the customer session args.storefrontName string The name configured for the storefront artifacts.session.id string The ID of the session artifacts.session.customerUid string The customer ID in the headless system artifacts.session.cartUid string The cart ID generated in the headless system artifacts.session.status string The status of the session can be
ACTIVE
FINISHED
EXPIREDartifacts.order.id string The identifier for the order generated in the headless system artifacts.order.customerCode string The identifier for the customer artifacts.order.sessionUid string The identifier for the session artifacts.order.items Array An array of items that the order contains artifacts.order.status string The status of the order can be:
CREATED
PROCESSED
CANCELLED
CONFIRMEDartifacts.order.total float The total amount of the order Depending on the configuration saved in the splitter of orders (StoreFront splitter order configuration) there are the types of add-ons that are used:
- CREATE_ORDER
In the scenario that the store has turned OFF or does not have the order separation options configured: you must implement the addOn typeCREATE_ORDER
which theorder
field will return a single order object.{ ... "artifacts": { ... "order": { "id": string, "customerCode": string, "storeCode": string, "sessionUid": string, "items": [ ... { "sku": string, "quantity": integer, "price": float, "name": string, "brand": string, "imageURL": Array<string>, "description": string, "packageType": string, "unitDivision": string, "unitsPerPackage": integer, "divisionsByUnit": string, "attributes": Array<string> } ... ] "status": string, "processedAt": date, "notes": string, "total": float, "createdAt": date, "updatedAt": date } } }
- CREATE_ORDERS
In the scenario that the store has turned ON or does have the order separation options configured: you must implement the addOn typeCREATE_ORDERS
which theorder
field will return a single order object.{ ... "artifacts": { ... "order": [ { "id": string, "customerCode": string, "storeCode": string, "sessionUid": string, "items": [ ... { "sku": string, "quantity": integer, "price": float, "name": string, "brand": string, "imageURL": Array<string>, "description": string, "packageType": string, "unitDivision": string, "unitsPerPackage": integer, "divisionsByUnit": string, "attributes": Array<string> } ... ] "status": string, "processedAt": date, "notes": string, "total": float, "createdAt": date, "updatedAt": date }, { "id": string, "customerCode": string, "storeCode": string, "sessionUid": string, "items": [ ... { "sku": string, "quantity": integer, "price": float, "name": string, "brand": string, "imageURL": Array<string>, "description": string, "packageType": string, "unitDivision": string, "unitsPerPackage": integer, "divisionsByUnit": string, "attributes": Array<string> } ... ] "status": string, "processedAt": date, "notes": string, "total": float, "createdAt": date, "updatedAt": date } ... ] } }
- CREATE_ORDER
-
RESPONSE STRUCT NEEDED FROM ADD-ON (TECH)
After processing the information of the order collected from Commerce with the Partner System, itâs mandatory to update the same data of the order/orders sent in theorder
field, remember that there were two options to receive the data (StoreFront splitter order configuration), one is a simple order (unique object) or with a collection of orders (array).
After doing an external information manipulation process, it is necessary to return the following payload:
ForCREATE_ORDER
:{ "id": string, "items": [ ... { "id": string, "sku": string, // required "quantity": integer, // required "price": float, // required } ... ], "total": float, // required "externalOrderUid": string // required }
For
CREATE_ORDERS
:đĄ For the definition of the properties of an item, you can see the table [here](https://www.notion.so/e0dd669687a64223a8190caeef4f9fbf?pvs=21). This response is an array of products `externalOrderUid` It can be any unique value of type string that allows having a hard relationship (ID) that allows making a relationship between the data of the order and the data that will be processed by the Partner System[ { "id": string, "items": [ ... { "id": string, "sku": string, // required "quantity": integer, // required "price": float, // required } ... ], "total": float, // required "externalOrderUid": string // required }, .... ]
-
EXTRA PROCESSING
- An order is created on headless system prior to sending it to add on
- After the answer to the add will check total, prices and quantity are ok and update the order in headless
- If the order is different than the one stored in the database, the order gets canceled, except if update flags (
updateCart
orupdatePrice
) are enabled in add on config - In case the callBack option is turned on, the
externalRefStatus
field is updated with thePROCESSING
value ofstatus
still withCREATED
AFTER-
WHEN TO USE
You need to use this add-on when you perform an action with the other created
In the event that the AddOn has thecallback
option turned ON, it will be possible to access the mutation with the same name that will proceed to receive the data that is received as a response from the Partner System -
ADDING TO MY COMMERCE (TECH)
mutation OrderCallback($data: OrderData!, storefrontName: $storefrontName, externalOrderUid: $externalOrderUid) { orderCallback(data: $data, storefrontName: $storefrontName, externalOrderUid: $externalOrderUid) { externalOrderUid externalRefNumber externalMessage externalErrorMessage externalRefStatus items total } }
-
RESPONSE STRUCT NEEDED FROM ADD-ON (TECH)
The data sent to process the response from the partner system is as follows:
{ "externalOrderUid": string, "externalRefNumber": string, "externalMessage": string, "externalErrorMessage": string, "externalRefStatus": string, "items": { "id": string, "sku": string, // required "quantity": integer, // required "price": float, // required }, "total": float }
Name Type Description externalOrderUid String Reference number with which the relationship is made between the data that is stored in the Commerce environment and with the partner system externalRefNumber String After the processing of the client's system, a reference or confirmation ID can be stored after the process carried out by the system externalMessage String In the event that the information has been processed correctly with the partner system, it is required to save a message if the client's system so wishes. externalErrorMessage String In case of an error message, this field is required in order to identify the reason why an error was generated in the partner system. externalRefStatus String The status of the order can be:
CONFIRMED
REJECTED
ERROR
TIMEOUTitems Object The list of items, in case the system makes any changes total number If the total has been modified by the system -
EXTRA PROCESSING
- Update the information in the external fields with the information
- If the
externalRefStatus
field is CONFIRMED the status of the order will remain as CONFIRMED - If the
externalRefStatus
field is not equal to CONFIRMED, thestatus
will be anERROR
Updated over 1 year ago