From 00352f4a0d4770b74095cb0394e96ec2c59e74b4 Mon Sep 17 00:00:00 2001 From: "Glenn R. Martin" Date: Tue, 2 Apr 2024 11:48:26 -0400 Subject: [PATCH] feat: add RECEIPT_URL and ORDER_HISTORY_URL env vars (#379) * feat: Unified Order History for Ecommerce and Commercetools (#370) * feat: Unified order history * fix: number formatting issues for order history table We now mostly trust the server and if its a pure decimal number, we assume its USD (this is to support legacy system) * fix: npx update-browserslist-db@latest --- Author: Glenn R. Martin Date: Wed Feb 7 05:30:57 2024 -0500 On branch 2u/replatform-to-master You are currently cherry-picking commit bb939ff. Changes to be committed: modified: .env.development modified: .env.test modified: src/order-history/OrderHistoryPage.jsx modified: src/order-history/service.js * feat: Unified Order History Receipt URL (#371) * feat: Unified Order History Receipt URL SONIC-279 * fix: Update .env.development trailing slash is what nginx appends to URLs during routing to the appropriate service. If it is not present, no endpoint would match Co-authored-by: Shafqat Farhan --------- Co-authored-by: Shafqat Farhan * feat: Uniform order history for CC's Unified Order History as well as Legacy (#377) * feat: Optionally triggered Legacy vs Unified order history * fix: URL Pathing to enable OSS to function a bit simpler with a better fallback, based on Shafqat's feedback --------- Co-authored-by: Shafqat Farhan --- .env | 1 + .env.development | 3 +- .env.test | 3 +- src/order-history/OrderHistoryPage.jsx | 15 ++++++++- src/order-history/service.js | 44 ++++---------------------- 5 files changed, 25 insertions(+), 41 deletions(-) diff --git a/.env b/.env index 5b69087e..9b54350b 100644 --- a/.env +++ b/.env @@ -17,6 +17,7 @@ SITE_NAME='' MARKETING_SITE_BASE_URL='' SUPPORT_URL='' ORDER_HISTORY_URL='' +RECEIPT_URL='' LOGO_URL='' LOGO_TRADEMARK_URL='' LOGO_WHITE_URL='' diff --git a/.env.development b/.env.development index ca83045f..6fd56a05 100644 --- a/.env.development +++ b/.env.development @@ -17,7 +17,8 @@ LANGUAGE_PREFERENCE_COOKIE_NAME=openedx-language-preference SITE_NAME=localhost MARKETING_SITE_BASE_URL=http://localhost:18000 SUPPORT_URL=http://localhost:18000/support -ORDER_HISTORY_URL=http://localhost:1996/orders +ORDER_HISTORY_URL='' +RECEIPT_URL='' LOGO_URL=https://edx-cdn.org/v3/default/logo.svg LOGO_TRADEMARK_URL=https://edx-cdn.org/v3/default/logo-trademark.svg LOGO_WHITE_URL=https://edx-cdn.org/v3/default/logo-white.svg diff --git a/.env.test b/.env.test index 23e5a9fe..6ca0436b 100644 --- a/.env.test +++ b/.env.test @@ -17,7 +17,8 @@ LANGUAGE_PREFERENCE_COOKIE_NAME=openedx-language-preference SITE_NAME=localhost MARKETING_SITE_BASE_URL=http://localhost:18000 SUPPORT_URL=http://localhost:18000/support -ORDER_HISTORY_URL=https://localhost:1996/orders +ORDER_HISTORY_URL='' +RECEIPT_URL='' LOGO_URL=https://edx-cdn.org/v3/default/logo.svg LOGO_TRADEMARK_URL=https://edx-cdn.org/v3/default/logo-trademark.svg LOGO_WHITE_URL=https://edx-cdn.org/v3/default/logo-white.svg diff --git a/src/order-history/OrderHistoryPage.jsx b/src/order-history/OrderHistoryPage.jsx index 2462c9fd..43a17913 100644 --- a/src/order-history/OrderHistoryPage.jsx +++ b/src/order-history/OrderHistoryPage.jsx @@ -1,7 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; -import { getConfig } from '@edx/frontend-platform'; +import { getConfig, mergeConfig } from '@edx/frontend-platform'; import { injectIntl, intlShape, @@ -19,6 +19,19 @@ import messages from './OrderHistoryPage.messages'; import { fetchOrders } from './actions'; import { pageSelector } from './selectors'; +/** + * TEMPORARY + * + * Until we add the following keys in frontend-platform, + * use mergeConfig to join it with the rest of the config items + * (so we don't need to get it separately from process.env). + * After we add the keys to frontend-platform, this mergeConfig can go away + */ +mergeConfig({ + ORDER_HISTORY_URL: process.env.ORDER_HISTORY_URL, + RECEIPT_URL: process.env.RECEIPT_URL, +}); + class OrderHistoryPage extends React.Component { constructor(props) { super(props); diff --git a/src/order-history/service.js b/src/order-history/service.js index fc71f88c..b2482b9b 100644 --- a/src/order-history/service.js +++ b/src/order-history/service.js @@ -1,24 +1,20 @@ -/* eslint-disable no-console */ -// NOTE: console logs are intentionally added for REV-2577 - import { getAuthenticatedHttpClient, getAuthenticatedUser } from '@edx/frontend-platform/auth'; import { getConfig } from '@edx/frontend-platform'; -const { ECOMMERCE_BASE_URL } = getConfig(); +const { ORDER_HISTORY_URL, RECEIPT_URL, ECOMMERCE_BASE_URL } = getConfig(); const ECOMMERCE_API_BASE_URL = `${ECOMMERCE_BASE_URL}/api/v2`; -const ECOMMERCE_RECEIPT_BASE_URL = `${ECOMMERCE_BASE_URL}/checkout/receipt/`; +const ECOMMERCE_RECEIPT_BASE_URL = RECEIPT_URL + ? `${RECEIPT_URL}` : `${ECOMMERCE_BASE_URL}/checkout/receipt/`; +const ECOMMERCE_ORDERS_URL = ORDER_HISTORY_URL + ? `${ORDER_HISTORY_URL}` : `${ECOMMERCE_API_BASE_URL}/orders/`; // eslint-disable-next-line import/prefer-default-export export async function getOrders(page = 1, pageSize = 20) { const httpClient = getAuthenticatedHttpClient(); const { username } = getAuthenticatedUser(); - const { COMMERCE_COORDINATOR_BASE_URL } = getConfig(); - const orderFetchingUrl = `${COMMERCE_COORDINATOR_BASE_URL}/orders/order_history/`; - // [START] TEMPORARY CODE for rollout testing/confirmation=========== - // Call ecommerce for order info including waffle flag - let { data } = await httpClient.get(`${ECOMMERCE_API_BASE_URL}/orders/`, { + const { data } = await httpClient.get(`${ECOMMERCE_ORDERS_URL}`, { params: { username, page, @@ -26,34 +22,6 @@ export async function getOrders(page = 1, pageSize = 20) { }, }); - let callCC = false; - if (data.count > 0) { - callCC = data.results[0].enable_hoist_order_history; - } - - if (callCC) { - // REV-2577: enable_hoist_order_history flag is on, about to call commerce-coordinator - const newData = await httpClient.get(orderFetchingUrl, { - params: { - username, - page, - page_size: pageSize, - }, - }); - data = newData.data; - } - // [END] TEMPORARY CODE for rollout testing/confirmation=========== - - // @TODO: after we've confirmed the above works in prod, we can replace with this: - // let { data } = await httpClient.get(orderFetchingUrl, { - // params: { - // username, - // page, - // page_size: pageSize, - // }, - // }); - // data = newData.data; - const transformedResults = data.results.map(({ total_excl_tax, // eslint-disable-line camelcase lines,