Payment (Paddle)
Laravel offers robust solutions for handling payments, primarily through its official packages and integration with third-party payment gateways.
Paddle manages global payments complexity for SaaS and digital product companies, so you don't have to. Paddle operates as a Merchant of Record, managing global payments and currencies, fraud, customer billing support, and complying with every local sales tax rule on your behalf.
For our projects, we've used Laravel as our backend framework, so for that we used Laravel Cashier (Paddle) package for easy implementation and because it covers a lot of configuration under the hood.
Environment Setup
Paddle provides two environments; one for testing and staging (or sandbox mode), and one for production where Paddle needs to verify your domain before using the application.
- Create an account in Paddle Sandbox: Visit this link and create an account
- Set up your environment: For this to work in a local development environment, we need a “tunneling software” or “reverse proxy services” like ngrok. Tools like this create a secure tunnel from a publicly accessible URL to a local development server running on your machine. This step is required so that Paddle's webhooks are listened to via a publicly accessible URL and redirected to your local machine.
2.A. Install ngrok on your application: visit this link create an account and follow all the steps mentioned in the documentation.
After that install the npm package in your local to be able to run it on your environment.
npm i ngrok
To run ngrok's listener, you need to call the following command each time after you turn off your computer.
ngrok http http://localhost:${your_port}
This command will generate a URL you’re gonna need it in the next step in the configuration.
Note: if you are using Laravel Sail you need to use Sail's site sharing command. After completing this you can proceed to the next step.
2.B. In your paddle dashboard go to “Developer Tools” → “Notifications” and create a new destination in URL field paste in the URL generated in the previous step and add /paddle/webhook at the end of the URL, choose the webhook as your notification type and select all events and fill in the other fields and click create new destination. Go again to the webhook you just created click edit and copy paddle webhook secret (”Secret Key”).
Now go to “Developer Tools” → “Authentication” and create an API Key (Make sure to copy the api key from the popup before closing it) and a Client-Side-Token and copy all those to your .env file
PADDLE_CLIENT_SIDE_TOKEN=
PADDLE_API_KEY=
PADDLE_WEBHOOK_SECRET=""
# Set this to false on production
PADDLE_SANDBOX=true
Products and Checkout
-
Create your products: In your paddle dashboard go to “Catalogue” → “Products” and create your products as you need. Foreach product you can create multiple prices. Copy all the prices IDs as you gonna need them for checking out users later.
-
Customize the Checkout popup: This step is optional, but you can go under “Checkout” → “Checkout Settings” on your dashboard, and customize the checkout to match your brand colors, you can change the accepted cards for payments.
Implementation
To start implementing the payment feature you need to have:
- A login functionality as the user must be authenticated to perform this kind of actions.
- A page to perform the call to payment action (such as: pricing page, basket page…etc.)
- A Success page to redirect users to after completing the payment successfully.
- A page contains the button to call the checkout page from paddle (overlay or inline)
Important Notes:
- The last two pages you can find them in the Laravel Cashier package documentation.
- There is a gatcha related to the User model if you're using Eloquent to verify subscriptions. You need to use a global cache-lock or mutex on subscription checks to avoid stale data or false-negatives.
For more information please refer to the official documentation (check the Laravel and Paddle version you are using).