feat: implement Telebirr payment API and types, enhance auth storage with token management

This commit is contained in:
Estifo77
2026-07-23 14:32:30 +03:00
parent 7191bc6791
commit 7e2186e758
8 changed files with 142 additions and 34 deletions

View File

@@ -0,0 +1,33 @@
import { baseApi } from "@ema-platform/api";
import {
TelebirrCreatePaymentResponse,
TelebirrPayload,
TelebirrResponse,
} from "../types/payment";
const paymentApi = baseApi.injectEndpoints({
endpoints: (builder) => ({
getPaymentStatusTelebirr: builder.query<TelebirrResponse, void>({
query: (orderId) => `/payments/${orderId}/status`,
providesTags: ["Api"],
}),
getPaymentDetail: builder.query<TelebirrResponse, void>({
query: (paymentId) => `/payments/${paymentId}`,
providesTags: ["Api"],
}),
createPaymentTelebirr: builder.mutation<
TelebirrCreatePaymentResponse,
TelebirrPayload
>({
query: (body) => ({
url: "/payments/telebirr/create",
method: "POST",
body,
}),
}),
}),
});
export const {
useCreatePaymentTelebirrMutation,
useGetPaymentStatusTelebirrQuery,
useGetPaymentDetailQuery,
} = paymentApi;

View File

@@ -0,0 +1,10 @@
export interface TelebirrPayload {
orderid: string;
}
export interface TelebirrCreatePaymentResponse {
status: string;
paymentUrl: string;
}
export interface TelebirrResponse {
status: string;
}

View File

@@ -1,5 +1,6 @@
import { configureStore } from '@reduxjs/toolkit';
import { baseApi, configureTokenRefresh } from '@ema-platform/api';
import { configureStore } from "@reduxjs/toolkit";
import { baseApi, configureTokenRefresh } from "@ema-platform/api";
import { setToken } from "@ema-platform/auth";
import {
authReducer,
signupReducer,
@@ -7,17 +8,22 @@ import {
authStorage,
refreshAccessToken,
logout,
} from '@ema-platform/auth';
import type { AuthUser, CurrentProfile } from '@ema-platform/auth';
} from "@ema-platform/auth";
import type { AuthUser, CurrentProfile } from "@ema-platform/auth";
configureAuthStorage('ema-portal');
configureAuthStorage("ema-portal");
const preloadedAuth = (() => {
const token = authStorage.getToken();
const user = authStorage.getUser<AuthUser>();
const profile = authStorage.getProfile<CurrentProfile>();
if (token && user) {
return { token, user, isAuthenticated: true, currentProfile: profile ?? null };
return {
token,
user,
isAuthenticated: true,
currentProfile: profile ?? null,
};
}
return undefined;
})();
@@ -34,10 +40,17 @@ export const store = configureStore({
});
configureTokenRefresh({
onTokenExpired: refreshAccessToken,
onTokenExpired: async () => {
const token = await refreshAccessToken();
store.dispatch(setToken(token));
return token;
},
onAuthFailure: () => {
store.dispatch(logout());
window.location.href = '/login';
window.location.href = "/login";
},
});