Download the PHP package linkthrow/laravel-billing without Composer

On this page you can find all versions of the php package linkthrow/laravel-billing. 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-billing

Billing Package for Laravel 5

This package provides an expressive, fluent interface to a billing services gateway. It handles almost all of the boilerplate code for managing billing customers, subscriptions, and individual charges. The usage and feature set was heavily influenced by the popular Laravel Cashier package. However, it has these major differences:

It currently comes bundled with drivers for these billing services:

Note: Not all features are supported by every billing gateway. See the Gateway Limitations section below for more information.

Installation

Composer

Add this to your composer.json file, in the require object:

After that, run composer install to install the package.

Service Provider

Register the LinkThrow\Billing\BillingServiceProvider in your app configuration file.

Dependencies

The following composer dependencies are needed for the listed billing gateways:

Configuration

Config File

Publish the default config file to your application so you can make modifications.

Customer Migration

Before using this package, we'll need to add several columns to the table that will represent your billing customer. You can use the laravel-billing:customer-table Artisan command to create a migration to add the necessary columns.

For example, to add the columns to the users table use:

Subscription Migrations

Next, we'll need to add several columns to the table that will represent your billing subscription plans. You can use the laravel-billing:subscription-table Artisan command to create a migration to add the necessary columns.

For example, if you have a hosting company and want to allow your customers add a subscription for a website, you might use:

Note: If you only need one subscription per customer, you may use the same table for both the customer migration and the subscription migration (eg. users table).

Note: You may also support multiple subscriptions per customer by adding these fields to more than one table.

Run Migrations

Once the migration has been created, simply run the migrate command.

Customer Model Setup

Next, add the CustomerBillableTrait to your customer model definition:

You should also define a subscriptionmodels method that returns all models that represent any billing subscriptions for a customer. This allows the customer model to propagate credit card changes and status changes (if the customer is deleted) to all of it's subscription models.

Subscription Model Setup

Then, add the SubscriptionBillableTrait to your subscription model definition(s):

You should also define a customermodel method that returns the model representing the customer who owns this subscription. This ensures a subscription has access to the necessary customer information when interacting with the different gateway APIs.

Model Definitions

Finally, to add the ability to look up a model based on it's gateway ID (customer ID, or subscription ID), you need to define the array of Eloquent models acting as a Customer or Subscription.

Add your customer class to the customer_models property in this package's config file:

And add the subscription class(es) to the subscription_models property in this package's config file:

These values are primarily used by the WebhookControllers to help locate the corresponding Eloquent model from the gateway's ID when a new billing event is received.

Customers

Billing customers can be created and managed separately from subscriptions or charges.

Creating A Customer

Once you have a customer model instance, you can create the customer in the billing gateway using a gateway-specific credit card token:

If you would like to apply a coupon when creating the customer, you may use the withCoupon method:

The billing method will automatically update your database with the billing gateway's customer ID and other relevant billing information.

If you would like to specify additional customer details, you may do so by passing them in to the create method:

Updating A Customer

To update an existing customers primary credit card information, or to add a coupon to their existing account, you may use the update method:

Deleting A Customer

Deleting a customer will delete their account from the billing gateway and delete all existing subscriptions:

Multiple Credit Cards

You may add more than one credit card to a customer using the creditcards method:

Updating an existing credit card's information (such as expiration date or billing address) is also possible:

Or delete an existing credit card:

Retrieving and working with customer credit cards is pretty straight forward:

Invoices

You can easily retrieve an array of a customer's invoices using the invoices method:

Or get the most recent invoice:

Or find an invoice by it's ID:

To display relevant invoice information, use the invoice properties:

Use the render method to generate a pre-formatted HTML version of the invoice:

Checking Customer Status

To verify that a customer has been created in the billing gateway, use the readyForBilling method:

Subscriptions

Subscribing To A Plan

Once you have a subscription model instance, you can subscribe a customer to a given plan:

You may apply a coupon specifically to the subsciption using the withCoupon method:

You may also specify a new credit card token to use with this subscription:

Or specify an existing credit card ID:

Note: If no card or card_token is specified, the default (initial) card associated with the customer will be used.

There may be times when you haven't yet created the customer or you don't have the customer model available for use when you want to create a subscription. In these cases you may subscribe to a plan directly on the subscription model using the subscription method:

This method also supports the optional withCoupon and withCardToken methods:

Note: The customer will automatically be retrieved using the customermodel method you defined in your subscription model above.

No Card Up Front

If your application offers a free-trial with no credit-card up front, set the cardUpFront property on your model to false:

On model creation, be sure to set the trial end date on the model:

It should be noted that any subscription commands executed on an on-trial subscription model will not be synced with the billing gateway if the customer is not ready for billing (created in billing system with at least one credit card). This allows the developer to perform the same create, swap, etc commands on a model while you wait for the customer to be created in the billing gateway.

If you have one or more pending, on-trial, subscriptions when the user does add their credit card, you can use the withSubscriptions flag to activate all pending, non-free, subscriptions in the billing gateway:

Swapping Subscriptions

To swap a user to a new subscription, use the swap method:

If the user is on trial, the trial will be maintained as normal. Also, if a "quantity" exists for the subscription, that quantity will also be maintained.

Subscription Quantity

Sometimes subscriptions are affected by "quantity". For example, your application might charge $10 per month per user on an account. To easily increment or decrement your subscription quantity, use the increment and decrement methods:

Cancelling A Subscription

To cancel a subscription, use the cancel method:

When a subscription is canceled, this package will automatically set the billing_subscription_ends_at column on your database. This column is used to know when the subscribed method should begin returning false. For example, if a customer cancels a subscription on March 1st, but the subscription was not scheduled to end until March 5th, the subscribed method will continue to return true until March 5th.

Resuming A Subscription

If a user has canceled their subscription and you wish to resume it, use the resume method:

You may also specify a new credit card token:

If the user cancels a subscription and then resumes that subscription before the subscription has fully expired, they may not be billed immediately, depending on the billing gateway being used.

Free Subscription Plans

Sometimes you want to offer a free subscription plan. You can do that easily with the isFree flag. Any subscription flagged as free will not be synced to the billing gateway. However, you may continue to use the same subscription commands, for ease of use, as long as you use the isFree flag.

To create a free subscription:

You may also swap from a paid plan to a free plan. This will cancel the subscription in the billing gateway and update the local record to reflect the free state:

Note: If you do not use the isFree flag, then it is assumed the plan is not free and the subscription will be created in the billing gateway.

Note: This package will attempt to maintain the subscription id from the billing gateway and resume the existing subscription when swapped from paid to free and then back to paid again.

Working With Subscriptions

To verify that a model is subscribed to your application, use the subscribed command:

To determine if the model has an active subscription in the billing gateway, use the billingIsActive method. This method would not return true if the model is currently on trial with cardUpFront set to false or if they have canceled and are on their grace period.

You may also determine if the model is still within their trial period (if applicable) using the onTrial method:

To determine if the model was once an active subscriber, but has canceled their subscription, you may use the canceled method:

You may also determine if a model has canceled their subscription, but are still on their "grace period" until the subscription fully expires. For example, if a model subscription is canceled on March 5th that was scheduled to end on March 10th, the model is on their "grace period" until March 10th. Note that the subscribed method still returns true during this time.

The everSubscribed method may be used to determine if the model has ever subscribed to a plan in your application:

To retrieve the customer model associated with a subscription use the customer method:

You may also retrieve an array of subscriptions associated with a customer:

Charges

Creating individual charges on a customer, outside of subscriptions, is also possible.

Creating A Charge

Creating a new charge on a customer is easy:

Note: The amount of a charge is in cents.

To charge on a new credit card token, use the withCardToken method:

You may also specify an existing credit card to use for a charge:

Note: If no card or card_token is specified, the default (initial) card associated with the customer will be used.

Capturing A Charge

Sometimes you may want to preauthorize a charge before you capture it:

You may optionally specify the amount to capture as long as it is less than or equal to the amount preauthorized:

Refunding A Charge

Refunding a charge is also possible:

Or optionally specify an amount to refund:

Working With Charges

You may retrieve an array of all charges for a customer:

Or find the most recent charge for a customer:

Finding a charge from it's ID is also easy:

Charge objects has several properties you might find useful, including: id, created_at, amount, paid, refunded, card, invoice_id, and description.

You may also access the associated invoice object (if available) from a charge:

Webhooks

This package comes bundled with a Webhook controller for each supported gateway, which can handle things such as failed or successful invoice payments, deleted subscriptions, and trial-will-end events.

Handling Webhook Events

To enable these events, just point a route to the appropriate gateway controller:

By default, this package does not try to delete a subscription after a certain number of failed payment attempts. Most billing gateways can do this automatically which would trigger a deleted subscription webhook event. When that happens, we will update our local model to record that change in status.

Handling Other Events

If you have additional webhook events you would like to handle, simply extend the Webhook controller and point the route to your controller.

Model Events

To make it even easier to work with billing-related events, this package will trigger several convenient events on Eloquent models that you can hook into, so you don't have to do everything in the Webhook controller.

For example, to be notified when a model's trail will end, subscribe to the trialWillEnd model method:

Customer Events

There are several customer-related billing events you may subscribe to: customerCreated, customerDeleted, creditcardAdded, creditcardRemoved, creditcardUpdated, creditcardChanged, discountAdded, discountRemoved, discountUpdated, discountChanged, invoiceCreated, invoicePaymentSucceeded, and invoicePaymentFailed.

Subscription Events

There are several subscription-related billing events you may subscribe to: billingActivated, billingCanceled, planSwapped, planChanged, subscriptionIncremented, subscriptionDecremented, billingResumed, trialExtended, trialWillEnd, subscriptionDiscountAdded, subscriptionDiscountRemoved, subscriptionDiscountUpdated, and subscriptionDiscountChanged.

Gateway Limitations

Each billing gateway provides a different API and set of functionality. That being said, not all features are supported by every billing gateway. Here is a high level breakdown of the features NOT supported by each gateway:

Stripe

Braintree

Local Driver

This package comes bundled with a Local gateway driver to simulate talking with a real billing gateway. All data is stored in a SQLite database located in app/storage/meta/billing-local.sqlite.

Adding Plans

To add a subscription plan to the local driver database, use the laravel-billing:local:create-plan Artisan command:

It will prompt you for the plan name, amount, interval, and trial period.

Adding Coupons

To add a coupon to the local driver database, use the laravel-billing:local:create-coupon Artisan command:

It will prompt you for the coupon code, percent_off, amount_off, and duration.

Generating Credit Card Tokens

Even though this is not a real billing gateway, it is designed to simulate how a real gateway would respond. Therefore, you still need to generate a credit card token to attach to a customer or subscription.

To generate a valid token for this driver, simply JSON encode an object of fields you want to store with the credit card. For example:


All versions of laravel-billing with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
illuminate/support Version ~4.1
nesbot/carbon Version ~1.0
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 linkthrow/laravel-billing contains the following files

Loading the files please wait ....