Skip to content

Commit 90aa652

Browse files
NoyanAzizMuhammad Noyan  Aziz
andauthored
feat: added a generic creditPurchase Url logic (#675)
Co-authored-by: Muhammad Noyan Aziz <[email protected]>
1 parent 05a0810 commit 90aa652

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

example.env.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module.exports = {
2424
BASE_URL: 'localhost:1996',
2525
LMS_BASE_URL: 'http://localhost:18000',
2626
ECOMMERCE_BASE_URL: 'http://localhost:18130',
27+
CREDIT_PURCHASE_URL: 'http://localhost:8140',
2728
LOGIN_URL: 'http://localhost:18000/login',
2829
LOGOUT_URL: 'http://localhost:18000/logout',
2930
LOGO_URL: 'https://edx-cdn.org/v3/default/logo.svg',

src/config/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const configuration = {
22
// BASE_URL: process.env.BASE_URL,
33
LMS_BASE_URL: process.env.LMS_BASE_URL,
44
ECOMMERCE_BASE_URL: process.env.ECOMMERCE_BASE_URL,
5+
CREDIT_PURCHASE_URL: process.env.CREDIT_PURCHASE_URL,
56
// LOGIN_URL: process.env.LOGIN_URL,
67
// LOGOUT_URL: process.env.LOGOUT_URL,
78
// CSRF_TOKEN_API_PATH: process.env.CSRF_TOKEN_API_PATH,

src/data/services/lms/urls.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { StrictDict } from 'utils';
22

33
import { getConfig } from '@edx/frontend-platform';
44

5-
export const getEcommerceUrl = () => getConfig().ECOMMERCE_BASE_URL;
6-
75
const getBaseUrl = () => getConfig().LMS_BASE_URL;
86

97
export const getApiUrl = () => (`${getConfig().LMS_BASE_URL}/api`);
@@ -24,7 +22,12 @@ export const learningMfeUrl = (url) => updateUrl(getConfig().LEARNING_BASE_URL,
2422
// static view url
2523
const programsUrl = () => baseAppUrl('/dashboard/programs');
2624

27-
export const creditPurchaseUrl = (courseId) => `${getEcommerceUrl()}/credit/checkout/${courseId}/`;
25+
export const creditPurchaseUrl = (courseId) => {
26+
const config = getConfig();
27+
return config.CREDIT_PURCHASE_URL
28+
? `${config.CREDIT_PURCHASE_URL}/${courseId}/`
29+
: `${config.ECOMMERCE_BASE_URL}/credit/checkout/${courseId}/`;
30+
};
2831
export const creditRequestUrl = (providerId) => `${getApiUrl()}/credit/v1/providers/${providerId}/request/`;
2932

3033
export default StrictDict({

src/data/services/lms/urls.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ describe('urls', () => {
3838
const url = urls.creditPurchaseUrl(courseId);
3939
expect(url).toEqual(expect.stringContaining(courseId));
4040
});
41+
it('returns CREDIT_PURCHASE_URL if set, with courseId', () => {
42+
const courseId = 'test-course-id';
43+
const config = getConfig();
44+
config.CREDIT_PURCHASE_URL = 'http://credit-purchase.example.com';
45+
const url = urls.creditPurchaseUrl(courseId);
46+
expect(url).toBe(`http://credit-purchase.example.com/${courseId}/`);
47+
});
4148
});
4249
describe('creditRequestUrl', () => {
4350
it('builds from api url and loads providerId', () => {

0 commit comments

Comments
 (0)