This project uses Laravel Dusk to log into Paddle's web interface, navigate to the payouts page, and download the available PDF files for payouts.
I use these payout PDFs for accounting purposes by syncing them as invoices to my accounting software. Since this process only happens once a month, it might not seem like a big task. However, if you manage multiple Paddle accounts for different products, it can quickly take several hours each month to complete. So, let's automate it!
composer require laravel/dusk
When prompted, don't rerun with --dev if you want to run this in production and not just in your local/testing environments.
php artisan dusk:install
This command will download the Chromium browser driver.
Note: Laravel Dusk requires a browser to be installed on the system where it runs. So make sure to install the
google-chrome-stablepackage on the machine that will execute this process.
The core functionality of this project resides in: tests/Browser/PaddleDownloadPayoutPdfTest.php
Here's what it does:
- Fetches the available
PaddleAccountrecords (create at least one before running the script). - Logs into the Paddle dashboard, navigates to the Payouts page, and retrieves the available payouts.
- Uses the
downloadPdffunction to download and store the PDFs for "US" and "RoW" invoices instorage/app/private/paddle_invoices/. - Extracts the total amounts from the PDFs using the
PdfToTextpackage and theextractTotalAmountFromPdfTextfunction. - Creates or updates the PaddlePayout records in the database.
php artisan dusk
After running the test, you’ll have PaddlePayout records and the corresponding PDFs at your disposal!