PHP code example of genealabs / laravel-cashier-braintree
1. Go to this page and download the library: Download genealabs/laravel-cashier-braintree 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/ */
genealabs / laravel-cashier-braintree example snippets
public function handle($request, Closure $next)
{
if ($request->user() && ! $request->user()->subscribed('main')) {
// This user is not a paying customer...
return redirect('billing');
}
return $next($request);
}
if ($user->subscription('main')->onTrial()) {
//
}
if ($user->subscribedToPlan('monthly', 'main')) {
//
}
if ($user->subscription('main')->cancelled()) {
//
}
if ($user->subscription('main')->onGracePeriod()) {
//
}
$user = User::find(1);
$user->subscription('main')->incrementQuantity();
// Add five to the subscription's current quantity...
$user->subscription('main')->incrementQuantity(5);
$user->subscription('main')->decrementQuantity();
// Subtract five to the subscription's current quantity...
$user->subscription('main')->decrementQuantity(5);
use App\User;
use Carbon\Carbon;
$user = User::find(1);
$anchor = Carbon::parse('first day of next month');
$user->newSubscription('main', 'premium')
->anchorBillingCycleOn($anchor->startOfDay())
->create($stripeToken);
$user->subscription('main')->cancel();
if ($user->subscription('main')->onGracePeriod()) {
//
}
namespace App\Http\Controllers;
use Braintree\WebhookNotification;
use Laravel\Cashier\Http\Controllers\WebhookController as CashierController;
class WebhookController extends CashierController
{
/**
* Handle a new dispute.
*
* @param \Braintree\WebhookNotification $webhook
* @return \Symfony\Component\HttpFoundation\Responses
*/
public function handleDisputeOpened(WebhookNotification $webhook)
{
// Handle The Webhook...
}
}
// Stripe Accepts Charges In Cents...
$user->invoiceFor('One Time Fee', 500);
// Braintree Accepts Charges In Dollars...
$user->invoiceFor('One Time Fee', 5);