Download the PHP package enea/laravel-cashier without Composer

On this page you can find all versions of the php package enea/laravel-cashier. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-cashier

Deprecated - Laravel Cashier Package

This repository is marked as deprecated and has been replaced by a better and more comprehensive version.

Reason: We have released Swift Cart, which offers enhanced functionalities, a more user-friendly experience, and improved performance. As a result, this repository will no longer receive updates.

Deprecation Date: August 4st, 2023.

This package provides a functionality to manage the sale of products and abstracts all the calculations you need for a sale.

Installation

Laravel Cashier requires PHP 7.4. This version supports Laravel 7

To get the latest version, simply require the project using Composer:

And publish the configuration file.

Class reference

This table defines the implementation of the models necessary for the operation of the package, there are some models that come to help such as: $discount and $document, however it is recommended to replace these models with your own.

Concrete Abstract Description
$client Enea\Cashier\Contracts\BuyerContract person who makes the purchase
$document Enea\Cashier\Contracts\DocumentContract type of sale document
$product Enea\Cashier\Contracts\ProductContract product being sold
$quote Enea\Cashier\Contracts\QuoteContract quote available for sale
$quotedProduct Enea\Cashier\Contracts\QuotedProductContract quoted product to sell
$discount Enea\Cashier\Modifiers\DiscountContract representation of a discount
$tax Enea\Cashier\Modifiers\TaxContract representation of a tax

Usage

To start a purchase you must use the ShoppingManager::initialize($client, $document).

When you initialize a shopping cart, a token is generated so that it can be searched from ShoppingManager::find($token). This function gets the shopping cart from session.

It is also possible that you want to invoice a quote, and to do so you must call the attach function of the $shoppingCart. Doing this creates a QuoteManager instance inside the Shopping Cart, which can be accessed from the $shoppingCart->getQuoteManager() function.

Now you just have to add products to the shopping cart using $shoppingCart->push($product, $quantity).

Or you can also pull products from the quote using $shoppingCart->pull($productID).

The push and pull methods returns an instance of ProductCartItem, which provides a lot of useful method.

Example

For this example, we are going to simulate a simple purchase. We need a $client and we will use a $invoice with IVA as a sales document.

Now we add a controller to manage shopping cart products.

And to finish we save the document in the database.

Cashier

It is responsible for centralizing the calculations to get taxes, discounts and totals for each product. you can find it in Enea\Cashier\Calculations\Cashier.

Method Description Return
getUnitPrice() unit sales price float
getGrossUnitPrice() gross price (price without tax) float
getNetUnitPrice() net price (price + taxes) float
getSubtotal() subtotal float
getTotalDiscounts() total discounts float
getTotalTaxes() total taxes float
getTotal() final total with discounts and taxes float
getTaxes() all taxes grouped by name Taxed[]
getTax(string $name) tax by name Taxed
getDiscounts() all discounts grouped by code Discounted[]
getDiscount(string $code) discount by code Discounted

Pricing

Cashier separates the prices into 3, getGrossUnitPrice(), getNetUnitPrice() and getUnitPrice(), where the latter is the unit price after evaluating taxes, both included and excluded. $cashier->getUnitPrice() is the function used for all calculations. You can see an example in code from Enea\Tests\Calculations\PriceTest

Method getGrossUnitPrice() getNetUnitPrice() getUnitPrice()
Base 100.00 $USD 100.00 $USD 100.00 $USD
Included Taxes IVA(12%), AnotherTax(11%) IVA(12%), AnotherTax(11%) IVA(12%), AnotherTax(11%)
Tax to use IVA(12%) IVA(12%) IVA(12%)
Applied - IVA and AnotherTax IVA
Total 81.30 $USD 100 $USD 90.24 $USD

Configuration

There are a few things you need to know to set up taxes and discounts correctly.

More documentation

You can find a lot of comments within the source code as well as the tests located in the tests directory.


All versions of laravel-cashier with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
laravel/framework Version ^8.0||^9.0
ext-json Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package enea/laravel-cashier contains the following files

Loading the files please wait ....