import { J as n, M as y, I as _, by as h, K as g, P as u, cb as b, bu as k, _ as P, bN as f } from "./index-BBXAtvZr.js";
import { g as w, r as O } from "./Payment-x0BHQwG3.js";
const I = async (o) => {
  const e = n(y), s = e.licenses?.map(
    ({
      contentTokenId: r,
      licenseContractAddress: a,
      licenseType: i
    }) => ({
      contract_address: a,
      content_token_id: +r,
      license_type: +i
    })
  ) || [], t = e.tokens?.map(
    ({
      contractAddress: r,
      tokenId: a,
      amount: i
    }) => ({
      contract_address: r,
      token_id: +a,
      amount: i
    })
  ) || [], c = e.memberships?.map(
    ({ contractAddress: r, membershipTokenId: a }) => ({
      contract_address: r,
      ...a ? { token_id: a } : {}
    })
  ) || [], m = {
    ...o,
    tokens: t,
    memberships: c,
    licenses: s
  }, l = n(_), p = await fetch(l.credenza.evmApiUrl + "/contracts/buy-assets", {
    headers: {
      "Content-Type": "application/json",
      Authorization: `Bearer ${n(h)}`
    },
    method: "POST",
    body: JSON.stringify(m)
  });
  if (!p.ok) throw new Error("Failed to create order");
  const { _id: d } = await p.json();
  return d;
}, C = async (o) => {
  const e = n(_), s = n(y), t = await w(e.credenza.generalApiUrl, o);
  return t.payment_provider_tx && (await O({
    stripeChargeId: t.payment_provider_tx,
    title: s.title,
    subtitle: s.subtitle
  }), g(u.RECEIPT, { stripeChargeId: t.payment_provider_tx })), await b(t.items), t;
}, D = async (o) => {
  const e = n(_), s = n(y), t = n(k), c = await P(), m = t?.email || t?.pending?.email, l = t?.phone || t?.pending?.phone, p = `Passport Payment: (${JSON.stringify({
    ...s.tokens,
    ...s.memberships,
    ...s.licenses,
    userAddress: c,
    chainId: e.chainId,
    email: m,
    phone: l
  })})`, d = f(e.clientId).name, a = {
    card_token: (e.stripe.pk[d] ?? e.stripe.pk.DEFAULT).includes("pk_live") ? o : "tok_visa",
    client: d,
    description: p,
    address: c,
    chain_id: Number(e.chainId),
    currency: "USD"
  }, i = await I(a);
  return await C(i);
};
export {
  D as processPayment
};
//# sourceMappingURL=Stripe.service-Da85d2QQ.js.map
