This repository has been archived by the owner on Mar 19, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Printful shipping, tax calculations (#63)
* chore: Bump to react-hook-form@4.x.x * refactor: Use react-hook-form@4.x.x * style: camelCase SVG attributes * refactor: Usen gatsby-plugin-react-svg * refactor: Split out CheckoutForm component Use <FormContext /> * style: Remove unused import * style: Remove unused desctructure * feat: Add CheckoutProvider, CheckoutContext * feat: Allow payment once progressing from shipping form * feat: Add mutation, resolver to calculate shipping rates * refactor: Prefer nested syntax for defaultValues * fix: Correctl destructure first index of array in Printful payload * fix: Import const * fix: Actually return shipping data from Printful * feat: Enable disabled state for <Checkbox /> * feat: Hook up mutation to calculate shipping to form * feat: Add mutation, resolver to calculate tax rates * fix: Better calculate shipping button state * style: Remove unused desctructure * refactor: Use /orders/estimate-cost endpoint to retrieve accurate shipping, TAX totals * feat: Add shipping, tax totals from Printful to context * feat: Update checkout totals to include shipping, taxes * fix: Add note to hidden payment field to calculate shipping before proceeding * feat: Add orderTotal to the checkout context * feat: Use orderTotal when creating order, Stripe intent * refactor: Remove unused Printful datasource functions * refactor: Remove defaultValues * fix: Correct border-color of Textarea
- Loading branch information
Jonathan Steele
committed
Jan 22, 2020
1 parent
1a62618
commit be0e7c1
Showing
24 changed files
with
1,023 additions
and
602 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
functions/graphql/resolvers/mutation/estimateOrderCosts.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const estimateOrderCosts = async (_, { input }, { dataSources }) => { | ||
try { | ||
const { | ||
country: country_code, | ||
state: state_code, | ||
...rest | ||
} = input.shippingAddress; | ||
|
||
const { | ||
costs: { currency, shipping: shippingRate, tax: taxRate, vat: vatRate }, | ||
} = await dataSources.PrintfulAPI.estimateOrderCosts({ | ||
recipient: { | ||
country_code, | ||
state_code, | ||
...rest, | ||
}, | ||
items: input.items.map( | ||
({ quantity, variantId: external_variant_id }) => ({ | ||
external_variant_id, | ||
quantity, | ||
}) | ||
), | ||
}); | ||
|
||
return { currency, shippingRate, taxRate, vatRate }; | ||
} catch (err) { | ||
return err; | ||
} | ||
}; | ||
|
||
module.exports = estimateOrderCosts; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.