Hi there,
I know a global variable should be initialized by contractor. what if need to init a global variable inside one function and access it in another function.
this is my first function
public $customerId;
public function store(CheckoutRequest $request)
{
try {
$customer = Stripe::customers()->create([
'source' => $request->stripeToken,
'email' => $request->email,
'description' => $request->name
]);
$this->customerId = $customer->id;
$this->chargeCustomer($request, $customer->id);
return redirect()->route('shipper.payment')->with('success_message', 'Thank you! your payment was successfull.');
} catch (Exception $e) {
return back()->withErrors('Error! ' . $e->getMessage());
}
}
this is my second function
public function paymentDetails()
{
return $this->customerId;
}
I'm creating customer in Stripe and assign created customer id to $customerId global variable, I need $customerId insid paymentDetails function which gets calling by another route, but paymentDetails return null.
could anyone help please, how to get customer id in other functions?