cartalyst / stripe-laravel

Cartalyst Stripe package integration for Laravel.
BSD 3-Clause "New" or "Revised" License
335 stars 57 forks source link

Sometimes I get the card to be charged multiple times instead of only one #57

Closed yamenshahin closed 4 years ago

yamenshahin commented 4 years ago

Your Environment

Expected behavior

Charge card one time only

Actual behavior

Sometimes it charge card more than one time.

Steps to reproduce


       try {
            $charge = Stripe::charges()->create([
                'currency' => 'GBP',
                'amount'   => $request->amount,
                'source' => $request->stripeToken,
                'receipt_email' => env('RECEIPT_EMAIL', 'info@xxx.com'),
                'metadata' => [
                    'job_id' => $request->id,
                ], 

            ]);
            // save this info to your database
            JobController::setStatus($request->id, 'booked');
            JobController::setMeta($request->id, 'paymentMethod', 'credit'); 

            // If new user
            if($request->customerEmail)  {
                JobController::setCustomer($request->id, $request->customerEmail);
            }

            //send book emails
            EmailBookController::send($request->id);

            // SUCCESSFUL
            return 'success';
        } catch (CardErrorException $e) {
            // save info to database for failed
            return response()->json([
                'error' => [
                    'message' => $e->getMessage()
                ]
                ], 422);
        }`

*If your issue requires any specific steps to reproduce, please outline them here.*
brunogaspar commented 4 years ago

Hello

Without knowing much about how you're triggering the code above, i have to assume you have a form with a submit button, that when pressed reaches the code above that i assume that's inside a controller.

Do you block the form from being sent twice in a row? That's the only explanation for such "bug".

Without a consistent way for me to reproduce the problem i have to assume the problem to be within your application, like the user clicking the submit button twice, because you don't disable the submit button.