PHP code example of tmyers273 / laravel-stripe-billing
1. Go to this page and download the library: Download tmyers273/laravel-stripe-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/ */
tmyers273 / laravel-stripe-billing example snippets
// Create a customer from token (new default card will be created)
$user->retrieveOrCreateStripeCustomer($token);
$user->retrieveStripeCustomer($token);
// Check if user is already subscribed to product
// Accepts Price object, Product object, string (name of Product or Price) e.g. basic, basic_yearly_90
$user->isSubscribedTo($product);
// Check if user is subscribed to a specific $price
$user->isSubscribedStrictlyTo($price);
// true or false
$user->hasActiveSubscriptions();
// or for subscription
// accepts Price|Product|string (name of Product or Price)
$subscription->isFor($product);
$user->getSubscriptionFor($product)->isActive();
$user->getSubscriptionFor('basic-monthly-10')->cancelNow();
// in the vast majority of cases your users will be only allowed
// to have one active subscription, so use this method when applicable
$user->getFirstActiveSubscription();
// Create the plans
$bronzePlan= Plan::create([
'description' => 'Bronze Plan',
'name' => 'bronze',
]);
// Create the Price
$bronzeMonthly = Price::create([
'product_id' => $bronzePlan->id, // parent plan id
'description' => 'Monthly Bronze Plan',
'name' => 'bronze_monthly_50.00',
'interval' => 'month',
'stripe_product_id' => 'bronze_monthly', // this needs to be created in Stripe first
'price' => 5000,
'active' => true,
]);
// Accepts Plan object or string representing Plan name e.g. bronze_monthly_50.00
$user->subscribeTo($bronzeMonthly); // for already existing stripe customer
$user->subscribeTo($bronzeMonthly, $token); // for user without created customer
// Accepts Plan object
$subscription->changeTo($basicMonthlyPlan);
Subscription::active()->get(); // get all active subscriptions
Subscription::canceledAndArchived()->get(); // get all canceled and non active subscriptions
$user->defaultCard;
$card = $user->addCardFromToken($token);
$user->setCardAsDefault($card);
$user->hasDefaultCard(); //true or false
$user->hasDefaultCard($card); //true or false
$user->removeCard($card);
$card->isOwnedBy($user); // true or false
$card->isDefault(); // true or false
$user->charge(2500); // Charge 25$
$user->chargeByToken(1799, 'some token from stripe.js'); // Charge 17.99$