Skip to content

Commit 93395a8

Browse files
authored
chore(release): publish content (#21)
Co-authored-by: ct-sdks[bot] <153784748+ct-sdks[bot]@users.noreply.github.com>
1 parent 9b7fce2 commit 93395a8

143 files changed

Lines changed: 6049 additions & 5025 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.agents/README.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

.agents/plugins/commercetools/skills/commercetools-checkout/SKILL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ When this skill is invoked, always follow these steps:
4949

5050
See [payment-only-mode.md](./references/payment-only-mode.md) for:
5151
- Full architecture diagram (Browser SDK → Checkout service → PSP)
52-
- Session creation (`/api/checkout/session` → commercetools Sessions API)
52+
- Session creation (`/<api>/checkout/session` → commercetools Sessions API)
5353
- `paymentFlow`, `checkoutFlow`, and `expressPayment` implementation patterns
5454
- PSP connector setup (Stripe, Adyen, Mollie)
5555
- Webhook handling and order confirmation

.agents/plugins/commercetools/skills/commercetools-checkout/references/payment-only-mode.md

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Adds payment processing via the [Checkout Browser SDK](https://docs.commercetool
4040
```
4141
Browser (SDK) → Checkout service → PSP
4242
43-
/api/checkout/session (creates Checkout Session from cart)
43+
/<api>/checkout/session (creates Checkout Session from cart)
4444
4545
commercetools Sessions API (POST https://session.{region}.commercetools.com/{projectKey}/sessions)
4646
```
@@ -51,33 +51,33 @@ The storefront creates a **Checkout Session** (server-side, via a new API route)
5151

5252
## Step 0 — Prerequisites
5353

54-
### 0a. Add environment variables to `site/.env`
54+
### 0a. Add environment variables to `<root-dir>/.env`
5555

5656
```bash
5757
# The key of your Checkout Application
5858
CTP_CHECKOUT_APP_KEY=storefront-checkout
5959
```
6060

61-
`CTP_PROJECT_KEY`, `CTP_API_URL`, and `CTP_SCOPES` are already in `site/.env`. The region is derived automatically from `CTP_API_URL` at startup — **do not add a separate `CT_REGION` variable**. `projectKey` and `region` are returned to the browser by `/api/checkout/session`, so **no `NEXT_PUBLIC_*` variables are needed**.
61+
`CTP_PROJECT_KEY`, `CTP_API_URL`, and `CTP_SCOPES` are already in `<root-dir>/.env`. The region is derived automatically from `CTP_API_URL` at startup — **do not add a separate `CT_REGION` variable**. `projectKey` and `region` are returned to the browser by `/<api>/checkout/session`.
6262

6363
### 0b. Install the Browser SDK
6464

6565
```bash
66-
cd site && npm install @commercetools/checkout-browser-sdk
66+
cd <root-dir> && npm install @commercetools/checkout-browser-sdk
6767
```
6868

6969
---
7070

7171
## Step 1 — Session creation API route
7272

73-
Create `site/app/api/checkout/session/route.ts`. This route:
73+
Create `<api-dir>/checkout/session`. This route:
7474
1. Reads the current cart ID from the session
7575
2. Exchanges an OAuth token
7676
3. POSTs to the commercetools Sessions API to create a Checkout Session
7777
4. Returns the `sessionId` to the browser
7878

7979
```typescript
80-
// site/app/api/checkout/session/route.ts
80+
// <root-dir>/<api-dir>/checkout/session/route.ts
8181

8282
const APP_KEY = process.env.CTP_CHECKOUT_APP_KEY!;
8383

@@ -87,6 +87,7 @@ const REGION = API_URL.replace(/^https?:\/\/api\./, '').replace(/\.commercetools
8787

8888
async function getManageSessionsToken(): Promise<string> {
8989
// fetch token from oauth/token?grant_type=client_credentials
90+
// use the full scope provided in .env vars
9091
}
9192

9293
export async function POST() {
@@ -110,7 +111,7 @@ export async function POST() {
110111
);
111112
// handle errors here
112113
const data = await res.json();
113-
// Return projectKey and region so the client component needs no NEXT_PUBLIC_ vars
114+
// Return projectKey and region so the client component needs no frontend facing environment vars
114115
return NextResponse.json({ sessionId: data.id, projectKey: PROJECT_KEY, region: REGION });
115116
} catch (e: unknown) {
116117
// handle error
@@ -126,10 +127,11 @@ export async function POST() {
126127

127128
This is the least invasive change. Keep the existing address and shipping steps. Only the payment step.
128129

129-
#### 2A-1. Implement `StepPayment.tsx`
130+
#### 2A-1. Implement `StepPayment` frontend component
130131

132+
Example react/typescript component
131133
```typescript
132-
// site/components/checkout/StepPayment.tsx
134+
// <root-dir>/components/checkout/StepPayment.tsx
133135
'use client';
134136
...
135137
import { paymentFlow } from '@commercetools/checkout-browser-sdk';
@@ -176,7 +178,7 @@ export default function StepPayment() {
176178
}
177179
```
178180

179-
**No `NEXT_PUBLIC_*` env vars are needed.** `projectKey` and `region` are returned by `/api/checkout/session` alongside the `sessionId` and read from the response in the client component.
181+
**No extra environment env vars are needed.** `projectKey` and `region` are returned by `/<api>/checkout/session` alongside the `sessionId` and read from the response in the client component.
180182

181183
#### 2A-2. Integrate into the checkout step page
182184

@@ -218,22 +220,19 @@ Available CSS variables are listed in the Checkout theming docs.
218220
|---|---|---|
219221
| `CTP_CHECKOUT_APP_KEY` | No | **New** — key of the Checkout Application |
220222

221-
222-
No `CT_REGION`, `NEXT_PUBLIC_CT_PROJECT_KEY`, or `NEXT_PUBLIC_CT_REGION` variables are needed. The session API derives the region from `CTP_API_URL` and returns `{ sessionId, projectKey, region }` to the browser.
223-
224223
---
225224

226225
## Checklist
227226

228227
### Prerequisites
229-
- [ ] `CTP_CHECKOUT_APP_KEY` added to `site/.env` (the only new variable required)
228+
- [ ] `CTP_CHECKOUT_APP_KEY` added to `<root-dir>/.env` (the only new variable required)
230229
- [ ] `@commercetools/checkout-browser-sdk` installed
231230

232231
### Session API
233-
- [ ] Create `site/app/api/checkout/session/route.ts`
232+
- [ ] Create `<api-dir>/checkout/session` endpoint
234233

235234
### SDK integration (per mode)
236-
- [ ] **paymentFlow**: Replace `StepPayment.tsx` with commercetools widget mount; remove payment actions from `/api/checkout/route.ts`
235+
- [ ] **paymentFlow**: Replace `StepPayment.tsx` with commercetools widget mount;
237236

238237
### Order confirmation
239238
- [ ] Update confirmation page to read `?orderId=` from commercetools redirect URL or `onInfo` callback
@@ -246,6 +245,6 @@ No `CT_REGION`, `NEXT_PUBLIC_CT_PROJECT_KEY`, or `NEXT_PUBLIC_CT_REGION` variabl
246245

247246
**`<div data-ctc />`** — For `paymentFlow`, always render `<div data-ctc />` in the component's JSX. Without it the commercetools widget mounts at the document root and occupies the full page.
248247

249-
**No `NEXT_PUBLIC_*` vars**`projectKey` and `region` are server-side config. Return them from `/api/checkout/session` alongside `sessionId` so the browser never needs `NEXT_PUBLIC_` prefixed variables for these values.
248+
**No `PUBLIC_*` vars**`projectKey` and `region` are server-side config. Return them from `/<api>/checkout/session` alongside `sessionId` so the browser never needs environment vars for these values.
250249

251250
**`paymentReturnUrl` must be registered** — Only one return URL per Connector. The URL must exactly match what's registered in the commercetools Application `paymentsConfiguration.paymentReturnUrl`.

.agents/plugins/commercetools/skills/commercetools-platform/references/sdk-setup.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export async function getSomething(id: string) {
9191

9292
## Pattern 3: Environment Variables
9393

94-
**INCORRECT:** `NEXT_PUBLIC_CTP_CLIENT_SECRET` — exposes the secret in the browser bundle.
94+
**INCORRECT:** Example Nextjs `NEXT_PUBLIC_CTP_CLIENT_SECRET` — exposes the secret in the browser bundle.
9595

9696
**CORRECT — all commercetools variables are server-only (no `NEXT_PUBLIC_` prefix):**
9797

@@ -123,5 +123,5 @@ Use **Frontend B2C** template (or Frontend B2B), then make sure `manage_sessions
123123

124124
- [ ] `lib/ct/client.ts` exports a single `apiRoot` — no `new ClientBuilder()` anywhere else
125125
- [ ] `.env` is listed in `.gitignore`
126-
- [ ] No commercetools env vars use the `NEXT_PUBLIC_` prefix
126+
- [ ] No commercetools env vars exposed to client rendering component
127127
- [ ] All `lib/ct/*.ts` helper functions import `apiRoot` from `./client`

0 commit comments

Comments
 (0)