Unlimited Plugins, WordPress themes, videos & courses! Unlimited asset downloads! From $16.50/m
by
Lessons:9Length:50 minutes

Next lesson playing in 5 seconds

Cancel

Free Preview: Process Payments With Stripe and Laravel Cashier

Introduction

01:04
  • Overview
  • Transcript

Stripe is a payment-processing service that comes with a suite of easy-to-use APIs and powers e-commerce for businesses of all sizes. Stripe makes it easy to implement secure credit-card transactions while providing your users the convenience of in-page checkout. Not only that, but Stripe has built-in support for subscriptions and recurring billing.

Laravel is the perfect back-end technology for implementing a Stripe-powered store. Along with Laravel's built-in object-relational mapping, routing and authentication functionality, there is also native support for Stripe with Laravel Cashier.

In this course, Envato Tuts+ instructor Jason Lewis will show you how to process payments on Stripe using Laravel Cashier. You'll cover a number of key topics, including how to prepare your database for payments and pointers to the security concerns you should be aware of when handling cardholder data. You'll also learn how to process single, one-off payments for an online shopping cart, and even how to handle Stripe subscriptions.

1. Introduction

1.1 Introduction

Hello, my name is Jason Noice and I'm going to be your instructor for this course. During this course, we're going to be looking at how we can process payments with Stripe, when using the Laravel PHP framework. This lesson is going to cover a couple of different payment methods we may want to consider when using Stripe, such as single payments and then managing user subscriptions. For this course we'll be utilizing cashier, an official component for Laravel that's maintained by Taylor Rotwell. Cashier itself is primarily designed to manage subscriptions for applications that require subscription management. However, Cashier can process single payments and will do a whole lot of other odds and ends that make dealing with Stripe a lot easier. At it's core, Cashier is merely a wrapper for the underlying stripe, PHPSTK, which can still be used for more complex tasks. In this lesson, I'm going to be using the command line for a few things, as well as homestead for saving a small application. And we'll be using the my skew RL workbench to inspect tables and view data. So, let's get right into it, shall we? Let's take a good look at what Stripe is.

2. Getting Ready

2.1 Getting Familiar With Stripe

In this lesson, we're going to be getting ourselves familiar with what Stripe is and what it offers us. Now, you might already have some idea of what Stripe is, but let's just talk about it quickly. Stripe advertises itself as a set of unified APIs and tools that instantly enable businesses to accept and manage online payments. In a nutshell, Stripe is a payment gateway. But why would we bother using Stripe? Why not just add one of those simple PayPal checkout buttons and be done with it? See now that's a good question, and it is one that you should really be asking yourself. Stripe allows you to process the payment from your application. So the customer doesn't have to click through to PayPal. And they don't have to go through several more forms on the PayPal website just to pay for a subscription, or pay for some products. Stripe is a much more streamlined approach. With it, you can accept and process the payment directly from your application. This will usually involve fewer page loads and clicks for the customer, which is always a good thing. Stripe can also accept a number of different payment methods, including credit cards and bitcoins. When you compare it to a service like PayPal, Stripe may seem a little bit more complicated to implement, but it's really not that hard. Thankfully, Stripe does include a very handy JavaScript library called Checkout, which is built upon the Stripe.js library. This acts very much like a PayPal payment button. Checkout will integrate a form directly into your application so that you don't have to worry about actually handing the credit card details. Checkout will send an AJAX request with the customer's details to the Stripe servers which will then return a unique token. You can then use this token to process the payment. We'll be talking more about this and the security implications in the lessons to come. So now you might be wondering how much all this will cost. Well, it's actually free, but you will be charged a small fee per transaction. Let's take a look at those fees now. For the United States, Stripe will charge 2.9% of the transaction, plus an additional $0.30. The fees that Stripe charge will vary from country to country, so it's always worth investigating what fees you may be charged. Let's look at an example of how Stripe charges the fees. Say we want to charge a customer $100. First, Stripe takes 2.9% of the total, which in this case would be $2.90. We're now left with $97.10. Then Stripe will charge an additional flat-rate fee of $0.30, which will leave us with a total of $96.80. But if you prefer, you can make up that loss by moving the Stripe fee onto the customer. Stripe has a detailed help article covering this in detail. Basically, all we need to do is take the amount we wish to charge the customer and add the flat rate fee to it. In our case, if we wish to charge $100 then we need to add the 30 cents, which would give us $100.30. Next, we need to divide this by the percentage fee subtracted from 1. Our percentage fee is 2.9%, which you can represent as 0.029. So, 1 minus 0.029 is 0.971, so if we do the division, we'll end up with roughly $103.30. Now you might notice that this is slightly higher than the initial fee that we calculated for the $100, but this is to compensate for the higher charge. If we now calculate the fees charged based on this amount, we'll get a fee of $3.30. So if you like, you can charge your customer for the Stripe fees. All right, so now that we know how Stripe handles our payments, and how we'll be charged on a per transaction basis, let's go ahead and log in to our Stripe account. If you don't have an account, then go ahead and sign up now. From our Stripe dashboard, we can immediately see an overview of all of our charges and our customers. On the left, we're able to navigate to our customers, our plans, payments, coupons and other odds and ends to configure our account. At the top, we're able to switch between the test and live modes. Some other things that we need to be aware of are our API keys, which can be found by going to our Account Settings and then selecting API Keys. Your private key should be kept confidential. And don't worry, I'll be regenerating these keys afterwards so that they cannot be used. And that just about covers the basics of Stripe. In the next lesson we're going to start by installing Laravel, and later we'll take a look at HTTP verse HTTPS.