Quick start

In this tutorial, we'll learn how to create an order in Norce Checkout from a basket in Norce Commerce, using the playground environment.

Prerequisites

Before you begin, make sure you have the following:

  • Access to Norce Commerce Playground : This is where we'll create our basket. Our application needs to be configured to work with Norce Checkout, this configuration is outside the scope of this tutorial.
  • Payment method Norce Checkout (239) set up.
  • Delivery method External Delivery (128) set up.
  • Merchant/Slug : For example, thingsandstuff . The merchant is required for all requests in Norce Checkout and the slug is your path into the load balancer.
  • Bearer Token : We can reach all Norce Checkout services as soon as we have access to Norce Commerce Playground, but a separate token is required to authenticate requests towards all Norce Checkout services. Example: 1AA1Aa1A111aAaAA+1aaaa1aAaaaAaaAaaAaAa1AAaa= .
  • Channel : We can choose our own channel for these requests, if we're sharing the merchant with a collegue its adviced to use something unique!

If you don't have access to these, please contact your Norce representative for help.

Tip

We recommend using Bruno to make these requests. We also provide a Checkout Collection that you can use for easier testing.

Configuring the Norce Adapter

To allow the Norce adapter to fetch basket information from Norce Commerce, it needs to be aware of our client and application IDs, as well as how to obtain a token using the identity client ID and client secret.

Set configuration

Copy
Copied
PUT /api/v1/configuration/merchants/<merchant>/channels/<channel>/configurations/norce_adapter
X-Merchant: <merchant>
X-Channel: <channel>
Authorization: Bearer <token>
Host: <slug>.api-se.playground.norce.tech/checkout/configuration
Content-Type: application/json

{
  "$schema": "https://<slug>.api-se.playground.norce.tech/checkout/norce-adapter/openapi/v1/schemas/norce_adapter.json",
  "id": "norce_adapter",
  "active": true,
  "adapter": {
    "internalUrl": "https://norce-adapter.checkout.playground.internal.norce.tech",
    "publicUrl": "https://<slug>.api-se.playground.norce.tech/checkout/norce-adapter"
  },
  "settings": {
    "clientId": <clientId>,
    "applicationId": <applicationId>
  },
  "api": {
    "identityAddress": "https://identityservice.commerce.test.internal.norce.tech/connect/token",
    "identityClientId": "<identityClientId>",
    "identityClientSecret": "<identityClientSecret>",
    "identityScope": "lab"
  },
  "application": {
    "productUrlPattern": "https://<slug>.admin-se.playground.norce.tech/product/detail/{productId}",
    "imageBaseUrl": "https://<slug>.test.cdn-norce.tech/{{commerceClientId}}"
  },
  "country": {
    "defaultCountry": "SE"
  },
  "features": {
    "shippingChangedHookEnabled": true
  }
}

Preparing a Basket in Norce Commerce

  1. Create a basket
  2. Insert a basket item
  3. Set payment method to 239
  4. Set delivery method to 128

Creating an Order in Norce Checkout

We provide the basket ID, culture, and currency and post it to our Norce adapter.

Create order

Create order requestCreate order response
Copy
Copied
POST /api/v1/orders
X-Merchant: <merchant>
X-Channel: <channel>
Authorization: Bearer <token>
Host: <slug>.api-se.playground.norce.tech/checkout/norce-adapter
Content-Type: application/json

{
  "cartReference": <basketId>,
  "culture": "sv-SE",
  "currency": "SEK"
}
Copy
Copied
201 Created
Content-Type: application/json

{
  "id": "<orderId>"
}

Note, cart references must be unique for each order. If we attempt to create the order again using the same basket id as cart reference we'll get a conflict.

Read the order

We can now fetch the order to see it mapped to a Norce Checkout order.

Get order

RequestResponse
Copy
Copied
GET /api/v0/checkout/orders/<order-id>
X-Merchant: <merchant>
X-Channel: <channel>
Authorization: Bearer <token>
Host: <slug>.api-se.playground.norce.tech/checkout/order
Copy
Copied
200 OK
Content-Type: application/json

{
  "id": "<order-id>",
  "merchant": "<merchant>",
  "channel": "<channel>",
  "created": "2024-01-01T01:01:01.0000001Z",
  "lastModified": "2024-01-01T01:01:01.0000001Z",
  "state": {
    "currentStatus": "checkout",
    "transitions": [
      {
        "status": "checkout",
        "timeStamp": "2024-01-01T01:01:01.0000001Z",
      }
    ]
  },
  "cart": {
    "reference": "unique-basket-reference-1",
    "items": [
      {
        "reference": "item-reference-1",
        "sku": "I0001",
        "name": "Item name",
        "quantity": 1,
        "total": {
          "includingVat": 12.5,
          "excludingVat": 10
        },
        "vatRate": 0.25
      }
    ],
    "total": {
      "includingVat": 12.5,
      "excludingVat": 10
    }
  },
  "total": {
    "includingVat": 12.5,
    "excludingVat": 10
  }
}

Next steps

So far, we've created and read an order in Norce Checkout. However, we can't complete the order without adding some payment information.

Check out our START BUILDING section to learn more about core concepts and try out completing your order! Or read more about the Norce adapter.

Copyright © Norce 2024. All right reserved.