-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathordercalculate.ts
More file actions
29 lines (24 loc) · 1.07 KB
/
ordercalculate.ts
File metadata and controls
29 lines (24 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { OrderCalculatePayload, withErrorHandledOcWebhookAuth } from '@ordercloud/catalyst';
import type { NextApiResponse } from 'next'
import { OrderCalculateResponse } from 'ordercloud-javascript-sdk';
import { NextApiRequestTyped } from '../../../Types/NextApiRequestTyped';
// Verfies the header "x-oc-hash" matches the provided hashKey
// use withOcWebhookAuth() if you want to catch errors yourself. See shippingrates.ts.
export default withErrorHandledOcWebhookAuth(
orderCalculateHandler, process.env.OC_WEBHOOK_HASH_KEY
);
// Exporting this config allows access the raw, unparsed http body, which is needed for hash validation.
// withOcWebhookAuth() will populate req.body with the parsed body object so it can be used in the route handler.
export const config = {
api: {
bodyParser: false,
},
}
// Route handler
function orderCalculateHandler(
req: NextApiRequestTyped<OrderCalculatePayload>,
res: NextApiResponse<OrderCalculateResponse>
): void | Promise<void> {
// Put your custom order calculate logic here.
res.status(200).json({ TaxTotal: 123.45 })
}