How to Accept Payments

No longer do we require brick and mortar shops to sell our products. Have you written a book? Great! You can set up a webpage to sell it in a matter of minutes. It's that easy at this point, as long as you have a touch of programming knowledge. In this series, we'll review the ins and outs of accepting payments and subscriptions through Stripe.

Start Series

Share this series on:

  • 01

    Episode 1 Run Time 15:16

    Stripe Checkout Free

    In this opening episode, we'll leverage Stripe's Checkout integration to quickly generate a "Pay Now" button to sell our fictional book. Along the way, we'll discuss the basic flow for performing charges through Stripe. It's vital that you understand this flow, so pay attention!
  • 02

    Episode 2 Run Time 6:23

    Custom Checkout

    You may find that you need more control over the checkout process. In this episode, we'll review the manual approach for loading Stripe's checkout modal.
  • 03

    Episode 3 Run Time 10:07

    Integrating Vue 2

    As you may know, I'm a huge advocate of the Vue JavaScript framework. In this episode, we'll take the code we wrote in episode two, and transition it over to a custom Vue 2 component.
  • 04

    Episode 4 Run Time 8:26

    Dynamically Populating the Checkout Modal

    Now that we've transitioned over to Vue, let's figure out how to dynamically populate the checkout modal's price and details, based upon a chosen product from a dropdown menu.
  • 05

    Episode 5 Run Time 10:16

    Recurring Subscriptions

    So far, we've only attempted single charges. However, in this episode, we'll migrate over to associating customers with recurring subscription plans. It's easy! To start, we'll add two simple plans that mimic Laracasts, itself: monthly and yearly.
  • 06

    Episode 6 Run Time 5:54

    Handling Failed Charges

    When using Checkout, Stripe will perform a preliminary bit of validation on the provided card number. However, there can and will still be situations when the Customer object is properly created, but the charge fails to go through. It's paramount that we detect these exceptions, and alert the user. We'll tackle that very thing in this episode.
  • 07

    Episode 7 Run Time 12:11

    Recording the Stripe Customer

    When working with Stripe, it's paramount that you store a handful of columns in your database that indicate the user's customer id, their subscription status, and, if canceled, the timestamp for when their subscription-only access should expire.
  • 08

    Episode 8 Run Time 10:51

    Refactoring Strategies

    In this episode, I'll demonstrate a few refactoring strategies that I often implement in my own projects. To clean up our SubscriptionsController, we might leverage form objects, as well as creating a dedicated Subscription class to manage any interaction with Stripe. In incremental steps, let's review the workflow.
  • 09

    Episode 9 Run Time 12:09

    Events and Webhooks

    It's paramount that you listen for a number of Stripe-specific events. For example, what if attempts to renew a customer's subscription fails? Though Stripe will attempt this charge a number of times, eventually, the subscription will be canceled. As such, it's vital that we have a way to listen for such an event, and deactivate the user's account in our database.

    In this episode, we'll register a webhook endpoint with Stripe, and learn how to listen for events and fetch the associated payload. In the process, I'll also demonstrate a useful technique for registering local webhooks.

  • 10

    Episode 10 Run Time 8:51

    Cleaner Webhook Management

    Now that we understand the basics of how to register Stripe web hooks, let's take a few moments to refactor the code to make it more enjoyable to work with and extend. If we're planning on responding to a number of Stripe events in the future, it's vital that we structure things as elegantly as possible now, rather than later.
  • 11

    Episode 11 Run Time 6:42

    Testing Stripe Webhooks

    I'm sure you're itching to dig into more of Stripe's main API, however, it's vital that we learn how to write the necessary tests to ensure that all billing code works as expected. You never want to be in a situation, where you deploy code one afternoon...only to be woken up in the middle of the night because your subscription sign ups are broken!

    To begin, let's learn how to post to our Stripe webhooks endpoint, and then verify that the whenCustomerSubscriptionDeleted method behaves as expected.

  • 12

    Episode 12 Run Time 14:32

    Testing Against Stripe's API

    In certain situations, it's paramount that we physically tough Stripe's API to ensure that our code does in fact work as expected. In this episode, let's verify that our Subscription class does make a Stripe customer, associates them with the proper plan, and activates their account in our local database.
  • 13

    Episode 13 Run Time 3:25

    A Billable Trait

    If we want to maintain our current API, that allows us to call various subscriptions-specific methods off of $user, then we might consider extracting a helpful BillableTrait to clean things up. Let's tackle that very thing in this episode.

  • 14

    Episode 14 Run Time 10:56

    Record All Stripe Charges

    We should setup a dedicated table to store all incoming Stripe charges. Not only will this provide a fast payments list for the user, but it will also makes reporting and daily summaries easier to prepare.

  • 15

    Episode 15 Run Time 13:17

    Cancel Subscriptions With Tests

    It would be a pretty shabby service, if we didn't offer users the ability to cancel their subscriptions. In this episode, we'll write that very logic, while also preparing a test to ensure that everything works as we expect.
  • 16

    Episode 16 Run Time 9:51

    Apply Coupon Codes

    It's likely that your website will at some point offer coupon codes to new subscribers. Luckily, once again, Stripe makes this all a cinch. Let's review the basic flow - including the tests to ensure that it all works properly - in this episode.

    View the source code for this series on GitHub.

  • 17

    Episode 17 Run Time 8:47

    Testing for Grace Periods

    We need to offer users the ability to resume recently canceled subscriptions. But before we get to that point, we must first learn how to determine if a user is currently on their grace period. Let's tackle that in this episode!
  • 18

    Episode 18 Run Time 13:40

    Resuming Subscriptions

    In this episode, we'll update our API to allow users to resume their subscriptions. This will require that we add a resume method to the Subscription class. Stay tuned to the end for a bit of homework as well.
  • 19

    Episode 19 Run Time 8:45

    Clarity and Rendering Subscription-Only Content

    In this video, we'll take a few moments to discuss clarity, double-negatives, and the potential they have to introduce bugs. Then, we'll setup a template for rendering subscription-only content, while providing the necessary call-to-action for guests and deactivated users.
  • 20

    Episode 20 Run Time 5:36

    How to Reduce Conditionals in Your Views

    In the previous episode, we constructed multiple conditionals to determine which set of HTML should be displayed. For our basic example, the outcome was simple enough. However, for real-life projects, you may find that this quickly bloats your views and makes them difficult to reason about. Instead, let me show you a useful technique that involves applying polymorphism to dynamically load the proper view partial.