multiple charging with stripe and laravel

  laravel, queue, stripe-payments

I am trying to charge the customer with stripe first time as a deposit and the second time is after 5 minutes which is the rest of the amount and this is handled by Laravel Queue.But for some reason the second charge is not happening

This is my controller

public function StripeCharge(Request $request) {

        $product_name = $request->product_name;
        $product_price = $request->product_price;

 

    StripeStripe::setApiKey(env('STRIPE_SECRET'));
        $customer = StripeCustomer::create(array(
            "email" => $email = Auth::user()->email,
            "source" => $request->stripeToken
        ));

        $mailInfo = StripeCharge::create(array(
             "amount" => $product_price * 100,
             "currency" => "gbp",
             "customer" => $customer->id,
             "description" => "Deposit" . "-" . $product_name 
        ));

        $customerId = $customer->id;
        $amount = $product_price;


             
  
        $email = Auth::user()->email;
            
          Mail::to($email)->send(new WelcomeMail($mailInfo));

        
        $fullamount =  New ChargeCustomer($customerId,$amount); 


          dispatch(New ChargeCustomer( $fullamount) )->delay(now()->addMinutes(5));
        

        
          
        return view('confirmation');

    }


This is my job CustomerCharge

<?php

namespace AppJobs;

use IlluminateBusQueueable;
use IlluminateContractsQueueShouldQueue;
use IlluminateFoundationBusDispatchable;
use IlluminateQueueInteractsWithQueue;
use IlluminateQueueSerializesModels;
use Stripe;

class ChargeCustomer implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    public $customerId;
    public $amount;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct(string $customerId, int $amount)
    {
       $this->customerId = $customerId;
       $this->amount = $amount;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        StripeCharge::create([
            'amount' => $this->amount,
            'currency'=> 'gbp',
            'customer' => $this->customerId

        ]);

        ChargeCustomer::dispatch('cus_test',1000);
    }
}



any help will be appreciated

Source: Laravel

Leave a Reply