1. Go to this page and download the library: Download linkthrow/laravel-billing 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/ */
linkthrow / laravel-billing example snippets
use LinkThrow\Billing\CustomerBillableTrait;
class User extends Eloquent
{
use CustomerBillableTrait;
}
public function subscriptionmodels()
{
// Return an Eloquent relationship.
return $this->hasMany('Website');
// Or, return an array or collection of models.
return Website::where('user_id', $this->id)->get();
// Or, return an array of collections.
return array(
Website::where('user_id', $this->id)->get(),
Domain::where('user_id', $this->id)->get(),
);
}
use LinkThrow\Billing\SubscriptionBillableTrait;
class Website extends Eloquent
{
use SubscriptionBillableTrait;
}
public function customermodel()
{
// Return an Eloquent relationship.
return $this->belongsTo('User', 'user_id');
// Or, Return an Eloquent model.
return User::find($this->user_id);
}
// Get all customer credit cards.
$cards = $user->creditcards()->get();
// Get the first card for a customer.
$card = $user->creditcards()->first();
// Find a card by it's ID.
$card = $user->creditcards()->find('card_id');
echo $card->id;
echo "{$card->brand} xxxx-xxxx-xxxx-{$card->last4} Exp: {$card->exp_month}/{$card->exp_year}"
$website->subscription()->increment();
// Add five to the subscription's current quantity...
$website->subscription()->increment(5);
$website->subscription()->decrement();
// Subtract five from the subscription's current quantity...
$website->subscription()->decrement(5);
class WebhookController extends LinkThrow\Billing\Gateways\Stripe\WebhookController
{
public function handleChargeDisputeCreated($payload)
{
// Handle The Event
}
}
Website::trialWillEnd(function ($website, $args = array()) {
Log::info('Trial will end in ' . array_get($args, 'days') . ' day(s).');
});