|
1 | 1 | import { env } from '$env/dynamic/private'; |
2 | 2 | import xml2js from 'xml2js'; |
3 | 3 | import { PDFDocument } from 'pdf-lib'; |
| 4 | +import { fetchChitChatsRates } from './chit-chats'; |
4 | 5 |
|
5 | 6 | export const INCHES_TO_CM = 2.54; |
6 | 7 | export const GRAMS_TO_KG = 0.001; |
@@ -717,6 +718,28 @@ export async function fetchCheapestRate(params: { |
717 | 718 | console.error('Parcel rate lookup failed:', err); |
718 | 719 | } |
719 | 720 |
|
| 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 | + |
720 | 743 | if (allOptions.length === 0) return null; |
721 | 744 |
|
722 | 745 | allOptions.sort((a, b) => a.total - b.total); |
|
0 commit comments