import './interceptors' import { AxiosRequestConfig, AxiosResponse } from 'axios' import _get from 'lodash/get' import { customFieldsDataAdapter } from '../adapters' import { GetNetverifyUrlResponseData, UpdateVerificationStatusResponseData, VerificationStatusResponseData, } from '../types/verification' import { getQueryVariable, isBrowser } from '../utils' import { publicRequest } from './publicRequest' export { authorize, getProfileData, signUp, register, logout, checkEmailExists } from './auth' export { setAxiosHeader, setBaseUrl } from './publicRequest' export { getOrders, getOrderDetails } from './orders' export { addToCart, getCart } from './cart' export { postOnCheckout } from './checkout' export { getEvent, getTickets, getCountries, getStates, addToWaitingList, sendRSVPInfo, postReferralVisits, validatePhoneNumber, } from './common' export { getPaymentData, getConditions, handlePaymentSuccess, handleFreeSuccess, getConfirmationData, } from './payment' export { resaleTicket, removeFromResale, processTicket, declineInvitation, } from './resale' export { issueTicket, getDelegationTickets } from './guestTicketDelegation' export const setCustomHeader = (response: any) => { const guestHeaderResponseValue = _get(response, 'headers.authorization-guest') const guestHeaderExistingValue = _get(response, 'config.headers[Authorization-Guest]') const guestHeader = guestHeaderResponseValue || guestHeaderExistingValue if (guestHeader) { if (isBrowser) { window.localStorage.setItem('auth_guest_token', guestHeader) publicRequest.setGuestToken(guestHeader) } } } export const handlePaymentData = (orderHash: string, data: any) => { const res = publicRequest .post(`v1/order/${orderHash}/pay`, { data: { attributes: { 'stripe-source': data } }, }) .catch(error => { throw error }) return res } export const createPaymentPlan = (orderHash: string, stripePaymentMethodId: string) => { const res = publicRequest .post( `v1/order/${orderHash}/payment_plan/create`, { stripe_payment_method_id: stripePaymentMethodId, }, { headers: { 'Referer-Url': isBrowser ? document.referrer : '', }, } ) .catch(error => { throw error }) return res } // forgot password export const forgotPassword = (email: string) => publicRequest.post(`/auth/restore-password`, { email }) // reset password interface IResetPasswordData { token: string; password: string; confirmPassword: string; } export const resetPassword = (data: IResetPasswordData) => publicRequest.post(`/auth/reset-password`, data) export const getAddons = async (eventId: string) => { const result = await publicRequest.get(`/v1/event/${eventId}/add-ons`) const addons = _get(result, 'data.data.attributes', []) return addons } export const selectAddons = (data: any) => { publicRequest.post(`v1/on-checkout`, data) } export interface AttributesConfig { has_add_on: boolean; names_required: boolean; phone_required: boolean; minimum_age?: any; age_required: boolean; hide_phone_field: boolean; event_id: string; free_ticket: boolean; collect_mandatory_wallet_address: boolean; collect_optional_wallet_address: boolean; collect_mandatory_company: boolean; collect_optional_company: boolean; collect_mandatory_job_title: boolean; collect_optional_job_title: boolean; collect_mandatory_business_category: boolean; collect_optional_business_category: boolean; collect_mandatory_instagram: boolean; collect_optional_instagram: boolean; skip_billing_page: boolean; addon_max_quantity_groups: number | null; cart: ICart[]; } export interface ConfigsData { attributes: AttributesConfig; relationships: any[]; type: string; } export interface ResponseConfigs { data: ConfigsData; success: boolean; error: boolean; message: string; status: number; } export const getCheckoutPageConfigs = async (): Promise => { const response = await publicRequest.get(`v1/checkout-configs`) return response.data } export const getCustomFields = async (eventId: string) => { const response = await publicRequest.get(`/v1/event/${eventId}/custom_fields`) const customFields = _get(response, 'data.data.attributes', []) const adaptedResponse = customFieldsDataAdapter(customFields) return adaptedResponse } export const updateOrderCustomFields = async ( eventId: string, orderId: string, customFieldsData: Record ) => { const response = await publicRequest.put(`v1/event/${eventId}/order-data-capture`, { data: { attributes: { order_id: orderId, data_capture: customFieldsData, }, }, }) return response } export const updateTicketHoldersCustomFields = async ( eventId: string, customFieldsData: Record, ticketHash: string ) => { const response = await publicRequest.put(`v1/event/${eventId}/ticket-data-capture`, { data: { attributes: { ticket_hash: ticketHash, ticket_data_capture: { [ticketHash]: customFieldsData, }, }, }, }) return response } export const confirmPreRegistration = async ( eventId: string | number, data: IConfirmPreRegistrationRequestData ) => { const response = await publicRequest.post( `v1/event/${eventId}/pre-registration/confirm`, { data: { attributes: data, }, } ) return response.data } // seat map <--start--> // const makeId = (length = 20) => { // let result = '' // const characters = // 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' // const charactersLength = characters.length // for (let i = 0; i < length; i++) { // result += characters.charAt(Math.floor(Math.random() * charactersLength)) // } // return result // } export const getSeatMapData = async ( eventId: string | number ): Promise => { localStorage.setItem('tierId', '') const reservedSeatsHash = getQueryVariable('reserved_seats_hash') const params = {} as any if (reservedSeatsHash) { params.reserved_seats_hash = reservedSeatsHash } const response: AxiosResponse = await publicRequest.get(`v1/event/${eventId}/seat-map-data`, { params }) return response.data } export const getSeatMapStatuses = async ( eventId: string | number ): Promise => { const response = await publicRequest.get(`v1/event/${eventId}/seats/status`) return response.data } export const reserveSeat = async ( eventId: string | number, tierId: string, seatId: string ) => { const response = await publicRequest.post(`v1/event/${eventId}/seats/reserve`, { data: { tierId, seatId, ttl: 10, }, }) return response.data } export const removeSeatReserve = async ( eventId: string | number, tierId: string, seatIds: string[] ) => { const response = await publicRequest.delete( `v1/event/${eventId}/seats/delete-reserved`, { data: { tierId, seatIds, }, } ) return response.data } // seat map <--end--> export function getPixelScript(id: string | number, pageOptions: any) { const response = publicRequest.get(`v1/event/${id}/track`, { params: { page_url: pageOptions.pageUrl, page: pageOptions.page, order_hash: pageOptions.orderHash, }, }) return response } // ID Verification export const getNetverifyUrl = async (): Promise => { const response: AxiosResponse = await publicRequest.get('v1/authenticate/verify') return response.data } export const checkVerificationStatus = async (): Promise<{ data: VerificationStatusResponseData; }> => { const response: AxiosResponse< { data: VerificationStatusResponseData }, AxiosRequestConfig > = await publicRequest.get('v1/authenticate/get-verification-info') return response.data } export const updateVerificationStatus = async (): Promise<{ data: UpdateVerificationStatusResponseData; }> => { const response: AxiosResponse< { data: UpdateVerificationStatusResponseData }, AxiosRequestConfig > = await publicRequest.patch('v1/authenticate/verify', { data: { attributes: { verification: { verificationStatus: 'PENDING', }, }, }, }) return response.data } export const checkCustomerOrder = async (orderHash: string): Promise => { const response: AxiosResponse = await publicRequest.get( `v1/order/${orderHash}/verify-customer-order` ) return response.data } export const refreshSeatReservation = async (eventId: string, orderId: string) => { const response: AxiosResponse = await publicRequest.patch( `event/${eventId}/reservation/refresh/`, { order_id: orderId, } ) return response }