Skip to content

Commit

Permalink
feat: add RECEIPT_URL and ORDER_HISTORY_URL env vars (#379)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
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 <[email protected]>

---------

Co-authored-by: Shafqat Farhan <[email protected]>

* 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 <[email protected]>
  • Loading branch information
grmartin and shafqatfarhan committed Apr 2, 2024
1 parent 210babb commit 00352f4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 41 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -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=''
Expand Down
3 changes: 2 additions & 1 deletion .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion src/order-history/OrderHistoryPage.jsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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);
Expand Down
44 changes: 6 additions & 38 deletions src/order-history/service.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,27 @@
/* 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,
page_size: pageSize,
},
});

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,
Expand Down

0 comments on commit 00352f4

Please sign in to comment.