renoki-co / jetstream-cashier-billing-portal

Cashierstream is a simple Spark alternative written for Laravel Jetstream, with the super-power of tracking plan quotas, like seats or projects number on a per-plan basis
Apache License 2.0
163 stars 20 forks source link

Prevent Upgrade Downgrade Plans #8

Closed vmiguellima closed 3 years ago

vmiguellima commented 3 years ago

@rennokki Congrats on this Amazing Package!

Is there any way to prevent user from upgrade downgrade at any time?

rennokki commented 3 years ago

@vmiguellima This seems like a great feature. I'll look into this in the upcoming days. 😁

vmiguellima commented 3 years ago

@rennokki I really enjoy this package! Is there any way I can help?

vmiguellima commented 3 years ago

Other thing that I would do is to add the following migrations:

add_team_id_column_to_subscriptions_table and add_customers_columns_to_teams_table

add_team_id_column_to_subscriptions_table:

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddTeamIdColumnToSubscriptionsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('subscriptions', function (Blueprint $table) {
            $table->unsignedBigInteger('team_id')->index();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('subscriptions', function (Blueprint $table) {
            $table->dropColumn('team_id');
        });
    }
}

Table add_customers_columns_to_teams_table:

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddCustomersColumnsToTeamsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('teams', function (Blueprint $table) {
            $table->string('stripe_id')->nullable()->index();
            $table->string('card_brand')->nullable();
            $table->string('card_last_four', 4)->nullable();
            $table->timestamp('trial_ends_at')->nullable();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('teams', function (Blueprint $table) {
            $table->dropColumn([
                'stripe_id',
                'card_brand',
                'card_last_four',
                'trial_ends_at',
            ]);
        });
    }
}

So we can easily use team as our billable model (as showed in docs):

 BillingPortal::setBillableOnRequest(function (Request $request) {
            return $request->user()->currentTeam;
});
stale[bot] commented 3 years ago

This issue has been automatically closed because it has not had any recent activity. 😨