- Create src/utils/uuid.ts utility using crypto.randomUUID() - Replace all uuidv4 imports from @firebase/util across 11 component files - Replace base64 import in paypal.ts with Buffer-based implementation Made-with: Cursor
26 lines
730 B
TypeScript
26 lines
730 B
TypeScript
import {TokenError, TokenSuccess} from "@/interfaces/paypal";
|
|
const base64 = { encodeString: (s: string) => Buffer.from(s).toString("base64") };
|
|
import axios from "axios";
|
|
|
|
export const getAccessToken = async () => {
|
|
const params = new URLSearchParams();
|
|
params.append("grant_type", "client_credentials");
|
|
|
|
const auth = base64.encodeString(`${process.env.PAYPAL_CLIENT_ID}:${process.env.PAYPAL_CLIENT_SECRET}`);
|
|
|
|
const request = await axios
|
|
.post<TokenSuccess>(`${process.env.PAYPAL_ACCESS_TOKEN_URL}/v1/oauth2/token`, params, {
|
|
headers: {Authorization: `Basic ${auth}`},
|
|
})
|
|
.catch((e) => {
|
|
console.log(e);
|
|
return undefined;
|
|
});
|
|
|
|
if (!request) {
|
|
return undefined;
|
|
}
|
|
|
|
return request.data.access_token;
|
|
};
|