I have a function a stripe function that slashes the price of a product, and I am trying to charge the newly slashed price after 5 minutes.
in my checkoutController I have
public function secondHalf($id){
// fetch the price
$productprice = Product::where('id', $id)
->pluck('price')
->firstOrFail();
// slash price into half
$slashPrice = intdiv($productprice,2); // divide by 2
// commence payment
\Stripe\Stripe::setApiKey(config('stripe.sk'));
$session = \Stripe\Checkout\Session::create([
'line_items' => [
[
'price_data' => [
'currency' => 'gbp',
'product_data' => [
'name' => 'tax online payment',
],
'unit_amount' => $slashPrice*100,
],
'quantity' => 1,
],
],
'mode' => 'payment',
'success_url' => route('success'),
'cancel_url' => url('/single-product/'.$id),
]);
$details = ['email' => 'thomsontochi@gmail.com'];
$emailJob = (new AfterPayment($details))
->delay(Carbon::now()
->addMinutes(5));
dispatch($emailJob);
return redirect()->away($session->url);
}
it basically find the product, slash the price and I then charge the slashed price.
I have tried making a job , called LatePaymentCharge and I took the function that handles the charge to the job like so
public function handle()
{
$slashPrice = $this->slashPrice;
//dd('stipe checkout');
\Stripe\Stripe::setApiKey(config('stripe.sk'));
$session = \Stripe\Checkout\Session::create([
'line_items' => [
[
'price_data' => [
'currency' => 'gbp',
'product_data' => [
'name' => 'staxo online payment',
],
'unit_amount' => $slashPrice*100,
],
'quantity' => 1,
],
],
'mode' => 'payment',
'success_url' => route('success'),
// 'cancel_url' => url('/single-product/'.$id),
]);
return redirect()->away($session->url);
}
I am currently having issues on how to pass the slash price value from my checkoutController to my job and im not sure if this is the right way to do it . please help