From 2aaa79ac221e5bffae24c18bbbcfef56c5d2158c Mon Sep 17 00:00:00 2001 From: mark-jia <99465986+mark-jia@users.noreply.github.com> Date: Sat, 28 Oct 2023 16:12:07 +1100 Subject: [PATCH 1/3] Update [bodyJson]webhook.js stripe web hook returned amount data is integer of how many cents, we store in dollars with 4 decimal points in postgres database --- .../src/modules/stripe/api/stripeWebHook/[bodyJson]webhook.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/evershop/src/modules/stripe/api/stripeWebHook/[bodyJson]webhook.js b/packages/evershop/src/modules/stripe/api/stripeWebHook/[bodyJson]webhook.js index 30f0a45e6..d9e5f71ec 100644 --- a/packages/evershop/src/modules/stripe/api/stripeWebHook/[bodyJson]webhook.js +++ b/packages/evershop/src/modules/stripe/api/stripeWebHook/[bodyJson]webhook.js @@ -56,7 +56,7 @@ module.exports = async (request, response, delegate, next) => { // Create payment transaction await insert('payment_transaction') .given({ - amount: paymentIntent.amount, + amount: parseFloat((paymentIntent.amount/100).toFixed(4)), payment_transaction_order_id: order.order_id, transaction_id: paymentIntent.id, transaction_type: 'online', From 0f1dd1fa27c5dc39dffa1c83a95e7116b17d073d Mon Sep 17 00:00:00 2001 From: mark-jia <99465986+mark-jia@users.noreply.github.com> Date: Sat, 28 Oct 2023 17:25:34 +1100 Subject: [PATCH 2/3] Update [bodyJson]webhook.js use zero-decimal-currencies to fix stripe web hook amount inconsistency. For non zero-decimal-currencies, amount is divided by 100 before insert into database, otherwise, original paymentIntent.amount is saved --- .../src/modules/stripe/api/stripeWebHook/[bodyJson]webhook.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/evershop/src/modules/stripe/api/stripeWebHook/[bodyJson]webhook.js b/packages/evershop/src/modules/stripe/api/stripeWebHook/[bodyJson]webhook.js index d9e5f71ec..2e2b03d01 100644 --- a/packages/evershop/src/modules/stripe/api/stripeWebHook/[bodyJson]webhook.js +++ b/packages/evershop/src/modules/stripe/api/stripeWebHook/[bodyJson]webhook.js @@ -14,6 +14,7 @@ const { getConfig } = require('@evershop/evershop/src/lib/util/getConfig'); const { emit } = require('@evershop/evershop/src/lib/event/emitter'); const { debug } = require('@evershop/evershop/src/lib/log/debuger'); const { getSetting } = require('../../../setting/services/setting'); +const { display } = require('zero-decimal-currencies'); // eslint-disable-next-line no-unused-vars module.exports = async (request, response, delegate, next) => { @@ -56,7 +57,7 @@ module.exports = async (request, response, delegate, next) => { // Create payment transaction await insert('payment_transaction') .given({ - amount: parseFloat((paymentIntent.amount/100).toFixed(4)), + amount: parseFloat(display(paymentIntent.amount, paymentIntent.currency)), payment_transaction_order_id: order.order_id, transaction_id: paymentIntent.id, transaction_type: 'online', From 4ac7a026a4c81d58ae0a1bbcad1000fb8ccf0b7a Mon Sep 17 00:00:00 2001 From: ultimate-tester Date: Thu, 2 Nov 2023 15:56:51 +0100 Subject: [PATCH 3/3] Instead of using context, query the store setting for currency --- .../oms/pages/admin/dashboard/Bestcustomers.jsx | 17 ++++++++++++++--- .../oms/pages/admin/dashboard/Bestsellers.jsx | 17 ++++++++++------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/packages/evershop/src/modules/oms/pages/admin/dashboard/Bestcustomers.jsx b/packages/evershop/src/modules/oms/pages/admin/dashboard/Bestcustomers.jsx index a51b75eb4..5e63dc1d4 100644 --- a/packages/evershop/src/modules/oms/pages/admin/dashboard/Bestcustomers.jsx +++ b/packages/evershop/src/modules/oms/pages/admin/dashboard/Bestcustomers.jsx @@ -3,9 +3,8 @@ import React from 'react'; import { useAppState } from '@components/common/context/app'; import { Card } from '@components/admin/cms/Card'; -export default function BestCustomers({ listUrl }) { +export default function BestCustomers({ listUrl, setting }) { const context = useAppState(); - const currency = context.currency || 'USD'; const customers = context.bestCustomers || []; return ( @@ -33,7 +32,7 @@ export default function BestCustomers({ listUrl }) { {customers.map((c, i) => { const grandTotal = new Intl.NumberFormat('en', { style: 'currency', - currency + currency: setting.storeCurrency }).format(c.total); return ( // eslint-disable-next-line react/no-array-index-key @@ -54,5 +53,17 @@ export default function BestCustomers({ listUrl }) { } BestCustomers.propTypes = { + setting: PropTypes.shape({ + storeCurrency: PropTypes.string + }).isRequired, listUrl: PropTypes.string.isRequired }; + +export const query = ` + query Query { + setting { + storeCurrency + } + listUrl: url(routeId: "productGrid") + } +`; \ No newline at end of file diff --git a/packages/evershop/src/modules/oms/pages/admin/dashboard/Bestsellers.jsx b/packages/evershop/src/modules/oms/pages/admin/dashboard/Bestsellers.jsx index 691f164a8..ec844da20 100644 --- a/packages/evershop/src/modules/oms/pages/admin/dashboard/Bestsellers.jsx +++ b/packages/evershop/src/modules/oms/pages/admin/dashboard/Bestsellers.jsx @@ -1,13 +1,10 @@ import PropTypes from 'prop-types'; import React from 'react'; import { toast } from 'react-toastify'; -import { useAppState } from '@components/common/context/app'; import { Card } from '@components/admin/cms/Card'; import './Bestsellers.scss'; -export default function BestSellers({ api, listUrl }) { - const context = useAppState(); - const currency = context.currency || 'USD'; +export default function BestSellers({ api, listUrl, setting }) { const [products, setProducts] = React.useState([]); const [fetching, setFetching] = React.useState(true); @@ -66,9 +63,9 @@ export default function BestSellers({ api, listUrl }) { )} {products.map((p, i) => { - const formatedPrice = new Intl.NumberFormat('en', { + const formattedPrice = new Intl.NumberFormat('en', { style: 'currency', - currency + currency: setting.storeCurrency }).format(p.price); return ( // eslint-disable-next-line react/no-array-index-key @@ -112,7 +109,7 @@ export default function BestSellers({ api, listUrl }) { {p.name} - {formatedPrice} + {formattedPrice} {p.qty} sold ); @@ -126,6 +123,9 @@ export default function BestSellers({ api, listUrl }) { } BestSellers.propTypes = { + setting: PropTypes.shape({ + storeCurrency: PropTypes.string + }).isRequired, api: PropTypes.string.isRequired, listUrl: PropTypes.string.isRequired }; @@ -137,6 +137,9 @@ export const layout = { export const query = ` query Query { + setting { + storeCurrency + } api: url(routeId: "bestsellers") listUrl: url(routeId: "productGrid") }