import{n as e}from"./chunk-B3pr0VN8.js";import{r as t,x as n}from"./authSession-CrP9lMPq.js";import{r}from"./norm-CeclA1Tu.js";var i=e({billingClosePay:()=>_,billingCreateOrder:()=>h,billingMe:()=>p,billingOrders:()=>m,billingPromoMe:()=>y,billingQueryPay:()=>v,billingStartPay:()=>g,getApiOrigin:()=>s,getBillingApiConfig:()=>b}),a=`https://api2.bysjob.com`,o=()=>{let e=String(globalThis?.location?.protocol||``);return e===`chrome-extension:`||e===`moz-extension:`||e===`safari-extension:`},s=()=>{try{return`https://api2.bysjob.com`.replace(/\/+$/g,``)}catch{}if(!o()){let e=String(globalThis?.location?.origin||``).replace(/\/+$/g,``);if(e.includes(`localhost`)||e.includes(`127.0.0.1`))return e}return a},c=e=>`${s()}/api/billing${e.startsWith(`/`)?e:`/${e}`}`,l={auth_required:`请先登录后再试`,unauthorized:`请先登录后再试`,invalid_session:`请先登录后再试`,session_expired:`登录已过期，请重新登录`,order_not_found:`未找到支付订单，请重新发起充值`,missing_order_id:`缺少订单信息，请重新发起充值`,not_configured:`支付服务暂未配置完成，请稍后再试`,alipay_not_configured:`支付服务暂未配置完成，请稍后再试`,wechatpay_not_configured:`支付服务暂未配置完成，请稍后再试`,invalid_custom_amount:`自定义充值金额过低`,invalid_package:`充值套餐不可用`,invalid_plan:`订阅套餐不可用`,subscription_not_launched:`会员订阅暂未开放，请先使用积分充值。`,invalid_plugin_sku:`插件商品不可用`,invalid_resource_pack_sku:`资源包不可用`,promo_already_claimed:`该账号已开通618体验Token，无需重复支付。请返回个人中心查看额度。`,promo_rules_not_accepted:`请先勾选「我已知晓」确认618体验Token使用规则，再继续付款。`,account_role_locked:`该手机号已经锁定另一种账号身份，不能切换 618 活动身份。如需同时作为 HR 和求职者参加，请使用不同手机号分别注册。`,promo_identity_mismatch:`当前账号身份与所选 618 活动版本不一致，请切换到对应身份后再付款。`,promo_order_pending:`已有一笔待支付的618体验订单，请继续支付或先关闭订单。`,invalid_order_type:`不支持的订单类型`},u=(e,t,n)=>{let i=r(e?.error).toLowerCase();return i&&l[i]?l[i]:String(e?.message||e?.error||t||n)},d=async()=>{let e=await t(),i=r(e?.accessToken||e?.token);if(!i)throw Error(`请先登录`);let a={"Content-Type":`application/json`};a.Authorization=`Bearer ${i}`,a[`x-auth-token`]=i;try{let e=String(await n()||``).slice(0,64);e&&(a[`x-device-key`]=e)}catch{}return a},f=async(e,t,n)=>{let r=c(e),i=await d(),a=await fetch(r,{method:`POST`,headers:i,body:JSON.stringify(t||{})}),o=await a.text(),s=null;try{s=o?JSON.parse(o):null}catch{}if(!a.ok)throw Error(u(s,o,n));return s||{}},p=(e={})=>f(`/me`,e.promoAudience?{promoAudience:e.promoAudience}:{},`查询账单信息失败`),m=(e=20)=>f(`/orders/list`,{limit:e},`查询订单失败`),h=e=>{let t={orderType:e.orderType};return e.orderType===`subscription`&&(t.planId=r(e.planId)),(e.orderType===`plugin`||e.orderType===`resource_pack`||e.orderType===`promo_trial`)&&(t.sku=r(e.sku)),e.orderType===`points`&&(t.packageId=r(e.packageId),t.amountCents=Math.max(0,Math.floor(Number(e.amountCents||0)||0))),e.orderType===`promo_trial`&&(t.identityRole=r(e.identityRole)||`unknown`,t.companyName=r(e.companyName),t.companyRole=r(e.companyRole),t.hiringScale=r(e.hiringScale),t.acceptedRules=e.acceptedRules===!0),f(`/orders/create`,t,`创建订单失败`)},g=e=>{let t={orderId:r(e.orderId),provider:r(e.provider)||`alipay`};t.provider===`wechat_jsapi`&&(t.provider=`wechat_native`);let n=r(e.currentUrl);return n&&(t.currentUrl=n),e.acceptedRules===!0&&(t.identityRole=r(e.identityRole)||`unknown`,t.companyName=r(e.companyName),t.companyRole=r(e.companyRole),t.hiringScale=r(e.hiringScale),t.acceptedRules=!0),f(`/orders/start_pay`,t,`发起支付失败`)},_=e=>f(`/orders/close_pay`,{orderId:r(e.orderId),provider:r(e.provider)},`关闭订单失败`),v=e=>f(`/orders/query_pay`,{orderId:r(e.orderId)},`查询支付状态失败`),y=(e={})=>f(`/promo/me`,e.promoAudience?{promoAudience:e.promoAudience}:{},`promo query failed`),b=async()=>({url:`${s()}/api/billing`,anonKey:``,clientId:``});export{g as a,v as i,h as n,i as o,p as r,s,_ as t};