Laravel Cashier Paddle V2
Finally, after the release of the new version of laravel cashier, I had a taste of Cashier. For some of us in some countries that sometimes stripes don't support or maybe for some other reasons, we decided to use Paddle.
Should've known earlier that there are 2 different types of paddle domains, one for production and one for sandbox, I registered to production but didn't know that sandbox paddle exists, I thought you just needed to add an environment set to sandbox and that's it. Also don't forget to register again to sandbox paddle if you haven't done it already.
Production: https://www.paddle.com/
Sandbox: https://sandbox-vendors.paddle.com/
Like any other installation
composer require laravel/cashier-paddle
php artisan vendor:publish --tag="cashier-migrations"
php artisan migrate // it will add new tables
Grab your seller ID and the key, add it to your .env
In your user model
use Laravel\Paddle\Billable;
class User extends Authenticatable
{
use Billable;
}
In your master layout add this
<head>
...
@paddleJS
</head>
In your web.php
Route::get('/buy', function (Request $request) {
$checkout = auth()->user()->checkout('productId', (int) quantity)
->returnTo(url('/'));
return view('billing', ['checkout' => $checkout]);
});
create billing.blade.php, there are more types of showing buttons or inline checkout but I chose this.
<x-paddle-checkout :checkout="$checkout" class="w-full" />
Webhooks
I still can't figure out the package webhooks after the subscription is done, I've setup the listener but I don't think it's working. I managed to find another way to do it using the notification. Another way to do it is by using the link in the resource to try it out.
Troubleshoots
403 on receiving webhook
A 403 Forbidden error is usually using the wrong webhook signature.
A 405 error is usually when the webhook URL is doing a redirect and therefore changes the method from POST to GET. This usually occurs for things like canonical redirects where you redirect HTTP to HTTPS, or non-www URLs to www.
Resources
https://vendors.paddle.com/webhook-alert-test
https://sandbox-vendors.paddle.com/webhook-alert-test