-
Notifications
You must be signed in to change notification settings - Fork 7
/
route.ts
29 lines (25 loc) · 953 Bytes
/
route.ts
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
28
29
import { getShippingAppData } from '@/app/actions/app-data';
import { calculatePrice } from '@/app/utils/shipping-calculator';
import { wixAppClient } from '@/app/utils/wix-sdk.app';
wixAppClient.shippingRates.provideHandlers({
async getShippingRates({ request, metadata }) {
const appData = await getShippingAppData({ instanceId: metadata.instanceId! });
const currency = metadata.currency;
// The SPI implementation: implement your own shipping rates.
return {
shippingRates: appData.shippingMethods.map(({ code, title, logistics, costs, unitOfMeasure }) => ({
code,
title,
logistics,
cost: {
price: `${calculatePrice(request, costs, unitOfMeasure)}`,
currency: currency!,
},
})),
};
},
});
export async function POST(request: Request) {
console.info('Shipping rates::POST - called');
return wixAppClient.servicePlugins.processRequest(request);
}