Skip to content

Commit 6d9e4bd

Browse files
committed
Add Chit Chats rates to fetchCheapestRate batch shipping selection
1 parent 2eb4f9f commit 6d9e4bd

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

resolution-frontend/src/lib/server/canada-post.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { env } from '$env/dynamic/private';
22
import xml2js from 'xml2js';
33
import { PDFDocument } from 'pdf-lib';
4+
import { fetchChitChatsRates } from './chit-chats';
45

56
export const INCHES_TO_CM = 2.54;
67
export const GRAMS_TO_KG = 0.001;
@@ -717,6 +718,28 @@ export async function fetchCheapestRate(params: {
717718
console.error('Parcel rate lookup failed:', err);
718719
}
719720

721+
try {
722+
if (env.CHITCHATS_ACCESS_TOKEN && env.CHITCHATS_CLIENT_ID) {
723+
const chitChatsRates = await fetchChitChatsRates({
724+
country: params.country,
725+
postalCode: params.postalCode,
726+
name: 'Rate Quote',
727+
address1: '123 Main St',
728+
city: 'Unknown',
729+
weightGrams: params.weightGrams,
730+
lengthIn: effectiveLength,
731+
widthIn: effectiveWidth,
732+
heightIn: params.packageType === 'box' ? params.heightIn : 0.5,
733+
valueCad: 1.00
734+
});
735+
for (const rate of chitChatsRates) {
736+
allOptions.push({ serviceName: rate.serviceName, total: rate.priceDetails.total });
737+
}
738+
}
739+
} catch (err) {
740+
console.error('Chit Chats rate lookup failed:', err);
741+
}
742+
720743
if (allOptions.length === 0) return null;
721744

722745
allOptions.sort((a, b) => a.total - b.total);

0 commit comments

Comments
 (0)