-
Notifications
You must be signed in to change notification settings - Fork 29
REV-2575: update order status page to go through commerce-coordinator #181
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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; | ||
| console.log('DKTEMP: CC data.data.results', newData.data.results); | ||
| console.log('DKTEMP: ecommerce data.results', data.results); | ||
| } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here
datais replaced with thenewDatafromcommerce-coordinator, but then bothdataandnewDataare logged - aren't they the same thing at this point in the code?There was a problem hiding this comment.
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).