import axios from "axios"; import { IEventModel, ISellerPartnerData, ITicketModel } from "@nimee/shared-types"; const port = process.env.PAYMENT_PORT; const basePath = process.env.IS_LOCAL === "true" ? `http://127.0.0.1:${port}` : "http://payment"; const paymentUrl = `${basePath}/payment`; export class PaymentClient { async getCouponById(params: { accountId: string; eventId: string; couponId: string; jwt: string }) { const { accountId, eventId, couponId, jwt } = params; const response = await axios.get(`${paymentUrl}/coupon/getById/${accountId}/${eventId}/${couponId}`, { headers: { jwt }, }); return response?.data; } async createEventCouponsFromProductionCoupons(params: { accountId: string; eventId: string; jwt: string }) { const { accountId, eventId, jwt } = params; const response = await axios.post( `${paymentUrl}/coupon/create-event-coupons-from-production-coupons/${accountId}/${eventId}`, {}, { headers: { jwt }, } ); return response?.data; } async generateSale(params: { accountId: string; eventId: string; jwt: string; token: string }) { const { accountId, eventId, jwt, token } = params; const authorizationPayment = "authorization-payment"; const headers = { [authorizationPayment]: token, jwt }; const response = await axios.post( `${paymentUrl}/generate-sale/${accountId}/${eventId}`, {}, { headers: headers, timeout: 90000, // 90 seconds timeout for payment processing (increased from default) } ); return response?.data; } async createSellerPartner(params: { sellerData: ISellerPartnerData; accountId: string; jwt: string }) { const { sellerData, jwt, accountId } = params; const response = await axios.post(`${paymentUrl}/partner/create/${accountId}`, sellerData, { headers: { jwt } }); return response?.data; } async getPrice(params: { accountId: string; event: IEventModel; ticketsIdsChosen: string[]; couponId?: string; shouldIncCouponUsage?: boolean; endUserSeasonTicketId?: string; timeSlotId?: string; voucherRedemptionIds?: string[]; }) { const { accountId, event, ticketsIdsChosen, couponId, shouldIncCouponUsage, endUserSeasonTicketId, timeSlotId, voucherRedemptionIds, } = params; const response = await axios.post(`${paymentUrl}/getPrice/${accountId}`, { event, ticketsIdsChosen, couponId, shouldIncCouponUsage, endUserSeasonTicketId, timeSlotId, voucherRedemptionIds, }); return response?.data; } // /payment/seasonTicket/getBySellerIdPublic/${marketplaceId}/${sellerId} async getSeasonTicketBySellerIdPublic(params: { marketplaceId: string; sellerId: string }) { const { marketplaceId, sellerId } = params; if (!marketplaceId || !sellerId) { throw new Error("param_are_missing_in_getSeasonTicketBySellerIdPublic"); } const response = await axios.get(`${paymentUrl}/seasonTicket/getBySellerIdPublic/${marketplaceId}/${sellerId}`); return response?.data; } // Internal: ask payment service to recompute isProfileComplete on every family-subscription // row linked to this endUserId. Called fire-and-forget from user service after a profile update. // 5s timeout caps how long an upstream save can hang; the route returns 200 even on internal // failure (with a warning), so callers should ignore the result. async recomputeProfileCompletenessForEndUser(params: { endUserId: string }) { const response = await axios.post( `${paymentUrl}/endUserSeasonTicket/recomputeForEndUser`, { endUserId: params.endUserId }, { timeout: 5000 } ); return response?.data; } // #908 — on-demand Payme fee refresh for one event. Internal-only on the payment side (send // JWT_ADMIN); the caller (user-event) owns the marketplace/tenant authorization. Synchronous: // resolves with the merchant sweep summary. async reconcilePaymeFeesForEvent(params: { eventId: string; jwt: string }) { const { eventId, jwt } = params; const response = await axios.post(`${paymentUrl}/admin/reconcile-payme-fees/event/${eventId}`, {}, { headers: { jwt } }); return response?.data; } }