Update saleor-webhook.md (#214)

This commit is contained in:
Lukasz Ostrowski 2023-03-13 11:08:19 +01:00 committed by GitHub
parent ac8293a195
commit f38f3f403b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -22,6 +22,15 @@ In Next.js pages create a page, e.g. `pages/api/webhooks/order-created.ts`. We r
```typescript ```typescript
import { SaleorAsyncWebhook } from "@saleor/app-sdk/handlers/next"; import { SaleorAsyncWebhook } from "@saleor/app-sdk/handlers/next";
/**
* Default body parser must be turned off - raw body is needed to verify signature
* /
export const config = {
api: {
bodyParser: false,
},
};
/** /**
* To be type-safe, define payload from API. This should be imported from generated GraphQL code * To be type-safe, define payload from API. This should be imported from generated GraphQL code
*/ */
@ -37,6 +46,15 @@ For `SaleorSyncWebhook` it will be similar. Create e.g. `order-calculate-taxes.t
```typescript ```typescript
import { SaleorSyncWebhook } from "@saleor/app-sdk/handlers/next"; import { SaleorSyncWebhook } from "@saleor/app-sdk/handlers/next";
/**
* Default body parser must be turned off - raw body is needed to verify signature
* /
export const config = {
api: {
bodyParser: false,
},
};
/** /**
* To be type-safe, define payload from API. This should be imported from generated GraphQL code * To be type-safe, define payload from API. This should be imported from generated GraphQL code
*/ */
@ -109,6 +127,15 @@ type OrderPayload = {
id: string; id: string;
}; };
/**
* Default body parser must be turned off - raw body is needed to verify signature
* /
export const config = {
api: {
bodyParser: false,
},
};
export const orderCreatedWebhook = new SaleorAsyncWebhook<OrderPayload>({ export const orderCreatedWebhook = new SaleorAsyncWebhook<OrderPayload>({
name: "Order Created", name: "Order Created",
webhookPath: "api/webhooks/order-created", webhookPath: "api/webhooks/order-created",
@ -157,6 +184,15 @@ type Payload = {
}; };
}; };
/**
* Default body parser must be turned off - raw body is needed to verify signature
* /
export const config = {
api: {
bodyParser: false,
},
};
export const orderCalculateTaxesWebhook = new SaleorAsyncWebhook<Payload>({ export const orderCalculateTaxesWebhook = new SaleorAsyncWebhook<Payload>({
name: "Order Calculate Taxes", name: "Order Calculate Taxes",
webhookPath: "api/webhooks/order-created", webhookPath: "api/webhooks/order-created",