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

Developer tools -> Authentication

Grab your seller ID and the key, add it to your .env

PADDLE_SELLER_ID=
PADDLE_AUTH_CODE=
PADDLE_RETAIN_KEY=
PADDLE_WEBHOOK_SECRET=
PADDLE_SANDBOX=true
Retain is optional, sandbox true it will go to sandbox paddle, seller id and key to PADDLE_SELLER_ID & PADDLE_AUTH_CODE

In your user model

use Laravel\Paddle\Billable;
 
class User extends Authenticatable
{
    use Billable;
}

In your master layout add this

<head>
    ...
 
    @paddleJS
</head>
Don't forget to add this field with your URL Ex: the http//:cashier.test/buy 
Make new products, notice when you get the product id it start with pri_* not pro_*

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.

put this in your webhook secret

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