Skip to content
This repository was archived by the owner on Nov 4, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ NODE_ENV='production'
BASE_URL=''
LMS_BASE_URL=''
CREDENTIALS_BASE_URL=''
COMMERCE_COORDINATOR_BASE_URL=''
ECOMMERCE_BASE_URL=''
LOGIN_URL=''
LOGOUT_URL=''
Expand Down
1 change: 1 addition & 0 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ NODE_ENV=development
BASE_URL=localhost:1996
LMS_BASE_URL=http://localhost:18000
CREDENTIALS_BASE_URL=http://localhost:18150
COMMERCE_COORDINATOR_BASE_URL=http://localhost:8140
ECOMMERCE_BASE_URL=http://localhost:18130
LOGIN_URL=http://localhost:18000/login
LOGOUT_URL=http://localhost:18000/login
Expand Down
1 change: 1 addition & 0 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ NODE_ENV=development
BASE_URL=localhost:1996
LMS_BASE_URL=http://localhost:18000
CREDENTIALS_BASE_URL=http://localhost:18150
COMMERCE_COORDINATOR_BASE_URL=http://localhost:8140
ECOMMERCE_BASE_URL=http://localhost:18130
LOGIN_URL=http://localhost:18000/login
LOGOUT_URL=http://localhost:18000/login
Expand Down
53 changes: 51 additions & 2 deletions src/order-history/service.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,72 @@
import { getAuthenticatedHttpClient, getAuthenticatedUser } from '@edx/frontend-platform/auth';
import { getConfig } from '@edx/frontend-platform';
import { getConfig, initialize, mergeConfig } from '@edx/frontend-platform';

const { ECOMMERCE_BASE_URL } = getConfig();

// Temporary: until we add COMMERCE_COORDINATOR_BASE_URL 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
// it to frontend-platform, we'll be able to set it like ECOMMERCE_BASE_URL above, and block below can go away.
initialize({
handlers: {
config: () => {
mergeConfig({
COMMERCE_COORDINATOR_BASE_URL: process.env.COMMERCE_COORDINATOR_BASE_URL || null,
});
},
},
});

const ECOMMERCE_API_BASE_URL = `${ECOMMERCE_BASE_URL}/api/v2`;
const ECOMMERCE_RECEIPT_BASE_URL = `${ECOMMERCE_BASE_URL}/checkout/receipt/`;

// 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/`;

const { data } = await httpClient.get(`${ECOMMERCE_API_BASE_URL}/orders/`, {
// [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/`, {
params: {
username,
page,
page_size: pageSize,
},
});

let callCC = false;
if (data.count > 0) {
callCC = data.results[0].enable_hoist_order_history;
}
console.log('DKTEMP: enable_hoist_order_history flag is: ', callCC);

if (callCC) {
console.log('DKTEMP: about to call commerce-coordinator');
const newData = await httpClient.get(orderFetchingUrl, {
params: {
username,
page,
page_size: pageSize,
},
});
data = newData.data;
Copy link
Contributor

Choose a reason for hiding this comment

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

Here data is replaced with the newData from commerce-coordinator, but then both data and newData are logged - aren't they the same thing at this point in the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes these will get the same json results, the only difference being that one will go through commerce-coordinator. I do the replacement because even though these results aren't actually different, when the waffle flag is enabled we want the order history page to show the data coming back from commerce-coordinator. (As opposed to just calling the commerce-coordinator in the background but not actually showing the data we get from it).

console.log('DKTEMP: CC data.data.results', newData.data.results);
console.log('DKTEMP: ecommerce data.results', data.results);
}
Copy link
Contributor Author

@dianekaplan dianekaplan May 9, 2022

Choose a reason for hiding this comment

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

This big 'TEMPORARY CODE for rollout testing/confirmation' block is for use to sanity check using the commerce-coordinator endpoint for order history. Therefore I've included some debugging statements so our production test can be explicit about where the data came from. Is there a better way to do this, or are these statements okay for this temporary case?

Copy link
Contributor

Choose a reason for hiding this comment

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

As long as we're not logging any PII, and assuming we'll be logged-in in our accounts anyways (so the information will be ours), we should be good!

I would change DKTEMP to something theseus/commerce-coordinator related though to be more specific, in case the temporary code is not as temporary as we imagined?

Copy link
Contributor Author

@dianekaplan dianekaplan May 10, 2022

Choose a reason for hiding this comment

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

Good call- updated the logging prefix to 'REV-2577 LOG' (that'll be the testing ticket). There is PII in this data (name and address), but console.log should only make this appear in the user's own browser, as opposed to something like Splunk which shows server-side logging that's put there with a different/specific Logger.

// [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