Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix api #234

Merged
merged 2 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/modules/AboutShelter/AboutShelter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import EditIcon from '../../images/EditIcon/EditIcon';
import DeleteIcon from '../../images/DeleteIcon/DeleteIcon';
import ShelterOwnerStatistics from '../ShelterOwnerStatistics/ShelterOwnerStatistics';
import petLogo from '../../images/pet.jpg';
import setPayment from './api';
import { setPayment } from './api';

// TODO переделать названия классов (объединить?), не совсем понятно, по какому принципу about-shelter, shelter-info

Expand All @@ -22,9 +22,13 @@ const AboutShelter = () => {
// TODO подключить рероутер на редактирование инфо о приюте (6.2.1.4 в фигме)
// TODO сделать попап при удалении приюта (6.2.1.3 в фигме)

const handleSetPayment = () => {
// let token = localStorage.getItem('access');
setPayment(localStorage.getItem('access'));
const handleSetPayment = async () => {
try {
const paymentConfirmUrl = await setPayment();
window.open(paymentConfirmUrl, '_blank');
} catch (error) {
throw new Error(error.message);
}
};

return (
Expand Down
37 changes: 21 additions & 16 deletions src/modules/AboutShelter/api.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import { baseUrl } from '../../utils/constants';
import { baseUrl, apiHeaders } from '../../utils/constants';

const setPayment = async (token) => {
// Перенаправить на страницу OAuth-сервера ЮKassa
const response = await fetch(`${baseUrl}/v1/payments/get-partner-link/`, {
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
authorization: `Bearer ${token}`,
},
redirect: 'follow'
});

if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
// eslint-disable-next-line
export const setPayment = async (id, amount) => {
try {
if (localStorage.getItem('access')) {
const token = localStorage.getItem('access');
apiHeaders.authorization = `Bearer ${token}`;
}
const response = await fetch(`${baseUrl}/v1/payments/get-partner-link/`, {
method: 'GET',
headers: apiHeaders,
});

if (response.ok) {
const data = await response.json();
delete apiHeaders.authorization;
return data.partner_link;
}
throw new Error('Ошибка при отправке запроса');
} catch (error) {
throw new Error('Ошибка:', error);
}
};
export default setPayment;
Loading