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

Open
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

steven-fox
Copy link

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

Bypasses Anystack billing.

Todos:

  • Tests
  • Describe .env vars needed
  • Describe stripe config needed
  • Describe anystack config needed

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 customer.subscription.created event.
  • An Anystack api key must be generated.
  • A queue must be available for job dispatching.
  • A queue worker must be enabled for job processing.
  • 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_MINI_PRODUCT_ID=
ANYSTACK_PRO_PRODUCT_ID=
ANYSTACK_MAX_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.
  • Since it's possible for a user to close their browser before the redirect from Stripe back to nativephp.com has happened, we need to listen for a Stripe customer.subscription.created event via webhook to know that a purchase has occurred. The webhook receiving route dispatches a job to query Stripe to retrieve the details of the user (email, etc) and (via dispatching a separate job) send an api request to anystack to create a contact & license.
  • 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
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
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

  • 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

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