Added packages for students to be able to purchase

This commit is contained in:
Tiago Ribeiro
2023-11-26 10:08:57 +00:00
parent c312260721
commit 7e91a989b3
16 changed files with 552 additions and 35 deletions

25
src/utils/paypal.ts Normal file
View File

@@ -0,0 +1,25 @@
import {TokenError, TokenSuccess} from "@/interfaces/paypal";
import {base64} from "@firebase/util";
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;
};