1
1 Comment

Any Laravel Cashier users here?

I've seen a few people on here are working with Larvel for SaaS and similar applications, which likely means they're using Cashier.

After some playing with Cashier, I've noticed it has no support for free plans. The reason being you have to submit a Stripe token when creating a free plan, and obviously you won't have one.

Interested to hear how other Laravel developers have gotten around this snag, or what packages they've used instead of Cashier or Spark?

on July 12, 2019
  1. 1

    I haven't run into the exact situation you mention, but I was planning to use Cashier as well for a project awhile ago and noticed that it didn't fit my situation either. I'm sure its nice in certain instances, but its basically just a wrapper on top of the Stripe PHP class. You can always just use the Stripe API directly to match your situation.

    Here's some demo code, not sure if its helpful to get you started:

    //Use the config for the stripe secret key
    \Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));
    
    // Create the customer on Stripe's servers
    try {
        $customer = \Stripe\Customer::create([
            "description" => $request->organization,
            "name" => $request->name,
            "email" => $request->email,
            "source" => $request->token // obtained with Stripe.js
        ]);
    } catch(\Stripe\CardError $e) {
        $e_json = $e->getJsonBody();
        $error = $e_json['error'];
        // The card has been declined
        // redirect back to checkout page
        return back()->with('stripe_errors',$error['message']);
    }
    
    // Create the charge on Stripe's servers - this will charge the user's card
    try {
        $subscription = \Stripe\Subscription::create([
            'customer' => $customer->id,
            'items' => [['plan' => $plan_id]],
        ]);
    } catch(\Stripe\CardError $e) {
        $e_json = $e->getJsonBody();
        $error = $e_json['error'];
        // The card has been declined
        // redirect back to checkout page
        return back()->with('stripe_errors',$error['message']);
    }