1. Go to this page and download the library: Download fevinta/cashier-asaas library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Fevinta\CashierAsaas\Billable;
class User extends Authenticatable
{
use Billable;
// Optional: customize customer data for Asaas
public function asaasCpfCnpj(): ?string
{
return $this->document;
}
}
// Check if subscribed
if ($user->subscribed('default')) {
// Has active subscription
}
// Check specific plan
if ($user->subscribedToPlan('pro', 'default')) {
// Subscribed to Pro plan
}
// Check trial
if ($user->onTrial('default')) {
// On trial period
}
// Get subscription
$subscription = $user->subscription('default');
// Check subscription state
$subscription->active(); // Is active
$subscription->onTrial(); // On trial
$subscription->cancelled(); // Has been cancelled
$subscription->onGracePeriod(); // Cancelled but still active
$subscription->ended(); // Completely ended
$subscription = $user->subscription('default');
// Cancel (at period end)
$subscription->cancel();
// Cancel immediately
$subscription->cancelNow();
// Resume cancelled subscription (if on grace period)
$subscription->resume();
// Swap to different plan
$subscription->swap('enterprise');
// Update price
$subscription->updateValue(149.90);
// Change billing type
$subscription->changeBillingType(BillingType::PIX);
// Update credit card
$subscription->updateCreditCard($cardData, $holderInfo);
// Or with token
$subscription->updateCreditCardToken($newToken);
// Swap using config price
$subscription->swap('premium');
// Swap with custom price
$subscription->swap('custom', 99.90);
// Just update price without changing plan name
$subscription->updateValue(99.90);
use Fevinta\CashierAsaas\Checkout;
// Quick checkout for existing customer
$checkout = $user->checkoutCharge(99.90, 'Premium Feature');
// Redirect to checkout page
return $checkout->redirect();
// Or get the URL
$url = $checkout->url();
use Fevinta\CashierAsaas\Checkout;
// Guest checkout - customer data collected on checkout page
$checkout = Checkout::guest()
->charge(199.90, 'Product Purchase')
->allowAllPaymentMethods()
->successUrl('https://your-app.com/success')
->create();
return $checkout->redirect();
// Or pre-fill customer data
$checkout = Checkout::guest()
->charge(199.90, 'Product Purchase')
->customerName('John Doe')
->customerEmail('[email protected]')
->customerCpfCnpj('12345678901')
->create();
use Fevinta\CashierAsaas\Invoice;
$invoice = Invoice::find($id);
// Issue the NFS-e immediately
$invoice->authorize();
// Request cancellation
$invoice->cancel();
// Refresh local data from the Asaas API
$invoice->syncFromAsaas();
// Check status
$invoice->isScheduled();
$invoice->isSynchronized();
$invoice->isAuthorized();
$invoice->isCanceled();
$invoice->hasError();
// Get document URLs
$invoice->pdfUrl();
$invoice->xmlUrl();
// Query scopes
Invoice::authorized()->get();
Invoice::scheduled()->where('customer_id', $customerId)->get();
Asaas::invoice()->findByPayment($paymentId);
Asaas::invoice()->findByCustomer($customerId);
Asaas::invoice()->findByDateRange('2026-01-01', '2026-01-31');
Asaas::invoice()->findByStatus('AUTHORIZED');
// Fiscal and municipal service info
Asaas::invoice()->fiscalInfo();
Asaas::invoice()->saveFiscalInfo([...]);
Asaas::invoice()->municipalServices();