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;
|
||||
}
|
||||
|
||||
// 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
|
||||
*/
|
||||
|
||||
@ -35,14 +35,12 @@ export default function CustomTokenCalculator({
|
||||
|
||||
const fetchPackages = async () => {
|
||||
try {
|
||||
const token = localStorage.getItem("token");
|
||||
const response = await axios.get(
|
||||
`${process.env.NEXT_PUBLIC_API_URL}/rest/admin/token-packages`,
|
||||
{ headers: { Authorization: `Bearer ${token}` } }
|
||||
`${process.env.NEXT_PUBLIC_API_URL}/rest/payments/token-packages`
|
||||
);
|
||||
|
||||
if (response.data.success) {
|
||||
setPackages(response.data.packages.filter((pkg: TokenPackage) => pkg.is_active));
|
||||
setPackages(response.data.packages);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Failed to fetch packages:", err);
|
||||
|
||||
@ -52,14 +52,12 @@ export default function TokenPurchaseFlow({
|
||||
const fetchPackages = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const token = localStorage.getItem("token");
|
||||
const response = await axios.get(
|
||||
`${process.env.NEXT_PUBLIC_API_URL}/rest/admin/token-packages`,
|
||||
{ headers: { Authorization: `Bearer ${token}` } }
|
||||
`${process.env.NEXT_PUBLIC_API_URL}/rest/payments/token-packages`
|
||||
);
|
||||
|
||||
if (response.data.success) {
|
||||
setPackages(response.data.packages.filter((pkg: TokenPackage) => pkg.is_active));
|
||||
setPackages(response.data.packages);
|
||||
}
|
||||
} catch (err: any) {
|
||||
setError(err.response?.data?.message || "Failed to load packages");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user