Search code examples
laravellaravel-cashier

Laravel Cashier Single Charge does it is suitable for this task


I want to charge the customer 1 euro whenever he wants to do the calculations offered in my system. Every time the customer wants to perform the calculations again, he will have to pay 1 euro again. Would a Laravel Cashier single charge be suitable for such a task or I should choose a simple Stripe SDK?


Solution

  • Yes, you can do this with the Cashier package.

    First, the user should set up a payment method.

    return view('update-payment-method', [
        'intent' => $user->createSetupIntent()
    ]);
    

    And then in your view:

    <input id="card-holder-name" type="text">
    
    <!-- Stripe Elements Placeholder -->
    <div id="card-element"></div>
    
    <button id="card-button" data-secret="{{ $intent->client_secret }}">
        Update Payment Method
    </button>
    

    Then, you can charge the user every time you want to make a calculation.

    // The amount is in cents. 100 = 1 euro
    $stripeCharge = $user->charge(
      100, $user->defaultPaymentMethod()
    );
    

    You can view the docs for more details.