Skip to content

Feature: new billing flow #109

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

Closed
wants to merge 41 commits into from

Conversation

steven-fox
Copy link
Collaborator

@steven-fox steven-fox commented Apr 18, 2025

Bypasses Anystack billing.

Before Deploying:

  • Stripe products, prices, and payment links need to be created for each license tier.
  • Stripe must be configured to send webhooks to the /stripe/webhook route for the standard cashier events.
  • An Anystack api key must be generated.
  • A queue must be available for job dispatching.
  • A queue worker must be enabled for job processing.
  • Email sending must be setup & working.
  • Highly recommended to have failed job notifications and/or error notifications in place.
  • Ensure migrations will run with this deployment.
  • The following env vars must be saved to .env:
STRIPE_KEY=
STRIPE_SECRET=
STRIPE_WEBHOOK_SECRET=
STRIPE_MINI_PRICE_ID=
STRIPE_PRO_PRICE_ID=
STRIPE_MAX_PRICE_ID=
STRIPE_MINI_PAYMENT_LINK=
STRIPE_PRO_PAYMENT_LINK=
STRIPE_MAX_PAYMENT_LINK=

ANYSTACK_API_KEY=
ANYSTACK_PRODUCT_ID=
ANYSTACK_MINI_POLICY_ID=
ANYSTACK_PRO_POLICY_ID=
ANYSTACK_MAX_POLICY_ID=

Functionality:

  • A (guest) user will click a payment link button for one of the subscription products on the /mobile eap page.
  • They'll be taken to a Stripe checkout session for that product.
  • Upon payment, Stripe will redirect to /order/{checkout_session_id}. This route shows a view that says "Check your email for a copy of your license key" or, if the license key has been created and present in cache, it will show that to the user.
  • Via a ~typical Cashier setup, we listen for various Stripe events (namely customer.created and customer.subscription.created events) via webhook. We hook into these events to create a user from the Stripe customer record and dispatch a job to send an api request to anystack to create a contact & license for them.
  • Upon creating the license in anystack, the key is stored in cache for retrieval in a web request later and an email notification is sent to the user.

Future Improvements:

  • v1.1 License key email notification template could be styled better to be on-brand.
  • v1.1 Let Hassan clean up/change styling of the order-success page.
  • v1.1 Add Livewire and use a component to poll for license key creation to update the /order/... page.
  • Handle duplicate stripe customer creation
  • Handle subscription changes (cancellations, upgrades/downgrades) and payment method changes
  • Handle duplicate anystack user creation
  • Keep track of users and licenses locally so we can improve the UX in the docs (for example, show their email and license key inline).

/order/{session} when the license key is NOT available
image

/order/{session} when the license key is available
image

license key notification
image

@steven-fox steven-fox changed the title [WIP] Feature: new billing flow Feature: new billing flow Apr 19, 2025
@steven-fox
Copy link
Collaborator Author

@simonhamp I think this is ready to go. Once merged, I'll try to follow up with installing Livewire and polling on the order success page as we've discussed.

I recommend pulling down this branch and configuring your setup locally to both confirm functionality but to also double check everything that the production server & services will need configured before deploying.

@steven-fox
Copy link
Collaborator Author

steven-fox commented Apr 23, 2025

@simonhamp Alrighty. Order success page has been converted to a Livewire page with 2 second polling. Test added for this page.

livewire.polling.mp4

@simonhamp
Copy link
Member

simonhamp commented Apr 29, 2025

  • Add a queue worker for the default queue.
  • Add env keys
  • Confirm migrations will run on deploy
  • Add repo access instructions to order confirmation page & email for Max customers only (i.e. "login into Anystack")
  • Remove "beta" wording - replace with "Early Access"
  • Confirm license keys are UUIDs

@steven-fox
Copy link
Collaborator Author

@simonhamp Added repo access instructions, changed "beta" to "Early Access" (on order-success.blade.php, there are other places in the repo where "beta" is still used...), and confirmed the license keys are UUIDs from anystack.

image
image

@simonhamp
Copy link
Member

I haven't tested this fully but it's looking great!

Please test a real payment (@shanerbaner82) before going to prod. If possible with the webhook firing somewhere so you can see everything working.

SES is going to be used for the emails - don't forget to set the env for this in Forge

Deployment checklist:

  • Test a real payment
  • Set up SES for sending mails

@steven-fox
Copy link
Collaborator Author

@simonhamp @shanerbaner82 FYI: I updated the links and references to Anystack in installation.md now that the v1 docs have been merged to main.

@simonhamp simonhamp mentioned this pull request May 2, 2025
@simonhamp
Copy link
Member

Replaced with #121

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants