1. Go to this page and download the library: Download ridho/justsubs 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/ */
ridho / justsubs example snippets
use Ridho\JustSubs\JustSubs;
public function boot()
{
JustSubs::auth(function ($request) {
return in_array($request->user()?->email, [
'[email protected]',
'[email protected]',
]);
});
}
namespace App\Models;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Ridho\JustSubs\Concerns\HasSubscriptions;
class User extends Authenticatable
{
use HasSubscriptions;
}
use Ridho\JustSubs\Models\Plan;
use Ridho\JustSubs\Enums\IntervalUnit;
$plan = Plan::create([
'name' => 'Pro Monthly',
'slug' => 'pro-monthly',
'description' => 'Full access on a monthly basis.',
'price' => 150000, // Stored in smallest unit (e.g., IDR or Cents)
'currency' => 'IDR',
'interval_count' => 1,
'interval_unit' => IntervalUnit::Month,
'is_active' => true,
]);
use Ridho\JustSubs\Services\SubscriptionManager;
$manager = app(SubscriptionManager::class);
// Activates immediately and sets the ends_at date
$subscription = $manager->subscribe($user, $plan);
if ($user->subscribed()) {
// Has an active subscription
}
if ($user->subscribedTo('pro-monthly')) {
// Specifically subscribed to the 'pro-monthly' plan slug
}
$manager->renew($subscription);
use Ridho\JustSubs\Enums\IntervalUnit;
// Extends the subscription by 5 days
$manager->extend($subscription, 5, IntervalUnit::Day, 'Apology for server downtime');
// Graceful cancellation (status stays Active until ends_at)
$manager->cancel($subscription, immediately: false);
// Immediate termination
$manager->cancel($subscription, immediately: true);
use Ridho\JustSubs\Services\BillingManager;
$billing = app(BillingManager::class);
$invoice = $billing->createInvoice(
subscriber: $user,
amount: 150000,
currency: 'IDR',
subscription: $subscription // Link it to activate/renew upon payment
);
use Ridho\JustSubs\Services\PaymentDrivers\ManualPaymentDriver;
$driver = new ManualPaymentDriver();
$billing->processPayment($invoice, $driver, $amount = 150000, 'IDR', [
'reference' => 'Bank Transfer TXN-12345'
]);
use Ridho\JustSubs\JustSubs;
JustSubs::extendPaymentDriver('midtrans', function () {
return new \App\Services\MidtransDriver();
});
bash
php artisan justsubs:install
bash
php artisan migrate
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.