This repo covers the 3 major steps to implementing Stripe Checkout in a Phoenix LiveView project.
- Prepare your app to handle a Stripe webhook response
- Triggering a Stripe Checkout
- Managing prices from Stripe using GenServer
I wrote up a brief guide that goes alongside this repo, you can find that here
-
Clone this repo with
git clone https://github.com/mstibbard/stripe_checkout_example.gitandcd stripe_checkout_example -
Rename the
.env.examplefile to.envand populate it with your Stripe keys
export STRIPE_SECRET=secret_here
export STRIPE_WEBHOOK_SIGNING_SECRET=whsec_secret_here
- Within your test Stripe dashboard, create a Stripe product, price, and tax rate. This demo assumes you have a Stripe Price with a lookup_key of
"feature_item"and a tax rate set up for Australia (i.e., country"AU"). If you already have other prices and tax rates set up, instead alter the code onlib/stripe_checkout_example_web/live/page_live.ex.
{:ok, price_id} = StripeCache.get_price_id("put_your_lookup_key_here")
{:ok, tax_id} = StripeCache.get_tax_rate_id("put_your_country_code_here")Note: If you decide NOT to use the StripeCache GenServer, remember to instead hardcode the Stripe price and tax rate IDs on lib/stripe_checkout_example_web/live/page_live.ex. You can refer to the prior commit to see this.
price_id = "price_HARD_CODED_PRICE_HERE"
tax_id = "txr_HARD_CODED_TAX_HERE"-
Run
mix deps.get && mix deps.compile -
Run
mix ecto.setup -
Run
mix phx.serverand visitlocalhost:4000