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