|
1 | 1 | import { getAuthenticatedHttpClient, getAuthenticatedUser } from '@edx/frontend-platform/auth'; |
2 | | -import { getConfig } from '@edx/frontend-platform'; |
| 2 | +import { getConfig, initialize, mergeConfig } from '@edx/frontend-platform'; |
3 | 3 |
|
4 | 4 | const { ECOMMERCE_BASE_URL } = getConfig(); |
| 5 | + |
| 6 | +// Temporary: until we add COMMERCE_COORDINATOR_BASE_URL in frontend-platform, use mergeConfig to join it |
| 7 | +// with the rest of the config items (so we don't need to get it separately from process.env). After we add |
| 8 | +// it to frontend-platform, we'll be able to set it like ECOMMERCE_BASE_URL above, and block below can go away. |
| 9 | +initialize({ |
| 10 | + handlers: { |
| 11 | + config: () => { |
| 12 | + mergeConfig({ |
| 13 | + COMMERCE_COORDINATOR_BASE_URL: process.env.COMMERCE_COORDINATOR_BASE_URL || null, |
| 14 | + }); |
| 15 | + }, |
| 16 | + }, |
| 17 | +}); |
| 18 | + |
5 | 19 | const ECOMMERCE_API_BASE_URL = `${ECOMMERCE_BASE_URL}/api/v2`; |
6 | 20 | const ECOMMERCE_RECEIPT_BASE_URL = `${ECOMMERCE_BASE_URL}/checkout/receipt/`; |
7 | 21 |
|
8 | 22 | // eslint-disable-next-line import/prefer-default-export |
9 | 23 | export async function getOrders(page = 1, pageSize = 20) { |
10 | 24 | const httpClient = getAuthenticatedHttpClient(); |
11 | 25 | const { username } = getAuthenticatedUser(); |
| 26 | + const { COMMERCE_COORDINATOR_BASE_URL } = getConfig(); |
12 | 27 |
|
13 | | - const { data } = await httpClient.get(`${ECOMMERCE_API_BASE_URL}/orders/`, { |
| 28 | + // @@TODO: replace with real waffle when that's available |
| 29 | + const callEcommerce = true; // <- false makes it call commerce-coordinator |
| 30 | + let orderFetchingUrl = null; |
| 31 | + if (callEcommerce) { |
| 32 | + orderFetchingUrl = `${ECOMMERCE_API_BASE_URL}/orders/`; |
| 33 | + } else { |
| 34 | + orderFetchingUrl = `${COMMERCE_COORDINATOR_BASE_URL}/orders/ecommerce/`; |
| 35 | + } |
| 36 | + |
| 37 | + const { data } = await httpClient.get(orderFetchingUrl, { |
14 | 38 | params: { |
15 | 39 | username, |
16 | 40 | page, |
17 | 41 | page_size: pageSize, |
18 | 42 | }, |
19 | 43 | }); |
20 | 44 |
|
| 45 | + console.log('DKTEMP: orderFetchingUrl', orderFetchingUrl); |
| 46 | + console.log('DKTEMP: data service.js', data); |
| 47 | + |
21 | 48 | const transformedResults = data.results.map(({ |
22 | 49 | total_excl_tax, // eslint-disable-line camelcase |
23 | 50 | lines, |
|
0 commit comments