mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-09-09 10:58:16 +00:00
feat: implement Telebirr payment API and types, enhance auth storage with token management
This commit is contained in:
33
apps/portal/src/app/features/payment/api/payment-api.ts
Normal file
33
apps/portal/src/app/features/payment/api/payment-api.ts
Normal 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;
|
||||
10
apps/portal/src/app/features/payment/types/payment.ts
Normal file
10
apps/portal/src/app/features/payment/types/payment.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
export interface TelebirrPayload {
|
||||
orderid: string;
|
||||
}
|
||||
export interface TelebirrCreatePaymentResponse {
|
||||
status: string;
|
||||
paymentUrl: string;
|
||||
}
|
||||
export interface TelebirrResponse {
|
||||
status: string;
|
||||
}
|
||||
@@ -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";
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user