Download the PHP package fevinta/cashier-asaas without Composer
On this page you can find all versions of the php package fevinta/cashier-asaas. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download fevinta/cashier-asaas
More information about fevinta/cashier-asaas
Files in fevinta/cashier-asaas
Package cashier-asaas
Short Description Laravel Cashier integration for Asaas payment gateway (Brazil)
License MIT
Homepage https://github.com/fevinta/cashier-asaas
Informations about the package cashier-asaas
Laravel Cashier-style Asaas (Unofficial)
Laravel Cashier-style subscription billing for Asaas payment gateway (Brazil).
Features
- 🇧🇷 Brazilian Payment Methods: PIX, Boleto, Credit Card
- 💳 Subscription Management: Create, update, cancel, resume subscriptions
- 🔄 Plan Swapping: Change plans with automatic proration
- ⏰ Trial Periods: Support for trial days
- 🪝 Webhook Handling: Automatic payment status updates
- 🎯 Laravel-like API: Familiar Cashier-style fluent interface
- 🛒 Asaas Checkout: Hosted checkout page (like Stripe Checkout)
- 🧾 Invoice (NFS-e): Issue and manage Notas Fiscais de Serviço
Requirements
- PHP 8.3+
- Laravel 12 or 13
Installation
Publish the configuration and migrations:
Configuration
Add your Asaas credentials to .env:
Define your subscription plans in config/cashier-asaas.php:
Setup
Add the Billable trait to your User model:
Usage
Creating Subscriptions
Checking Subscription Status
Managing Subscriptions
Plan Swapping & Proration
When you swap plans, automatic proration is applied via the Asaas API. Here's how it works:
Example: Upgrading from R$10/month to R$20/month
The swap() method sends updatePendingPayments: true to Asaas, which automatically:
- Calculates the prorated difference based on days remaining
- Adjusts pending invoices to include the prorated amount
- Sets all future payments to the new price
Single Charges
Webhooks
The package automatically handles Asaas webhooks. Configure the webhook URL in your Asaas dashboard:
Available events you can listen to:
Middleware
Protect routes requiring subscription:
Register the middleware in your Kernel:
Payment Split
Share revenue with partners:
Asaas Checkout
The package provides a powerful checkout session builder that redirects customers to Asaas's hosted checkout page. This is similar to Stripe Checkout and allows customers to complete payments without you handling sensitive payment data.
Basic Usage
Guest Checkout (No Account Required)
Customer Checkout (Existing User)
Payment Method Options
Installment Payments
Recurring/Subscription Checkout
Redirect URLs
Or configure defaults in config/cashier-asaas.php:
Session Options
Payment Split in Checkout
Using the Checkout Response
Checkout Webhook Events
Invoices (Nota Fiscal de Serviço)
The package supports issuing NFS-e (Nota Fiscal de Serviço) through the Asaas API. Invoices are scheduled via the API, processed with the city hall (prefeitura), and kept in sync locally through webhooks.
Configuration
Add the following to your project's .env:
Run the migration to create the asaas_invoices table:
Scheduling an Invoice
Working with the Invoice Model
Status Lifecycle
API Queries
Subscription Invoice Auto-Generation
Configure automatic NFS-e issuance for subscription payments:
Invoice Webhook Events
The webhook controller automatically syncs invoice data to the local database and dispatches events:
| Webhook Event | Event Class | Invoice Status |
|---|---|---|
INVOICE_CREATED |
InvoiceCreated |
SCHEDULED |
INVOICE_UPDATED |
InvoiceUpdated |
(varies) |
INVOICE_SYNCHRONIZED |
InvoiceSynchronized |
SYNCHRONIZED |
INVOICE_AUTHORIZED |
InvoiceAuthorized |
AUTHORIZED |
INVOICE_CANCELED |
InvoiceCanceled |
CANCELED |
INVOICE_CANCELLATION_DENIED |
InvoiceCancellationDenied |
CANCELLATION_DENIED |
INVOICE_ERROR |
InvoiceError |
ERROR |
Listen to invoice events in your application:
Custom Invoice Model
If you need to extend the default Invoice model:
API Reference
Billable Trait Methods
| Method | Description |
|---|---|
createAsAsaasCustomer() |
Create customer in Asaas |
updateAsaasCustomer() |
Update customer data |
asAsaasCustomer() |
Get Asaas customer data |
newSubscription($type, $plan) |
Start subscription builder |
subscription($type) |
Get subscription by type |
subscribed($type) |
Check if subscribed |
onTrial($type) |
Check if on trial |
charge($amount, $type, $options) |
Single charge |
newCheckout() |
Start checkout builder |
checkout($items, $options) |
Create checkout with items |
checkoutCharge($amount, $name) |
Quick single charge checkout |
Subscription Methods
| Method | Description |
|---|---|
active() |
Is subscription active |
valid() |
Is subscription valid (active/trial/grace) |
cancel() |
Cancel at period end |
cancelNow() |
Cancel immediately |
resume() |
Resume cancelled subscription |
swap($plan) |
Change plan |
updateValue($value) |
Update subscription price |
updateCreditCard() |
Update payment card |
Checkout Builder Methods
| Method | Description |
|---|---|
charge($amount, $description) |
Add single item |
addItem($name, $value, $qty) |
Add item to checkout |
items($items) |
Set multiple items |
allowAllPaymentMethods() |
Enable PIX, Boleto, Credit Card |
onlyPix() |
Only allow PIX |
onlyBoleto() |
Only allow Boleto |
onlyCreditCard() |
Only allow Credit Card |
withPix() / withBoleto() / withCreditCard() |
Add payment method |
oneTime() |
One-time payment (default) |
installments($count) |
Fixed installment payment |
maxInstallments($count) |
Customer chooses installments |
monthly() / yearly() / weekly() |
Recurring payment cycles |
successUrl($url) |
Set success redirect |
cancelUrl($url) |
Set cancel redirect |
expiredUrl($url) |
Set expired redirect |
expiresIn($minutes) |
Set session expiration |
externalReference($ref) |
Set external reference |
split($walletId, ...) |
Add payment split |
create() |
Create checkout session |
Checkout Response Methods
| Method | Description |
|---|---|
id() |
Get checkout session ID |
url() |
Get checkout page URL |
status() |
Get checkout status |
session() |
Get full API response |
redirect() |
Redirect to checkout page |
toArray() |
Convert to array |
toJson() |
Convert to JSON |
Testing
The package uses PEST for testing with a dual approach: mocked HTTP for fast unit/feature tests, and real Asaas Sandbox API for integration tests.
Run All Tests (Mocked)
Run Specific Test Suites
Integration Tests (Real Asaas Sandbox)
Integration tests hit the real Asaas Sandbox API. They are skipped by default when no credentials are configured.
Static Analysis
Test Configuration
Environment variables for testing:
| Variable | Description | Default |
|---|---|---|
ASAAS_API_KEY |
Asaas API key (required for integration tests) | - |
ASAAS_SANDBOX |
Enable sandbox mode | true |
ASAAS_WEBHOOK_TOKEN |
Webhook verification token | - |
License
MIT License. See LICENSE for details.
All versions of cashier-asaas with dependencies
illuminate/contracts Version ^12.0|^13.0
illuminate/database Version ^12.0|^13.0
illuminate/http Version ^12.0|^13.0
illuminate/routing Version ^12.0|^13.0
illuminate/support Version ^12.0|^13.0