Skip to content

Commit 607ef15

Browse files
committed
fix(lune-integration): Correct typos, rename lune.js to index.js, update README, and update shipment service ID varible
1 parent 33d3142 commit 607ef15

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

src/functions/lune-integration/README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ This Foxy.io-Lune integration provides you with:
1616
- Set the environment variables
1717
- Deploy the site
1818

19-
You will also need to configure your Lune account default project bundles, and billing info.
19+
Notes:
20+
21+
- You will also need to configure your Lune account default project bundles, and billing info.
22+
- Note that this integration doesn't handle multi ship transactions. It will only calculate shipping rates with CO2 offset for one shipping, and it will grab the information from the first shipment to create a CO2 offset order in lune.
2023

2124
### Deploy this repository to Netlify
2225

@@ -25,12 +28,12 @@ You will also need to configure your Lune account default project bundles, and b
2528
3. Add a new site and select the **Import an existing project** option
2629
4. Connect your GitHub account and choose your repository (the repository name should be something like `your-github-username/foxy-node-netlify-functions`)
2730
5. In the site settings, click the **Show advanced** button
28-
6. Under the Advanced build settings section, click the **New variable** button, yoyu will add two environment variables.
31+
6. Under the Advanced build settings section, click the **New variable** button, you will add two environment variables.
2932
7. In the Key field, enter `LUNE_API_KEY`
3033
8. In the Value field, enter your Lune API key
3134
9. Deploy the site
3235

33-
### Create a new Foxy Weebhok
36+
### Create a new Foxy Webhook
3437

3538
After the deploy is complete, click the "functions" tab, look for the `lune-integration` function and copy the **Endpoint URL**.
3639

@@ -42,7 +45,7 @@ Specify a query string value within the `API filter query string` with the follo
4245
zoom=applied_taxes,billing_addresses,custom_fields,customer,discounts,items,items:item_category,items:item_options,payments,shipments,attributes
4346
```
4447

45-
Then click on `Update Weebhooks Next`
48+
Then click on `Update Webhooks Next`
4649

4750
## Upgrade your webhook
4851

src/functions/lune-integration/custom-shipping-code.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ const weightUnit = "lb";
1515
const originAddress = "address goes here, city goes here";
1616

1717
// How to add the offset amount to the rates?
18-
// If set to false: Add rates with the CO2 offset estimate ammount included
19-
// If set to true: Keep regular rates, and duplicate them to add them with the CO2 offset estimate ammount included
20-
const addOffsetRatesSeparetly = true;
18+
// If set to false: Add rates with the CO2 offset estimate amount included
19+
// If set to true: Keep regular rates, and duplicate them to add them with the CO2 offset estimate amount included
20+
const addOffsetRatesSeparately = true;
2121

2222
/* --- End Config --- */
2323

@@ -111,7 +111,7 @@ try {
111111
shippingResultsEmissions.push(shippingEmissions);
112112
}
113113

114-
// Add rates Separetly or Update rates with CO2 Offset amount
114+
// Add rates Separately or Update rates with CO2 Offset amount
115115
upsertCO2ShippingRates(shippingResultsEmissions, attributesRequestPayload);
116116

117117
//Save estimate ids with service IDs in the cart's attributes
@@ -155,7 +155,7 @@ function upsertCO2ShippingRates(
155155
Number(price) + Number(quote.estimated_total_cost)
156156
).toFixed(2);
157157

158-
if (addOffsetRatesSeparetly) {
158+
if (addOffsetRatesSeparately) {
159159
const serviceIdNewRate = 10001 + index;
160160

161161
const serviceNameNewRate = `${service_name} (${CO2MassString})`;

src/functions/lune-integration/lune.js renamed to src/functions/lune-integration/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ async function handler(requestEvent) {
1212
const cartDetails = JSON.parse(requestEvent.body);
1313
const ratePrefix = "rate_id_";
1414
const selectedShippingRateID =
15-
cartDetails["_embeded"]["fx:shipment"].shipping_service_id;
15+
cartDetails["_embedded"]["fx:shipments"][0].shipping_service_id;
1616
const luneEstimateID = cartDetails["_embedded"]["fx:attributes"].find(
1717
(attr) => attr.name === `${ratePrefix}${selectedShippingRateID}`
1818
).value;
1919

20-
const LUNE_API_KEY = config.lune.accessKey;
20+
const LUNE_API_KEY = config.lune.apiKey;
2121

2222
if (!luneEstimateID) {
2323
console.log("No lune CO2 estimate ID is provided");
@@ -33,10 +33,10 @@ async function handler(requestEvent) {
3333
const orderByEstimateIdUrl = "https://api.lune.co/v1/orders/by-estimate";
3434
const response = await fetch(orderByEstimateIdUrl, {
3535
body: JSON.stringify({
36-
estimate_id: "luneEstimateID",
36+
estimate_id: luneEstimateID,
3737
metadata: {
3838
customer_email: cartDetails.customer_email,
39-
transaction_id: cartDetails.id,
39+
transaction_id: String(cartDetails.id),
4040
},
4141
}),
4242
headers: {
@@ -48,10 +48,10 @@ async function handler(requestEvent) {
4848
const data = await response.json();
4949

5050
if (data.id) {
51-
console.log("Order created succesfully", data);
51+
console.log("Order created successfully", data);
5252
return {
5353
body: JSON.stringify({
54-
details: `Order ${data.id} created succesfully on lune`,
54+
details: `Order ${data.id} created successfully on lune`,
5555
ok: true,
5656
}),
5757
statusCode: 200,

0 commit comments

Comments
 (0)