Skip to main content

Documentation Index

Fetch the complete documentation index at: https://danestvesllc-2b77d201.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

The Billable trait exposes a small set of customer-management helpers that let you send users to Polar’s hosted customer portal and interact with their stored payment methods — all without exposing your org-scoped admin token to the client. Both portal redirects and payment method operations mint a short-lived customer session token server-side on every call, so your admin credentials are never sent to the browser.
Polar customer portal is a Polar-hosted page where customers can update their info, manage subscriptions, download invoices, and add payment methods. You link to it; Polar hosts it.

Customer portal

Polar’s customer portal is a hosted, self-service page where your customers can update their personal information, manage subscriptions, and add new payment methods.

Redirecting to the portal

Call redirectToCustomerPortal() from a controller or route closure. It returns a RedirectResponse pointing to the portal URL.
use Illuminate\Http\Request;

Route::get('/customer-portal', function (Request $request) {
    return $request->user()->redirectToCustomerPortal();
});

Getting the portal URL directly

If you need the URL without issuing an immediate redirect — for example to pass it to a view — use customerPortalUrl():
$url = $user->customerPortalUrl();
This is the same URL that redirectToCustomerPortal() uses internally. Both methods mint a short-lived customer session each time they are called, so the resulting URL is always fresh.
Both methods throw Danestves\LaravelPolar\Exceptions\InvalidCustomer if the billable model does not yet have an associated Polar customer record. Make sure the customer has completed at least one checkout before calling these methods.

Payment methods

Listing saved payment methods

Call paymentMethods() on your billable to retrieve a Collection of the customer’s stored cards and generic payment instruments.
$methods = $user->paymentMethods();
// Collection<int, Components\PaymentMethodCard|Components\PaymentMethodGeneric>
The type property on each item acts as a discriminator. When type is 'card', the item is a PaymentMethodCard and exposes the following properties:
PropertyTypeDescription
brandstringCard network, e.g. "visa"
last4stringLast four digits of the card number
expMonthintExpiry month (1–12)
expYearintExpiry year (four-digit)
typestringDiscriminator — "card"
foreach ($user->paymentMethods() as $method) {
    if ($method->type === 'card') {
        // $method is a PaymentMethodCard
        echo "{$method->brand} ending in {$method->last4}";
        echo " — expires {$method->expMonth}/{$method->expYear}";
    }
}

Deleting a payment method

Pass the payment method ID (prefixed pm_) to deletePaymentMethod():
$user->deletePaymentMethod('pm_xxx');
Polar does not expose a server-side “add payment method” endpoint. Customers add new payment methods exclusively through the customer portal. Send them there with $user->redirectToCustomerPortal().
Like paymentMethods(), this method throws Danestves\LaravelPolar\Exceptions\InvalidCustomer if the billable has no Polar customer yet.
All of these methods — paymentMethods(), deletePaymentMethod(), customerPortalUrl(), and redirectToCustomerPortal() — authenticate server-side on each call. Your admin access token is never sent to the browser.