PHPackages                             leafs/billing - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. leafs/billing

ActiveLibrary[Payment Processing](/categories/payments)

leafs/billing
=============

Leaf Billing API design

v0.3.0(6mo ago)01862MITPHP

Since Apr 8Pushed 4mo agoCompare

[ Source](https://github.com/leafsphp/billing)[ Packagist](https://packagist.org/packages/leafs/billing)[ Docs](https://github.com/leafsphp/billing)[ GitHub Sponsors](https://github.com/leafsphp)[ Fund](https://opencollective.com/leaf)[ RSS](/packages/leafs-billing/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (2)Versions (5)Used By (2)

 [![](https://camo.githubusercontent.com/d98ee5e32c2ff016fdfdac6c42654a908f4cc34b229c7b00caacc5a717455ae8/68747470733a2f2f6c6561667068702e6465762f6c6f676f2d636972636c652e706e67)](https://camo.githubusercontent.com/d98ee5e32c2ff016fdfdac6c42654a908f4cc34b229c7b00caacc5a717455ae8/68747470733a2f2f6c6561667068702e6465762f6c6f676f2d636972636c652e706e67)

Leaf Billing (Beta)
===================

[](#leaf-billing-beta)

 [![Latest Stable Version](https://camo.githubusercontent.com/474d7f35988a8f23e9604ad66bdbd91f35fbc608962f47bf355c841fe69120c4/68747470733a2f2f706f7365722e707567782e6f72672f6c656166732f62696c6c696e672f762f737461626c65)](https://packagist.org/packages/leafs/billing) [![Total Downloads](https://camo.githubusercontent.com/d58cf08609d1d8db779c772f3dd3b1f5e3406e388a5647db2c4fb06a91fe4457/68747470733a2f2f706f7365722e707567782e6f72672f6c656166732f62696c6c696e672f646f776e6c6f616473)](https://packagist.org/packages/leafs/billing) [![License](https://camo.githubusercontent.com/ca4207b85532b6dc9c836203236658eb3ed5fa136f4d87835e9127fec5fae30f/68747470733a2f2f706f7365722e707567782e6f72672f6c656166732f62696c6c696e672f6c6963656e7365)](https://packagist.org/packages/leafs/billing)

Leaf's billing system helps makers move faster by handling payments and subscriptions out of the box. With built-in Stripe support—and more providers like Paystack coming soon—you can set up one-time payments or recurring subscriptions in just a few minutes. That means less time worrying about billing and more time building.

Setting up
----------

[](#setting-up)

To get started, create a Stripe account and grab your API keys. Then, drop them into your `.env` file:

```
BILLING_PROVIDER=stripe
STRIPE_API_KEY=sk_test_XXXX
STRIPE_PUBLISHABLE_KEY=pk_test_XXXX
STRIPE_WEBHOOK_SECRET=whsec_XXXX # only if you are using webhooks
```

You then have to install the Stripe module for Leaf:

```
leaf install stripe
```

Billing on-the-fly
------------------

[](#billing-on-the-fly)

Billing on-the-fly is the fastest way to charge customers—ideal for one-time payments, donations, or services. Just generate a payment link with Leaf Billing, and we’ll handle the rest. You can do this using the `billing()` helper in your controller.

```
...

public function handleCartPurchase($cartId) {
    $cart = Cart::find($cartId);

    $session = billing()->charge([
        'currency' => 'USD',
        'description' => 'Purchase of items in cart',
        'metadata' => [
            'cart_id' => $cartId,
            'items' => $cart->items(),
        ]
    ]);

    $cart->payment_session = $session->id;
    $cart->save();

    response()->redirect($session->url);
}
```

Leaf takes care of the entire payment session for you—automatically tracking the user (if available), any metadata you provide, and the payment status, keeping your code clean and focused on your app.

Billing Callbacks
-----------------

[](#billing-callbacks)

By default, Leaf Billing redirects users to `/billing/callback` after a payment is completed or canceled. You can customize this behavior by setting `BILLING_SUCCESS_URL` and `BILLING_CANCEL_URL` in your `.env` file, or by passing custom URLs directly to the `charge()` method.

```
