feat: added a generic creditPurchase Url logic (#675)

Co-authored-by: Muhammad Noyan  Aziz <noyan.aziz@A006-01474.local>
This commit is contained in:
Muhammad Noyan Aziz
2025-06-30 19:35:32 +05:00
committed by GitHub
parent 05a08101a2
commit 90aa652ca6
4 changed files with 15 additions and 3 deletions

View File

@@ -24,6 +24,7 @@ module.exports = {
BASE_URL: 'localhost:1996',
LMS_BASE_URL: 'http://localhost:18000',
ECOMMERCE_BASE_URL: 'http://localhost:18130',
CREDIT_PURCHASE_URL: 'http://localhost:8140',
LOGIN_URL: 'http://localhost:18000/login',
LOGOUT_URL: 'http://localhost:18000/logout',
LOGO_URL: 'https://edx-cdn.org/v3/default/logo.svg',

View File

@@ -2,6 +2,7 @@ const configuration = {
// BASE_URL: process.env.BASE_URL,
LMS_BASE_URL: process.env.LMS_BASE_URL,
ECOMMERCE_BASE_URL: process.env.ECOMMERCE_BASE_URL,
CREDIT_PURCHASE_URL: process.env.CREDIT_PURCHASE_URL,
// LOGIN_URL: process.env.LOGIN_URL,
// LOGOUT_URL: process.env.LOGOUT_URL,
// CSRF_TOKEN_API_PATH: process.env.CSRF_TOKEN_API_PATH,

View File

@@ -2,8 +2,6 @@ import { StrictDict } from 'utils';
import { getConfig } from '@edx/frontend-platform';
export const getEcommerceUrl = () => getConfig().ECOMMERCE_BASE_URL;
const getBaseUrl = () => getConfig().LMS_BASE_URL;
export const getApiUrl = () => (`${getConfig().LMS_BASE_URL}/api`);
@@ -24,7 +22,12 @@ export const learningMfeUrl = (url) => updateUrl(getConfig().LEARNING_BASE_URL,
// static view url
const programsUrl = () => baseAppUrl('/dashboard/programs');
export const creditPurchaseUrl = (courseId) => `${getEcommerceUrl()}/credit/checkout/${courseId}/`;
export const creditPurchaseUrl = (courseId) => {
const config = getConfig();
return config.CREDIT_PURCHASE_URL
? `${config.CREDIT_PURCHASE_URL}/${courseId}/`
: `${config.ECOMMERCE_BASE_URL}/credit/checkout/${courseId}/`;
};
export const creditRequestUrl = (providerId) => `${getApiUrl()}/credit/v1/providers/${providerId}/request/`;
export default StrictDict({

View File

@@ -38,6 +38,13 @@ describe('urls', () => {
const url = urls.creditPurchaseUrl(courseId);
expect(url).toEqual(expect.stringContaining(courseId));
});
it('returns CREDIT_PURCHASE_URL if set, with courseId', () => {
const courseId = 'test-course-id';
const config = getConfig();
config.CREDIT_PURCHASE_URL = 'http://credit-purchase.example.com';
const url = urls.creditPurchaseUrl(courseId);
expect(url).toBe(`http://credit-purchase.example.com/${courseId}/`);
});
});
describe('creditRequestUrl', () => {
it('builds from api url and loads providerId', () => {