How can I add a go back arrow to Stripe checkout?

dev
7ca5724Merge pull request #521 from useautumn/feat/atmn-nuke-push-server
This post might have stale content, as dev is 29 commits ahead.

How can I add a go back arrow to the Stripe checkout? I'm using the checkout function from useCustomer()

Avatar of Gemini 3 FlashGemini 3 Flashcommented

To add a "go back" arrow to the Stripe checkout when using useCustomer(), you need to pass a cancel_url to Stripe. This is done via the checkoutSessionParams field in the checkout function.

When you provide a cancel_url, Stripe automatically includes a back button (usually in the header or as a "Return to [Business]" link) that redirects the user back to your application if they decide not to complete the purchase.

###Example

import { useCustomer } from "autumn-js/react";

export default function PurchaseButton() {
  const { checkout } = useCustomer();

  const handleCheckout = async () => {
    await checkout({
      productId: "your_product_id",
      successUrl: `${window.location.origin}/success`,
      // Add this to enable the back arrow in Stripe Checkout
      checkoutSessionParams: {
        cancel_url: window.location.href, 
      },
    });
  };

  return (
    <button onClick={handleCheckout}>
      Upgrade Plan
    </button>
  );
}

###Why this works:

  1. The checkout function in autumn-js allows you to pass checkoutSessionParams, which are passed directly to the Stripe API when creating the Checkout Session.
  2. Stripe's Checkout API uses the cancel_url parameter to determine whether to show a back button and where it should point.
  3. In the Autumn server implementation (server/src/internal/customers/add-product/handleCreateCheckout.ts), the checkoutSessionParams are spread into the Stripe session creation call:
    let sessionParams: Stripe.Checkout.SessionCreateParams = {
        // ... other params
        ...(attachParams.checkoutSessionParams || {}),
    };
    

Note: Ensure you use cancel_url (snake_case) inside the checkoutSessionParams object to match what the Stripe API expects.


END OF POST

Log in to add a comment
Gemini 3 Flash
How can I add a go back arrow to Stripe checkout? — useautumn/autumn