Untitled

mail@pastecode.io avatar
unknown
typescript
a year ago
2.2 kB
1
Indexable
Never
import api from '@/services/apiServcie';
import { FetchedLogginedUserDataType } from '@/types/global/fetchedLogginedUserData.type';
import { BookType } from '@/types/routes/global/book.type';
import { AxiosResponse } from 'axios';

type AxiosResponseType = {
  data: string | null;
  msg: string;
  errorCode: 0 | 103;
};

export const APIvalidateCartItemsAndGetZarinpalUrlForPayment = async (
  token: string | undefined,
  totalBookPrice: number,
  transportCost: number,
  totalWeight: number,
  fetchedLogginedUserData: FetchedLogginedUserDataType | null,
  booksData:
    | (BookType &
        {
          status: 1 | 2 | 3;
          max_sell: number;
          quantity: number;
          modifyPrice: number;
        }[])
    | null,
): Promise<AxiosResponseType> => {
  const { data }: AxiosResponse<AxiosResponseType> = await api.post(
    '/checkoutsell',
    {
      customerid: `0${fetchedLogginedUserData?.customerid}`,
      city: fetchedLogginedUserData?.city,
      state: fetchedLogginedUserData?.state,
      address: fetchedLogginedUserData?.address,
      postalCode: fetchedLogginedUserData?.postalcode,
      countPack: Number(fetchedLogginedUserData?.postalcode),
      postMethod: fetchedLogginedUserData?.postmethod,
      sendTime: fetchedLogginedUserData?.sendtime,
      sendDay: fetchedLogginedUserData?.sendday,
      bank: fetchedLogginedUserData?.bank,
      accNumber: fetchedLogginedUserData?.accnumber,
      accountholder: fetchedLogginedUserData?.accountholder,
      email: fetchedLogginedUserData?.email,
      discountcode: '',
      sell: '1',
      first_name: fetchedLogginedUserData?.first_name,
      last_name: fetchedLogginedUserData?.last_name,
      total_weight: totalWeight,
      payment_method: 'post',
      total_books_price: totalBookPrice,
      total_dicounts: '',
      post_price: transportCost,
      //final_total_price: totalBookPrice + transportCost, // TODO: uncomment for send final price to api
      final_total_price: 10001,
      books: booksData,
    },
    {
      headers: {
        'Content-Type': 'application/json',
        Authorization: `Bearer ${token}`,
      },
    },
  );
  return data;
};