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

trevorpan's avatar

Can you suggest a proper response at endpoint for Stripe charges?

Hi,

Have been working on this payment gateway for some time, and finally have it working!!!

However, when the payment goes through, the website goes away and this is the response I'm getting (on a black screen).

user_id 1
confirmation_number "84HLU8UAZ4SJTUA5DULZMHUE"
amount  500
card_last_four  "4242"

The controller:

   public function store($jobId)
    {

        $job = Job::incomplete()->findOrFail($jobId);

        $this->validate(request(), [
            'amount' => ['required', 'integer', 'min:1'],
            'stripeToken' => ['required']
        ]);

        // Charging the customer
        try {
            $bidReserve = $job->bidReserves()->create([
                'amount' => 500,
                'job_id' => $jobId,
            ]);

            $order = $bidReserve->complete($this->paymentGateway, request('stripeToken'), auth()->user()->id);

            DB::transaction(function () use($order) {
                DB::table('bidreserves')->update(['order_id' => $order->id]);
            });

            Mail::to($order->user->email)->send(new OrderConfirmationMail($order));

            return response()->json($order, 201);
//            return view('jobs.jobfull', compact('order', 'job', 201));

        } catch (PaymentFailedException $e) {
            return response()->json([], 422);
//            return view('jobs.jobfull', compact([], 'job', 422));
        }

I feel like it should return back() to the jobs page, but what I tried above seems to interfere with the JobsController.

//form
<div class="bidReserve">

<form id="payment-form" action="/jobs/{{ $job->id }}/bidreserve" method="post">
    @csrf
     <input type="hidden" id="amount" name="amount" value="500">
//<input type="hidden" name="stripeToken" value=""/>
      <label for="card-element">
//Credit or debit card
      </label>
       <div id="card-element">
// A Stripe Element will be inserted here.//id="card-element" &ndash;&gt;--}}
        </div>

// &lt;!&ndash; Used to display form errors. &ndash;&gt;--}}
        <div id="card-errors" role="alert"></div>

         <button>Bid Reserve</button>
          </form>
 </div>
0 likes
0 replies

Please or to participate in this conversation.