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

Mithrandir69's avatar

How to send stripe payment informations to database when success

I want to send the payment datas to the database after the payment : here is my code :


       <script src = "https://checkout.stripe.com/checkout.js" > </script>
       <script type = "text/javascript">
           $(document).ready(function() {
               $.ajaxSetup({
                   headers: {
                       'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                   }
               });
           });

       $('.btn-block').click(function() {
         var amount = $('.amount').val();
         var handler = StripeCheckout.configure({
             key: '{{env('STRIPE_KEY')}}', //your publisher key id
             locale: 'auto',
             token: function(token) {
                 //You can access the token ID with `token.id`.
                 //Get the token ID to your server-side code for use.
                 $('#res_token').html(JSON.stringify(token));
                 $.ajax({
                     url: '{{ url("payment-process") }}',
                     method: 'post',
                     data: {
                         tokenId: token.id,
                         amount: 27
                     },
                     success: (response) => {
                         console.log(response)
                     },
                     error: (error) => {
                         console.log(error);
                         alert('Oops! Something went wrong')
                     }
                 })
             }
         });
         handler.open({
             name: 'Payment Demo',
             description: 'NiceSnippets',
             amount: amount * 100
         });
       })

       </script>

This is my Controller:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Payment;
use Stripe;

class StripePaymentController extends Controller
{
    public function index()
    {
       return view('stripe');
    }

    public function process(Request $request)
    {
  		\Log::info($request->all());
        $stripe = Stripe::charges()->create([
            'source' => $request->get('tokenId'),
            'currency' => 'USD',
            'amount' => $request->get('amount')
        ]);

        return $stripe;
    }


}

i already have the payments table and model , so how please to send the user's payment informations to database

0 likes
3 replies

Please or to participate in this conversation.