Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: EmbeddedChechout doesn't work for connect account #527

Open
ragnarok22 opened this issue Sep 17, 2024 · 0 comments
Open

[BUG]: EmbeddedChechout doesn't work for connect account #527

ragnarok22 opened this issue Sep 17, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@ragnarok22
Copy link

ragnarok22 commented Sep 17, 2024

What happened?

On the backend I'm able to create a checkout session for a connect account and get the client_secret . This is my code:

const info = {
  ui_mode: 'embedded',
  mode: 'subscription',
  line_items: [
    {
      price: price_id,
      quantity: 1,
    },
  ],
  subscription_data: {
    description: `Host Subscription of amount ${price}`,
    metadata: {
      month,
      subscriptionType: 'Subscription',
      user_id: loggedUser.id,
    },
  },
  return_url: `${DOMAIN}?session_id={CHECKOUT_SESSION_ID}`,
  redirect_on_completion: 'if_required',
};

const session = await stripe.checkout.sessions.create(info, { stripeAccount: host.account_id });

return session.client_secret;

image

I get a client secret and I check that is working using stripe-cli.
Now, in the frontend I get 404 error. This is my code on the frontend:

const getSession = async (params) => {
  const response = await axios.post(
    config.BACKENDADDRESS + 'stripe/create-checkout-session/',
    params
  );
  return response.data.clientSecret;
};

export function StripeFormModal({ isOpen, onClose, host, paymentInfo, onComplete }) {
  const returnUrl = window.location.href;
  const options = { onComplete };

  const fetchClientSecret = useCallback(() => {
    const params = {
      mediaId: paymentInfo?.mediaId,
      messageId: paymentInfo?.messageID,
      month: paymentInfo?.month,
      price: paymentInfo?.price,
      paymentType: paymentInfo.type,
      hostId: host,
      returnUrl,
    };
    return getSession(params);
  }, [paymentInfo, host, returnUrl]);

  options.fetchClientSecret = fetchClientSecret;

  return (
    <Drawer
      variant="persistent"
      anchor="bottom"
      open={isOpen}
      className={`subscription-modal payment-subscription ${isOpen ? 'link-drawer' : ''}`}
    >
      <div style={{ overflowY: 'auto' }}>
        <div className="close-modal-btn" onClick={onClose}>
          <CloseIcon width="12px" height="12px" />
        </div>
        {isOpen && <CheckoutForm options={options} />}
      </div>
    </Drawer>
  );
}

const CheckoutForm = ({ options }) => {
  if (!options) return null;

  return (
    <form id="checkout-modal">
      <EmbeddedCheckoutProvider stripe={stripePromise} options={options}>
        <EmbeddedCheckout />
      </EmbeddedCheckoutProvider>
    </form>
  );
};

And this is what I get.

image
image

Environment

Vivaldi 6.9 on ArchLinux 09-2024

Reproduction

No response

@ragnarok22 ragnarok22 added the bug Something isn't working label Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant