@eventcatalog/create-eventcatalog 4.3.12 → 4.3.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/templates/default/domains/Catalog/systems/product-catalog-system/services/ProductAPI/commands/CreateProduct/examples/index.mdx +194 -0
- package/templates/default/domains/Catalog/systems/product-catalog-system/services/ProductAPI/commands/DeleteProduct/examples/index.mdx +161 -0
- package/templates/default/domains/Catalog/systems/product-catalog-system/services/ProductAPI/commands/UpdateProduct/examples/index.mdx +182 -0
- package/templates/default/domains/Catalog/systems/product-catalog-system/services/ProductAPI/events/ProductCreated/examples/index.mdx +227 -0
- package/templates/default/domains/Catalog/systems/product-catalog-system/services/ProductAPI/events/ProductDeleted/examples/index.mdx +175 -0
- package/templates/default/domains/Catalog/systems/product-catalog-system/services/ProductAPI/events/ProductUpdated/examples/index.mdx +205 -0
- package/templates/default/domains/Catalog/systems/product-catalog-system/services/ProductAPI/queries/GetProduct/examples/index.mdx +205 -0
- package/templates/default/domains/Catalog/systems/search-system/services/SearchAPI/queries/SearchProducts/examples/index.mdx +369 -0
- package/templates/default/domains/Customer/systems/customer-management-system/services/CustomerAPI/commands/RegisterCustomer/examples/index.mdx +168 -0
- package/templates/default/domains/Customer/systems/customer-management-system/services/CustomerAPI/commands/UpdateCustomer/examples/index.mdx +168 -0
- package/templates/default/domains/Customer/systems/customer-management-system/services/CustomerAPI/events/CustomerRegistered/examples/index.mdx +201 -0
- package/templates/default/domains/Customer/systems/customer-management-system/services/CustomerAPI/events/CustomerUpdated/examples/index.mdx +194 -0
- package/templates/default/domains/Customer/systems/customer-management-system/services/CustomerAPI/queries/GetCustomer/examples/index.mdx +194 -0
- package/templates/default/domains/Customer/systems/identity-provider/services/OAuthAPI/commands/AuthenticateCustomer/examples/index.mdx +198 -0
- package/templates/default/domains/Customer/systems/identity-provider/services/OAuthAPI/events/CustomerAuthenticated/examples/index.mdx +276 -0
- package/templates/default/domains/Fulfilment/systems/carrier/services/CarrierTrackingAPI/events/ShipmentCreated/examples/index.mdx +184 -0
- package/templates/default/domains/Fulfilment/systems/carrier/services/CarrierTrackingAPI/events/ShipmentDelivered/examples/index.mdx +173 -0
- package/templates/default/domains/Fulfilment/systems/carrier/services/CarrierTrackingAPI/events/ShipmentFailed/examples/index.mdx +265 -0
- package/templates/default/domains/Fulfilment/systems/inventory-system/services/InventoryService/commands/ReleaseInventory/examples/index.mdx +246 -0
- package/templates/default/domains/Fulfilment/systems/inventory-system/services/InventoryService/events/InventoryReserved/examples/index.mdx +227 -0
- package/templates/default/domains/Fulfilment/systems/inventory-system/services/InventoryService/events/InventoryUnavailable/examples/index.mdx +229 -0
- package/templates/default/domains/Fulfilment/systems/inventory-system/services/InventoryService/queries/GetStockLevel/examples/index.mdx +186 -0
- package/templates/default/domains/Fulfilment/systems/shipping-system/services/CarrierAdapter/commands/CreateShipment/examples/index.mdx +206 -0
- package/templates/default/domains/Fulfilment/systems/warehouse-system/services/PickingWorker/events/OrderPacked/examples/index.mdx +172 -0
- package/templates/default/domains/Fulfilment/systems/warehouse-system/services/WarehouseService/events/OrderReadyForShipping/examples/index.mdx +208 -0
- package/templates/default/domains/Ordering/systems/checkout-system/services/CheckoutOrchestrator/commands/AuthorizePayment/examples/index.mdx +179 -0
- package/templates/default/domains/Ordering/systems/checkout-system/services/CheckoutOrchestrator/commands/ReserveInventory/examples/index.mdx +215 -0
- package/templates/default/domains/Ordering/systems/order-management-system/services/OrderService/commands/CancelOrder/examples/index.mdx +163 -0
- package/templates/default/domains/Ordering/systems/order-management-system/services/OrderService/commands/CreateOrder/examples/index.mdx +246 -0
- package/templates/default/domains/Ordering/systems/order-management-system/services/OrderService/events/OrderCancelled/examples/index.mdx +267 -0
- package/templates/default/domains/Ordering/systems/order-management-system/services/OrderService/events/OrderCompleted/examples/index.mdx +171 -0
- package/templates/default/domains/Ordering/systems/order-management-system/services/OrderService/events/OrderCreated/examples/index.mdx +190 -0
- package/templates/default/domains/Ordering/systems/order-management-system/services/OrderService/queries/GetOrder/examples/index.mdx +343 -0
- package/templates/default/domains/Payments/systems/fraud-detection/services/FraudAPI/events/FraudCheckFailed/examples/index.mdx +271 -0
- package/templates/default/domains/Payments/systems/fraud-detection/services/FraudAPI/events/FraudCheckPassed/examples/index.mdx +173 -0
- package/templates/default/domains/Payments/systems/payment-processing-system/services/PaymentWorker/events/PaymentRequested/examples/index.mdx +191 -0
- package/templates/default/domains/Payments/systems/payment-processing-system/services/PaymentWorker/events/RefundRequested/examples/index.mdx +194 -0
- package/templates/default/domains/Payments/systems/stripe/services/StripeWebhookEndpoint/events/PaymentFailed/examples/index.mdx +265 -0
- package/templates/default/domains/Payments/systems/stripe/services/StripeWebhookEndpoint/events/PaymentSucceeded/examples/index.mdx +190 -0
- package/templates/default/domains/Payments/systems/stripe/services/StripeWebhookEndpoint/events/RefundProcessed/examples/index.mdx +186 -0
- package/templates/default/domains/Reviews/services/RatingAggregator/events/rating-updated/examples/index.mdx +183 -0
- package/templates/default/domains/Reviews/services/ReviewAPI/commands/flag-review/examples/index.mdx +183 -0
- package/templates/default/domains/Reviews/services/ReviewAPI/commands/submit-review/examples/index.mdx +195 -0
- package/templates/default/domains/Reviews/services/ReviewAPI/commands/vote-review-helpful/examples/index.mdx +178 -0
- package/templates/default/domains/Reviews/services/ReviewAPI/events/review-flagged/examples/index.mdx +186 -0
- package/templates/default/domains/Reviews/services/ReviewAPI/events/review-helpful-voted/examples/index.mdx +177 -0
- package/templates/default/domains/Reviews/services/ReviewAPI/events/review-submitted/examples/index.mdx +194 -0
- package/templates/default/domains/Reviews/services/ReviewAPI/queries/get-product-reviews/examples/index.mdx +259 -0
- package/templates/default/domains/Reviews/services/ReviewModerationWorker/events/review-published/examples/index.mdx +183 -0
- package/templates/default/domains/Reviews/services/ReviewModerationWorker/events/review-rejected/examples/index.mdx +178 -0
- package/templates/default/domains/Shopping/systems/cart-system/services/CartAPI/commands/AddItemToCart/examples/index.mdx +171 -0
- package/templates/default/domains/Shopping/systems/cart-system/services/CartAPI/commands/CheckoutCart/examples/index.mdx +168 -0
- package/templates/default/domains/Shopping/systems/cart-system/services/CartAPI/commands/RemoveItemFromCart/examples/index.mdx +170 -0
- package/templates/default/domains/Shopping/systems/cart-system/services/CartAPI/events/CartCheckedOut/examples/index.mdx +275 -0
- package/templates/default/domains/Shopping/systems/promotion-system/services/PromotionService/commands/CalculateDiscount/examples/index.mdx +207 -0
- package/templates/default/domains/Shopping/systems/promotion-system/services/PromotionService/events/DiscountCalculated/examples/index.mdx +190 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
<Columns cols={2}>
|
|
2
|
+
|
|
3
|
+
<Column>
|
|
4
|
+
|
|
5
|
+
## 1. Remove a T-shirt line completely
|
|
6
|
+
|
|
7
|
+
A shopper clicks **Remove** next to the T-shirt in their basket. The storefront sends `RemoveItemFromCart` without a quantity, so the Cart API deletes the whole line.
|
|
8
|
+
|
|
9
|
+
### Payload details
|
|
10
|
+
|
|
11
|
+
- `cartId` identifies the shopper's cart.
|
|
12
|
+
- `productId` is the T-shirt to remove.
|
|
13
|
+
- `quantity` is omitted, which means "remove the item entirely".
|
|
14
|
+
|
|
15
|
+
### Using this example
|
|
16
|
+
|
|
17
|
+
Check that the T-shirt line no longer exists in the cart, whatever quantity it had before.
|
|
18
|
+
|
|
19
|
+
The examples use a **fictional Acme Events SDK** to send a payload matching the RemoveItemFromCart schema. The package names and send methods are illustrative.
|
|
20
|
+
|
|
21
|
+
</Column>
|
|
22
|
+
|
|
23
|
+
<Column>
|
|
24
|
+
|
|
25
|
+
<CodeGroup dropdown>
|
|
26
|
+
|
|
27
|
+
```typescript send-remove-item-from-cart.ts
|
|
28
|
+
import { EventsClient } from '@acme/events';
|
|
29
|
+
import type { RemoveItemFromCart } from './schemas/remove-item-from-cart';
|
|
30
|
+
|
|
31
|
+
const client = new EventsClient({
|
|
32
|
+
apiKey: process.env.ACME_API_KEY!,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const command: RemoveItemFromCart = {
|
|
36
|
+
cartId: 'a7c3e9f1-2b4d-4e6a-8f1c-3d5b7e9a1c24',
|
|
37
|
+
productId: '0e8f4b2a-7c1d-4f3e-9a5b-6d2c8e1f7a93',
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
await client.send('RemoveItemFromCart', command);
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
```python send_remove_item_from_cart.py
|
|
44
|
+
import os
|
|
45
|
+
from acme_events import EventsClient
|
|
46
|
+
|
|
47
|
+
client = EventsClient(api_key=os.environ["ACME_API_KEY"])
|
|
48
|
+
|
|
49
|
+
command = {
|
|
50
|
+
"cartId": "a7c3e9f1-2b4d-4e6a-8f1c-3d5b7e9a1c24",
|
|
51
|
+
"productId": "0e8f4b2a-7c1d-4f3e-9a5b-6d2c8e1f7a93",
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
client.send("RemoveItemFromCart", command)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
```java SendRemoveItemFromCart.java
|
|
58
|
+
import com.acme.events.EventsClient;
|
|
59
|
+
import java.util.Map;
|
|
60
|
+
|
|
61
|
+
public class SendRemoveItemFromCart {
|
|
62
|
+
public static void main(String[] args) {
|
|
63
|
+
var client = new EventsClient(
|
|
64
|
+
System.getenv("ACME_API_KEY")
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
var command = Map.of(
|
|
68
|
+
"cartId", "a7c3e9f1-2b4d-4e6a-8f1c-3d5b7e9a1c24",
|
|
69
|
+
"productId", "0e8f4b2a-7c1d-4f3e-9a5b-6d2c8e1f7a93"
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
client.send("RemoveItemFromCart", command);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
</CodeGroup>
|
|
78
|
+
|
|
79
|
+
</Column>
|
|
80
|
+
|
|
81
|
+
</Columns>
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
<Columns cols={2}>
|
|
86
|
+
|
|
87
|
+
<Column>
|
|
88
|
+
|
|
89
|
+
## 2. Reduce the number of caps
|
|
90
|
+
|
|
91
|
+
The shopper has three caps in the cart and lowers the quantity to one. The storefront sends `RemoveItemFromCart` with a quantity of 2, and the Cart API decreases the line.
|
|
92
|
+
|
|
93
|
+
### Payload details
|
|
94
|
+
|
|
95
|
+
- `cartId` is the same cart as in the first example.
|
|
96
|
+
- `productId` is the cap.
|
|
97
|
+
- `quantity` is `2`, the number of units to take away (minimum 1).
|
|
98
|
+
|
|
99
|
+
The cap line goes from **3 units to 1 unit**.
|
|
100
|
+
|
|
101
|
+
### Using this example
|
|
102
|
+
|
|
103
|
+
Check that the cap line keeps 1 unit, and that removing a product that is not in the cart returns a `404` response.
|
|
104
|
+
|
|
105
|
+
The examples use a **fictional Acme Events SDK** to send a payload matching the RemoveItemFromCart schema. The package names and send methods are illustrative.
|
|
106
|
+
|
|
107
|
+
</Column>
|
|
108
|
+
|
|
109
|
+
<Column>
|
|
110
|
+
|
|
111
|
+
<CodeGroup dropdown>
|
|
112
|
+
|
|
113
|
+
```typescript send-remove-item-from-cart.ts
|
|
114
|
+
import { EventsClient } from '@acme/events';
|
|
115
|
+
import type { RemoveItemFromCart } from './schemas/remove-item-from-cart';
|
|
116
|
+
|
|
117
|
+
const client = new EventsClient({
|
|
118
|
+
apiKey: process.env.ACME_API_KEY!,
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const command: RemoveItemFromCart = {
|
|
122
|
+
cartId: 'a7c3e9f1-2b4d-4e6a-8f1c-3d5b7e9a1c24',
|
|
123
|
+
productId: '8d4f6a2c-3e5b-4c7d-9f1a-5b7d9e3c1a46',
|
|
124
|
+
quantity: 2,
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
await client.send('RemoveItemFromCart', command);
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
```python send_remove_item_from_cart.py
|
|
131
|
+
import os
|
|
132
|
+
from acme_events import EventsClient
|
|
133
|
+
|
|
134
|
+
client = EventsClient(api_key=os.environ["ACME_API_KEY"])
|
|
135
|
+
|
|
136
|
+
command = {
|
|
137
|
+
"cartId": "a7c3e9f1-2b4d-4e6a-8f1c-3d5b7e9a1c24",
|
|
138
|
+
"productId": "8d4f6a2c-3e5b-4c7d-9f1a-5b7d9e3c1a46",
|
|
139
|
+
"quantity": 2,
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
client.send("RemoveItemFromCart", command)
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
```java SendRemoveItemFromCart.java
|
|
146
|
+
import com.acme.events.EventsClient;
|
|
147
|
+
import java.util.Map;
|
|
148
|
+
|
|
149
|
+
public class SendRemoveItemFromCart {
|
|
150
|
+
public static void main(String[] args) {
|
|
151
|
+
var client = new EventsClient(
|
|
152
|
+
System.getenv("ACME_API_KEY")
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
var command = Map.of(
|
|
156
|
+
"cartId", "a7c3e9f1-2b4d-4e6a-8f1c-3d5b7e9a1c24",
|
|
157
|
+
"productId", "8d4f6a2c-3e5b-4c7d-9f1a-5b7d9e3c1a46",
|
|
158
|
+
"quantity", 2
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
client.send("RemoveItemFromCart", command);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
</CodeGroup>
|
|
167
|
+
|
|
168
|
+
</Column>
|
|
169
|
+
|
|
170
|
+
</Columns>
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
<Columns cols={2}>
|
|
2
|
+
|
|
3
|
+
<Column>
|
|
4
|
+
|
|
5
|
+
## 1. Publish a single-item checkout
|
|
6
|
+
|
|
7
|
+
A customer checks out a cart with two T-shirts and no voucher. The Cart API publishes `CartCheckedOut`, and downstream systems use it to create the order and take payment.
|
|
8
|
+
|
|
9
|
+
### Payload details
|
|
10
|
+
|
|
11
|
+
- `eventId` and `occurredAt` identify this event and when the checkout happened (UTC).
|
|
12
|
+
- `items` holds one line: 2 T-shirts at a `unitPrice` of 2,000 pence each.
|
|
13
|
+
- `subtotal` and `discount` are omitted because no discount applied.
|
|
14
|
+
- `currency` is `GBP`, so all amounts are in pence.
|
|
15
|
+
|
|
16
|
+
The total is **2 × 2,000 = 4,000 pence (£40.00)**.
|
|
17
|
+
|
|
18
|
+
### Using this example
|
|
19
|
+
|
|
20
|
+
Check that the order created from this event has one line and a total of 4,000 pence, and that a missing `discount` is treated as zero.
|
|
21
|
+
|
|
22
|
+
The examples use a **fictional Acme Events SDK** to publish a payload matching the CartCheckedOut schema. The package names and publish methods are illustrative.
|
|
23
|
+
|
|
24
|
+
</Column>
|
|
25
|
+
|
|
26
|
+
<Column>
|
|
27
|
+
|
|
28
|
+
<CodeGroup dropdown>
|
|
29
|
+
|
|
30
|
+
```typescript publish-cart-checked-out.ts
|
|
31
|
+
import { EventsClient } from '@acme/events';
|
|
32
|
+
import type { CartCheckedOut } from './schemas/cart-checked-out';
|
|
33
|
+
|
|
34
|
+
const client = new EventsClient({
|
|
35
|
+
apiKey: process.env.ACME_API_KEY!,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const event: CartCheckedOut = {
|
|
39
|
+
eventId: 'e4b7c1d9-2f6a-4e8b-a3c5-7d9f1b3e5a02',
|
|
40
|
+
occurredAt: '2026-09-11T08:12:45Z',
|
|
41
|
+
cartId: 'c1d2e3f4-5a6b-4c7d-8e9f-0a1b2c3d4e5f',
|
|
42
|
+
customerId: '7a1e5c9d-8b3f-4f2a-a6d4-2e9c0b7f3d51',
|
|
43
|
+
items: [
|
|
44
|
+
{
|
|
45
|
+
productId: '0e8f4b2a-7c1d-4f3e-9a5b-6d2c8e1f7a93',
|
|
46
|
+
quantity: 2,
|
|
47
|
+
unitPrice: 2000,
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
total: 4000,
|
|
51
|
+
currency: 'GBP',
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
await client.publish('CartCheckedOut', event);
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
```python publish_cart_checked_out.py
|
|
58
|
+
import os
|
|
59
|
+
from acme_events import EventsClient
|
|
60
|
+
|
|
61
|
+
client = EventsClient(api_key=os.environ["ACME_API_KEY"])
|
|
62
|
+
|
|
63
|
+
event = {
|
|
64
|
+
"eventId": "e4b7c1d9-2f6a-4e8b-a3c5-7d9f1b3e5a02",
|
|
65
|
+
"occurredAt": "2026-09-11T08:12:45Z",
|
|
66
|
+
"cartId": "c1d2e3f4-5a6b-4c7d-8e9f-0a1b2c3d4e5f",
|
|
67
|
+
"customerId": "7a1e5c9d-8b3f-4f2a-a6d4-2e9c0b7f3d51",
|
|
68
|
+
"items": [
|
|
69
|
+
{
|
|
70
|
+
"productId": "0e8f4b2a-7c1d-4f3e-9a5b-6d2c8e1f7a93",
|
|
71
|
+
"quantity": 2,
|
|
72
|
+
"unitPrice": 2000,
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
"total": 4000,
|
|
76
|
+
"currency": "GBP",
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
client.publish("CartCheckedOut", event)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
```java PublishCartCheckedOut.java
|
|
83
|
+
import com.acme.events.EventsClient;
|
|
84
|
+
import java.util.List;
|
|
85
|
+
import java.util.Map;
|
|
86
|
+
|
|
87
|
+
public class PublishCartCheckedOut {
|
|
88
|
+
public static void main(String[] args) {
|
|
89
|
+
var client = new EventsClient(
|
|
90
|
+
System.getenv("ACME_API_KEY")
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
var event = Map.of(
|
|
94
|
+
"eventId", "e4b7c1d9-2f6a-4e8b-a3c5-7d9f1b3e5a02",
|
|
95
|
+
"occurredAt", "2026-09-11T08:12:45Z",
|
|
96
|
+
"cartId", "c1d2e3f4-5a6b-4c7d-8e9f-0a1b2c3d4e5f",
|
|
97
|
+
"customerId", "7a1e5c9d-8b3f-4f2a-a6d4-2e9c0b7f3d51",
|
|
98
|
+
"items", List.of(
|
|
99
|
+
Map.of(
|
|
100
|
+
"productId", "0e8f4b2a-7c1d-4f3e-9a5b-6d2c8e1f7a93",
|
|
101
|
+
"quantity", 2,
|
|
102
|
+
"unitPrice", 2000
|
|
103
|
+
)
|
|
104
|
+
),
|
|
105
|
+
"total", 4000,
|
|
106
|
+
"currency", "GBP"
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
client.publish("CartCheckedOut", event);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
</CodeGroup>
|
|
115
|
+
|
|
116
|
+
</Column>
|
|
117
|
+
|
|
118
|
+
</Columns>
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
<Columns cols={2}>
|
|
123
|
+
|
|
124
|
+
<Column>
|
|
125
|
+
|
|
126
|
+
## 2. Publish a multi-item checkout with a discount
|
|
127
|
+
|
|
128
|
+
A customer checks out T-shirts, a hoodie and a cap with the `AUTUMN10` voucher. The event carries the subtotal, the discount and the final total so consumers do not need to reprice the cart.
|
|
129
|
+
|
|
130
|
+
### Payload details
|
|
131
|
+
|
|
132
|
+
- `items` has three lines: 2 T-shirts at 2,000, 1 hoodie at 4,500 and 1 cap at 1,500 pence.
|
|
133
|
+
- `subtotal` is the total before discounts.
|
|
134
|
+
- `discount` is the 10% voucher saving.
|
|
135
|
+
- `total` is `subtotal` minus `discount`.
|
|
136
|
+
|
|
137
|
+
The subtotal is **4,000 + 4,500 + 1,500 = 10,000 pence (£100.00)**, the discount is **1,000 pence (£10.00)** and the total is **9,000 pence (£90.00)**.
|
|
138
|
+
|
|
139
|
+
### Using this example
|
|
140
|
+
|
|
141
|
+
Check that the payment is taken for 9,000 pence, not the subtotal, and that the order has three lines.
|
|
142
|
+
|
|
143
|
+
The examples use a **fictional Acme Events SDK** to publish a payload matching the CartCheckedOut schema. The package names and publish methods are illustrative.
|
|
144
|
+
|
|
145
|
+
</Column>
|
|
146
|
+
|
|
147
|
+
<Column>
|
|
148
|
+
|
|
149
|
+
<CodeGroup dropdown>
|
|
150
|
+
|
|
151
|
+
```typescript publish-cart-checked-out.ts
|
|
152
|
+
import { EventsClient } from '@acme/events';
|
|
153
|
+
import type { CartCheckedOut } from './schemas/cart-checked-out';
|
|
154
|
+
|
|
155
|
+
const client = new EventsClient({
|
|
156
|
+
apiKey: process.env.ACME_API_KEY!,
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
const event: CartCheckedOut = {
|
|
160
|
+
eventId: 'f6a2d8c4-9b1e-4a7d-b5c3-1e7f9a2d4c68',
|
|
161
|
+
occurredAt: '2026-09-14T17:30:05Z',
|
|
162
|
+
cartId: 'a7c3e9f1-2b4d-4e6a-8f1c-3d5b7e9a1c24',
|
|
163
|
+
customerId: '3f2c8a91-6b4e-4d7a-9c1f-8e5b2a7d4c60',
|
|
164
|
+
items: [
|
|
165
|
+
{
|
|
166
|
+
productId: '0e8f4b2a-7c1d-4f3e-9a5b-6d2c8e1f7a93',
|
|
167
|
+
quantity: 2,
|
|
168
|
+
unitPrice: 2000,
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
productId: '5b9d3e7f-1a2c-4b6d-8e0f-2c4a6e8b0d15',
|
|
172
|
+
quantity: 1,
|
|
173
|
+
unitPrice: 4500,
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
productId: '8d4f6a2c-3e5b-4c7d-9f1a-5b7d9e3c1a46',
|
|
177
|
+
quantity: 1,
|
|
178
|
+
unitPrice: 1500,
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
subtotal: 10000,
|
|
182
|
+
discount: 1000,
|
|
183
|
+
total: 9000,
|
|
184
|
+
currency: 'GBP',
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
await client.publish('CartCheckedOut', event);
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
```python publish_cart_checked_out.py
|
|
191
|
+
import os
|
|
192
|
+
from acme_events import EventsClient
|
|
193
|
+
|
|
194
|
+
client = EventsClient(api_key=os.environ["ACME_API_KEY"])
|
|
195
|
+
|
|
196
|
+
event = {
|
|
197
|
+
"eventId": "f6a2d8c4-9b1e-4a7d-b5c3-1e7f9a2d4c68",
|
|
198
|
+
"occurredAt": "2026-09-14T17:30:05Z",
|
|
199
|
+
"cartId": "a7c3e9f1-2b4d-4e6a-8f1c-3d5b7e9a1c24",
|
|
200
|
+
"customerId": "3f2c8a91-6b4e-4d7a-9c1f-8e5b2a7d4c60",
|
|
201
|
+
"items": [
|
|
202
|
+
{
|
|
203
|
+
"productId": "0e8f4b2a-7c1d-4f3e-9a5b-6d2c8e1f7a93",
|
|
204
|
+
"quantity": 2,
|
|
205
|
+
"unitPrice": 2000,
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
"productId": "5b9d3e7f-1a2c-4b6d-8e0f-2c4a6e8b0d15",
|
|
209
|
+
"quantity": 1,
|
|
210
|
+
"unitPrice": 4500,
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
"productId": "8d4f6a2c-3e5b-4c7d-9f1a-5b7d9e3c1a46",
|
|
214
|
+
"quantity": 1,
|
|
215
|
+
"unitPrice": 1500,
|
|
216
|
+
},
|
|
217
|
+
],
|
|
218
|
+
"subtotal": 10000,
|
|
219
|
+
"discount": 1000,
|
|
220
|
+
"total": 9000,
|
|
221
|
+
"currency": "GBP",
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
client.publish("CartCheckedOut", event)
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
```java PublishCartCheckedOut.java
|
|
228
|
+
import com.acme.events.EventsClient;
|
|
229
|
+
import java.util.List;
|
|
230
|
+
import java.util.Map;
|
|
231
|
+
|
|
232
|
+
public class PublishCartCheckedOut {
|
|
233
|
+
public static void main(String[] args) {
|
|
234
|
+
var client = new EventsClient(
|
|
235
|
+
System.getenv("ACME_API_KEY")
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
var event = Map.of(
|
|
239
|
+
"eventId", "f6a2d8c4-9b1e-4a7d-b5c3-1e7f9a2d4c68",
|
|
240
|
+
"occurredAt", "2026-09-14T17:30:05Z",
|
|
241
|
+
"cartId", "a7c3e9f1-2b4d-4e6a-8f1c-3d5b7e9a1c24",
|
|
242
|
+
"customerId", "3f2c8a91-6b4e-4d7a-9c1f-8e5b2a7d4c60",
|
|
243
|
+
"items", List.of(
|
|
244
|
+
Map.of(
|
|
245
|
+
"productId", "0e8f4b2a-7c1d-4f3e-9a5b-6d2c8e1f7a93",
|
|
246
|
+
"quantity", 2,
|
|
247
|
+
"unitPrice", 2000
|
|
248
|
+
),
|
|
249
|
+
Map.of(
|
|
250
|
+
"productId", "5b9d3e7f-1a2c-4b6d-8e0f-2c4a6e8b0d15",
|
|
251
|
+
"quantity", 1,
|
|
252
|
+
"unitPrice", 4500
|
|
253
|
+
),
|
|
254
|
+
Map.of(
|
|
255
|
+
"productId", "8d4f6a2c-3e5b-4c7d-9f1a-5b7d9e3c1a46",
|
|
256
|
+
"quantity", 1,
|
|
257
|
+
"unitPrice", 1500
|
|
258
|
+
)
|
|
259
|
+
),
|
|
260
|
+
"subtotal", 10000,
|
|
261
|
+
"discount", 1000,
|
|
262
|
+
"total", 9000,
|
|
263
|
+
"currency", "GBP"
|
|
264
|
+
);
|
|
265
|
+
|
|
266
|
+
client.publish("CartCheckedOut", event);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
</CodeGroup>
|
|
272
|
+
|
|
273
|
+
</Column>
|
|
274
|
+
|
|
275
|
+
</Columns>
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
<Columns cols={2}>
|
|
2
|
+
|
|
3
|
+
<Column>
|
|
4
|
+
|
|
5
|
+
## 1. Calculate a voucher discount
|
|
6
|
+
|
|
7
|
+
During checkout, the Cart API sends `CalculateDiscount` with the customer's `AUTUMN10` code. The Promotion Service checks the promotion rules and returns the discount, and also publishes `DiscountCalculated`.
|
|
8
|
+
|
|
9
|
+
### Payload details
|
|
10
|
+
|
|
11
|
+
- `cartId` and `customerId` identify the cart and its owner.
|
|
12
|
+
- `subtotal` is 10,000 pence, the cart total before discounts.
|
|
13
|
+
- `currency` is `GBP`.
|
|
14
|
+
- `promotionCode` is `AUTUMN10`, a 10% off voucher.
|
|
15
|
+
- The response `discount` is in pence, and `appliedPromotions` lists the promotions used.
|
|
16
|
+
|
|
17
|
+
10% of 10,000 pence gives a discount of **1,000 pence (£10.00)**.
|
|
18
|
+
|
|
19
|
+
### Example response
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"discount": 1000,
|
|
24
|
+
"appliedPromotions": ["AUTUMN10"]
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Using this example
|
|
29
|
+
|
|
30
|
+
Check that the discount is 1,000 pence and that `AUTUMN10` appears in `appliedPromotions`.
|
|
31
|
+
|
|
32
|
+
The examples use a **fictional Acme Events SDK** to send a payload matching the CalculateDiscount schema. The package names and send methods are illustrative.
|
|
33
|
+
|
|
34
|
+
</Column>
|
|
35
|
+
|
|
36
|
+
<Column>
|
|
37
|
+
|
|
38
|
+
<CodeGroup dropdown>
|
|
39
|
+
|
|
40
|
+
```typescript send-calculate-discount.ts
|
|
41
|
+
import { EventsClient } from '@acme/events';
|
|
42
|
+
import type { CalculateDiscountRequest, CalculateDiscountResponse } from './schemas/calculate-discount';
|
|
43
|
+
|
|
44
|
+
const client = new EventsClient({
|
|
45
|
+
apiKey: process.env.ACME_API_KEY!,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const request: CalculateDiscountRequest = {
|
|
49
|
+
cartId: 'a7c3e9f1-2b4d-4e6a-8f1c-3d5b7e9a1c24',
|
|
50
|
+
customerId: '3f2c8a91-6b4e-4d7a-9c1f-8e5b2a7d4c60',
|
|
51
|
+
subtotal: 10000,
|
|
52
|
+
currency: 'GBP',
|
|
53
|
+
promotionCode: 'AUTUMN10',
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const result: CalculateDiscountResponse = await client.send('CalculateDiscount', request);
|
|
57
|
+
|
|
58
|
+
console.log(result.discount, result.appliedPromotions);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
```python send_calculate_discount.py
|
|
62
|
+
import os
|
|
63
|
+
from acme_events import EventsClient
|
|
64
|
+
|
|
65
|
+
client = EventsClient(api_key=os.environ["ACME_API_KEY"])
|
|
66
|
+
|
|
67
|
+
request = {
|
|
68
|
+
"cartId": "a7c3e9f1-2b4d-4e6a-8f1c-3d5b7e9a1c24",
|
|
69
|
+
"customerId": "3f2c8a91-6b4e-4d7a-9c1f-8e5b2a7d4c60",
|
|
70
|
+
"subtotal": 10000,
|
|
71
|
+
"currency": "GBP",
|
|
72
|
+
"promotionCode": "AUTUMN10",
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
result = client.send("CalculateDiscount", request)
|
|
76
|
+
print(result["discount"], result.get("appliedPromotions", []))
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
```java SendCalculateDiscount.java
|
|
80
|
+
import com.acme.events.EventsClient;
|
|
81
|
+
import java.util.Map;
|
|
82
|
+
|
|
83
|
+
public class SendCalculateDiscount {
|
|
84
|
+
public static void main(String[] args) {
|
|
85
|
+
var client = new EventsClient(
|
|
86
|
+
System.getenv("ACME_API_KEY")
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
var request = Map.of(
|
|
90
|
+
"cartId", "a7c3e9f1-2b4d-4e6a-8f1c-3d5b7e9a1c24",
|
|
91
|
+
"customerId", "3f2c8a91-6b4e-4d7a-9c1f-8e5b2a7d4c60",
|
|
92
|
+
"subtotal", 10000,
|
|
93
|
+
"currency", "GBP",
|
|
94
|
+
"promotionCode", "AUTUMN10"
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
var result = client.send("CalculateDiscount", request);
|
|
98
|
+
System.out.println(result.get("discount"));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
</CodeGroup>
|
|
104
|
+
|
|
105
|
+
</Column>
|
|
106
|
+
|
|
107
|
+
</Columns>
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
<Columns cols={2}>
|
|
112
|
+
|
|
113
|
+
<Column>
|
|
114
|
+
|
|
115
|
+
## 2. Price a cart with no applicable promotions
|
|
116
|
+
|
|
117
|
+
A customer checks out two T-shirts without a voucher. The Cart API still asks the Promotion Service for a discount, in case an automatic promotion applies.
|
|
118
|
+
|
|
119
|
+
### Payload details
|
|
120
|
+
|
|
121
|
+
- `cartId` identifies the cart.
|
|
122
|
+
- `customerId` and `promotionCode` are optional and omitted here, so only automatic promotions are checked.
|
|
123
|
+
- `subtotal` is 4,000 pence (£40.00) in `GBP`.
|
|
124
|
+
- The response `discount` is `0` and `appliedPromotions` is omitted.
|
|
125
|
+
|
|
126
|
+
### Example response
|
|
127
|
+
|
|
128
|
+
```json
|
|
129
|
+
{
|
|
130
|
+
"discount": 0
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Using this example
|
|
135
|
+
|
|
136
|
+
Check that the Cart API accepts a zero discount and a missing `appliedPromotions` list, and keeps the total at 4,000 pence.
|
|
137
|
+
|
|
138
|
+
The examples use a **fictional Acme Events SDK** to send a payload matching the CalculateDiscount schema. The package names and send methods are illustrative.
|
|
139
|
+
|
|
140
|
+
</Column>
|
|
141
|
+
|
|
142
|
+
<Column>
|
|
143
|
+
|
|
144
|
+
<CodeGroup dropdown>
|
|
145
|
+
|
|
146
|
+
```typescript send-calculate-discount.ts
|
|
147
|
+
import { EventsClient } from '@acme/events';
|
|
148
|
+
import type { CalculateDiscountRequest, CalculateDiscountResponse } from './schemas/calculate-discount';
|
|
149
|
+
|
|
150
|
+
const client = new EventsClient({
|
|
151
|
+
apiKey: process.env.ACME_API_KEY!,
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
const request: CalculateDiscountRequest = {
|
|
155
|
+
cartId: 'c1d2e3f4-5a6b-4c7d-8e9f-0a1b2c3d4e5f',
|
|
156
|
+
subtotal: 4000,
|
|
157
|
+
currency: 'GBP',
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const result: CalculateDiscountResponse = await client.send('CalculateDiscount', request);
|
|
161
|
+
|
|
162
|
+
console.log(result.discount, result.appliedPromotions);
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
```python send_calculate_discount.py
|
|
166
|
+
import os
|
|
167
|
+
from acme_events import EventsClient
|
|
168
|
+
|
|
169
|
+
client = EventsClient(api_key=os.environ["ACME_API_KEY"])
|
|
170
|
+
|
|
171
|
+
request = {
|
|
172
|
+
"cartId": "c1d2e3f4-5a6b-4c7d-8e9f-0a1b2c3d4e5f",
|
|
173
|
+
"subtotal": 4000,
|
|
174
|
+
"currency": "GBP",
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
result = client.send("CalculateDiscount", request)
|
|
178
|
+
print(result["discount"], result.get("appliedPromotions", []))
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
```java SendCalculateDiscount.java
|
|
182
|
+
import com.acme.events.EventsClient;
|
|
183
|
+
import java.util.Map;
|
|
184
|
+
|
|
185
|
+
public class SendCalculateDiscount {
|
|
186
|
+
public static void main(String[] args) {
|
|
187
|
+
var client = new EventsClient(
|
|
188
|
+
System.getenv("ACME_API_KEY")
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
var request = Map.of(
|
|
192
|
+
"cartId", "c1d2e3f4-5a6b-4c7d-8e9f-0a1b2c3d4e5f",
|
|
193
|
+
"subtotal", 4000,
|
|
194
|
+
"currency", "GBP"
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
var result = client.send("CalculateDiscount", request);
|
|
198
|
+
System.out.println(result.get("discount"));
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
</CodeGroup>
|
|
204
|
+
|
|
205
|
+
</Column>
|
|
206
|
+
|
|
207
|
+
</Columns>
|