Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lune-integration): Add Lune integration custom shipping code and… #20

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jesusmpds
Copy link

… transaction webhook for CO2 shipping rate estimates and creating CO2 offset orders in Lune

… transaction weebhook for CO2 shipping rate estimates and creating CO2 offset orders in Lune
@CLAassistant
Copy link

CLAassistant commented Jun 2, 2023

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

8. In the Value field, enter your Lune API key
9. Deploy the site

### Create a new Foxy Weebhok
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a little change "Weebhok -> Webhook"

zoom=applied_taxes,billing_addresses,custom_fields,customer,discounts,items,items:item_category,items:item_options,payments,shipments,attributes
```

Then click on `Update Weebhooks Next`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weebhooks -> Webhooks

const originAddress = "address goes here, city goes here";

// How to add the offset amount to the rates?
// If set to false: Add rates with the CO2 offset estimate ammount included
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ammount->amount


// How to add the offset amount to the rates?
// If set to false: Add rates with the CO2 offset estimate ammount included
// If set to true: Keep regular rates, and duplicate them to add them with the CO2 offset estimate ammount included
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ammount->amount

// How to add the offset amount to the rates?
// If set to false: Add rates with the CO2 offset estimate ammount included
// If set to true: Keep regular rates, and duplicate them to add them with the CO2 offset estimate ammount included
const addOffsetRatesSeparetly = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addOffsetRatesSeparetly->addOffsetRatesSeparately

shippingResultsEmissions.push(shippingEmissions);
}

// Add rates Separetly or Update rates with CO2 Offset amount
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separetly->Separately

Number(price) + Number(quote.estimated_total_cost)
).toFixed(2);

if (addOffsetRatesSeparetly) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addOffsetRatesSeparetly->addOffsetRatesSeparately

(attr) => attr.name === `${ratePrefix}${selectedShippingRateID}`
).value;

const LUNE_API_KEY = config.lune.accessKey;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config.lune.accessKey->config.lune.apiKey

const orderByEstimateIdUrl = "https://api.lune.co/v1/orders/by-estimate";
const response = await fetch(orderByEstimateIdUrl, {
body: JSON.stringify({
estimate_id: "luneEstimateID",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

estimate_id: "luneEstimateID", -> estimate_id: luneEstimateID,

estimate_id: "luneEstimateID",
metadata: {
customer_email: cartDetails.customer_email,
transaction_id: cartDetails.id,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transaction_id: cartDetails.id, -> transaction_id: String(cartDetails.id),

Copy link
Contributor

@rijarobinson rijarobinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for all the individual comments.I tried to submit a branch to your own repo, but that didn't work.

@rijarobinson
Copy link
Contributor

And I guess you'll want to change the file name to index.js as well.

const cartDetails = JSON.parse(requestEvent.body);
const ratePrefix = "rate_id_";
const selectedShippingRateID =
cartDetails["_embeded"]["fx:shipment"].shipping_service_id;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cartDetails["_embeded"]["fx:shipment"].shipping_service_id; -> cartDetails["_embedded"]["fx:shipments"][0].shipping_service_id;

There can be multiple shipments for an order, so here I'm just getting the first one. not sure if we want to update the readme to note this limitation in the example

…ate README, and update shipment service ID varible
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants