Fix token packages authentication issue - add public endpoint for token packages
This commit is contained in:
parent
e75424aac0
commit
528be6027a
@ -51,6 +51,33 @@ export class PaymentController {
|
|||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get available token packages (public endpoint for purchasing)
|
||||||
|
@Get("/token-packages")
|
||||||
|
@Summary("Get available token packages for purchase")
|
||||||
|
@Description("Returns all active token packages that users can purchase")
|
||||||
|
@Returns(200, Array).Description("List of available token packages")
|
||||||
|
async getTokenPackages() {
|
||||||
|
const connection = await pool.getConnection();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const [rows] = await connection.execute(`
|
||||||
|
SELECT * FROM token_packages
|
||||||
|
WHERE is_active = 1
|
||||||
|
ORDER BY quantity ASC
|
||||||
|
`);
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
packages: Array.isArray(rows) ? rows : []
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error getting token packages:', error);
|
||||||
|
throw new BadRequest("Failed to fetch token packages");
|
||||||
|
} finally {
|
||||||
|
connection.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate token price for a given quantity
|
* Calculate token price for a given quantity
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -35,14 +35,12 @@ export default function CustomTokenCalculator({
|
|||||||
|
|
||||||
const fetchPackages = async () => {
|
const fetchPackages = async () => {
|
||||||
try {
|
try {
|
||||||
const token = localStorage.getItem("token");
|
|
||||||
const response = await axios.get(
|
const response = await axios.get(
|
||||||
`${process.env.NEXT_PUBLIC_API_URL}/rest/admin/token-packages`,
|
`${process.env.NEXT_PUBLIC_API_URL}/rest/payments/token-packages`
|
||||||
{ headers: { Authorization: `Bearer ${token}` } }
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response.data.success) {
|
if (response.data.success) {
|
||||||
setPackages(response.data.packages.filter((pkg: TokenPackage) => pkg.is_active));
|
setPackages(response.data.packages);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Failed to fetch packages:", err);
|
console.error("Failed to fetch packages:", err);
|
||||||
|
|||||||
@ -52,14 +52,12 @@ export default function TokenPurchaseFlow({
|
|||||||
const fetchPackages = async () => {
|
const fetchPackages = async () => {
|
||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const token = localStorage.getItem("token");
|
|
||||||
const response = await axios.get(
|
const response = await axios.get(
|
||||||
`${process.env.NEXT_PUBLIC_API_URL}/rest/admin/token-packages`,
|
`${process.env.NEXT_PUBLIC_API_URL}/rest/payments/token-packages`
|
||||||
{ headers: { Authorization: `Bearer ${token}` } }
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response.data.success) {
|
if (response.data.success) {
|
||||||
setPackages(response.data.packages.filter((pkg: TokenPackage) => pkg.is_active));
|
setPackages(response.data.packages);
|
||||||
}
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
setError(err.response?.data?.message || "Failed to load packages");
|
setError(err.response?.data?.message || "Failed to load packages");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user