A repository to experiment with Stripe webhooks.
- What do you need
- Ruby on Rails
- Stripe CLI
- Run the application
bin/rails s -p 3001
- Redirect events to the local server
stripe listen --forward-to localhost:3001/stripe_webhooks
- Interact with Stripe and do the following actions
- Create a subscription for a customer.
- If the customer does not exists yet, remember to create it and to add an email, otherwise, the subscription can't be created.
- The customer must have a payment method. A Stripe fake credit card can be used as explained here
-
Pay the subscription from Invoices >> Charge customer
-
Cancel the subscription only if it is paid.
-
You can corroborate each previous action in the Rails Console if needed
- Check for the user and its subscriptions
user = User.last
user.subscriptions
ℹ️ The external_id of user and subscription models, corresponds to the id in Stripe
- Check for the status of the subscription once created
subscription = Subscription.find_by(external_id: stripe_subscripion_id)
subscription.unpaid?
- Check for the status of the subscription once paid
subscription = Subscription.find_by(external_id: stripe_subscripion_id)
subscription.paid?
- Check for the status of the subscription once canceled
subscription = Subscription.find_by(external_id: stripe_subscripion_id)
subscription.canceled?