Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Shedman's avatar

Collecting Payments

I created a site that has customers. The users create customers and then contracts that belong to the customers. I need to for the users to collect payment (both recurring and single) for the contracts. I am supposed to use stripe. Looking at the stripe documentation it appears that the customers have to be users in order to do that payment. Is there a way to collect payments without a contract without having the customers as users? Hope this makes sense.

0 likes
12 replies
Shedman's avatar

Thanks, but the one-time payment won't work because each transaction will be a different price. Laravel has Cashier, but it seems to rely on a user being set up for each transaction. Is there a way to use Cashier with out having it tied to a user?

Shedman's avatar

It is a site for shed dealers to create rental contracts. Users create customers and their contracts then they need to take payments for the contracts. Single payment for the initial payment and then if the customer wants it taken out every month a recurring payment needs to be setup.

I had this all working with Authorize.net but then they switched it to Stripe and I am trying to figure out the best route. I started to change it to the customer as being a user type to use Cashier, but then I have to prevent these users from accessing the site. That opened up a whole new complexity. They really aren't meant to be users.

martinbean's avatar

You can have “billable” entities that don’t log in.

All Cashier requires you to do is to put a trait on a model, and that model’s table in the database to have a number of columns (stripe_id etc). This will allow you to create “customer” models in your application, as well as customer models in Stripe, that you can then charge or subscribe to subscription plans.

Shedman's avatar

I am really new to Laravel, can you point me to where I can learn about adding a trait to a model?

martinbean's avatar

@shedman The process is described in the Cashier documentation: https://laravel.com/docs/8.x/billing#billable-model

If you’re not familiar with what traits are, I’d maybe suggest doing some basic PHP tutorials as well to get familiar with its concepts, as a trait is a basic programming language feature and not something Laravel-specific.

1 like
jlrdw's avatar

I'm not 100% sure about stripe , but I know that payment gateways like PayPal you can pay with a charge card without having to sign up or be a user. Surely stripe has a way to make a payment without being a logged in user.

I would also suggest checking things like stack overflow for similar scenarios.

but yes if you can work it out with cashier by all means do that.

Look at Stripes forums. Check with their staff. when I'm programming something new I'll try to reach out to as many resources as possible, I even had lessons from a certified public accountant before programming for a non-profit.

so definitely just don't ask here, do much more research.

1 like
PaulMaxOS's avatar

I believe one can use cashier without having a user as billable object:

https://laravel.com/docs/8.x/billing#billable-model

Cashier is assuming that it’s the user model which is billable but you can actually define that in the .env

So changing environment and using the billable trait on the model of your choice should get you going

Shedman's avatar

Following the Cashier documentation, I have tried to change it to my customer model.

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Models\Contracts;
use Laravel\Cashier\Billable;


class Customers extends Model
{
    use HasFactory;
    use Billable;

    protected $guarded = [];

    public function user() {

        return  $this->belongsTo('App\Models\User'); // where customer belongs to user with id
    }

    public function contracts() {

        // get the contracts for this user
        return $this->hasMany(Contracts::class); // example SELECT * contracts where customer_id = this customer
    }
    
}

Then I found that I had to download the migrations for Cashier in the vendor according to this; https://laravel.com/docs/8.x/billing#installation

php artisan vendor:publish --tag="cashier-migrations"

I changed vendor/laravel/cashier/database/migration to customer table.

<?php

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

class CreateCustomerColumns extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('customers', 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('customers', function (Blueprint $table) {
            $table->dropColumn([
                'stripe_id',
                'card_brand',
                'card_last_four',
                'trial_ends_at',
            ]);
        });
    }
}

Also, I updated the vendor/laravel/cashier/config/casher.php

vendor/laravel/cashier/

I also added this to the .env file.

CASHIER_MODEL=App\Models\Customer

I ran migration:fresh and it still has the Cashier items in the user table, not the customer table. Stuck!

jlrdw's avatar

The people who get paid is your users. Don't let terms throw you off.

The people paying them are their customers. Just work it out where you use laravel conventions.

Please or to participate in this conversation.