Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Stripe Checkout Needs a Server. My Site Doesn't Have One.

I sell a small software product. I needed a way to take money for it. My website is static Jekyll on GitHub Pages — files and a CDN, nothing else. That combination is more of a problem than it sounds, and the way I found out was instructive. The prompt that didn't apply Stripe offers an AI-assisted setup prompt for adding embedded Checkout. I pasted it in and followed it, and the first thing it…

I sell a small software product. To accept payments, I needed a way to process transactions. My website is static using Jekyll on GitHub Pages, consisting only of files and a CDN. At first glance, this limitation seems problematic, but the experience proved otherwise.

When I attempted to use Stripe's AI-assisted setup for embedded Checkout, the first step required updating my Checkout Session call. However, I didn't have an existing server framework for this call. After verifying, I discovered that there was no package.json, Gemfile, requirements.txt, go.mod, server.js, app.py, .env, Dockerfile, vercel.json, netlify.toml, or wrangler.toml present in the repository.

The only configuration file was _config.yml. This indicates that the prompt's paths were unavailable due to the lack of a server framework.

Creating a Checkout Session requires a Stripe secret key, which must be processed server-side. Since my static site has no code path where a user can't inspect, it is impossible to reference a server-side secret key. Thus, the only way to reference a secret key in a static site is through client-side code, making it publicly accessible. A leaked secret key grants complete control of the Stripe account, including the ability to create charges, issue refunds, change payout destinations, read customer records, and more.

To resolve this issue, I needed to add a server (or a serverless function) to my site. After adding a server, I could then store the secret key securely. With the server in place, I followed the prompt's instructions to add a minimal endpoint to my existing server framework. Once the server was set up, I was able to proceed with the integration.

Alternatively, I could have used Stripe Payment Links, which are just URLs hosted by Stripe. My static site could direct paying customers to these links, which handle the checkout flow without requiring any code or a server. Payment Links are suitable for straightforward self-serve options, but they lack the ability to handle multi-dimensional pricing, such as a base setup fee plus a per-unit rate. For this, I used Stripe Invoices, which also require no code and can be linked to my static site.

In conclusion, deciding on a payment mechanism should be based on the pricing model, as the pricing model can rule out certain mechanisms. It is essential to consider potential limitations before integrating with a tool, especially when using a beta or unfinished API. Lastly, I caution against publishing sensitive information, such as API keys, in a public repository, as it can lead to unintended consequences.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in Tech

The 100 KB photo limit: why application forms ask for it, and how to hit it

Visa applications. Passport photos. A university portal. A job site. A marketplace listing. A government form that has been online since 2009.

  • The 100 KB limit balances upload costs and need for clear, legible prints.
  • Photo Size Reducer Android app compresses photos to meet size limits while preserving originals.

More from Thursday 26 November →