#feminaagravat_39821
1 messages · Page 1 of 1 (latest)
Hello! We'll be with you shortly. Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- feminaagravat_39821, 47 minutes ago, 26 messages
- femina-customer-portal, 18 hours ago, 16 messages
- feminaagravat_39821, 3 days ago, 56 messages
- feminaagravat_39821, 4 days ago, 8 messages
Hi
For security reasons, sessions are short-lived and will expire if the customer does not visit the URL. Create sessions on-demand when customers intend to manage their subscriptions and billing details.
Right now I am using the API
public function getCustomerPortal($stripeCustomerID){
// Authenticate your user.
$session = \Stripe\BillingPortal\Session::create([
'customer' => $stripeCustomerID,
'return_url' => $this->baseURL.'owner/renewal',
'flow_data' =>[
'type'=>'payment_method_update',
'after_completion' => [
'type' => 'redirect',
'redirect' => ['return_url' => $this->baseURL.'owner/renewal?paymentUpdated=true'],
],
]
]);
return $session->url;
}
And I am redirecting User to that URL
How can I start the fresh session for each user ?
Are you there ? Are we connected ?
Yes sorry for the late reply..
How can I start the fresh session for each user ?
First how are you sharing/opening the customer portal with/for the user ?
No I mean how you share the customer portal link with the customer
I do create it using API, the api gives me session->url .
I redirect them through code,
THey have a button , when they click on that button i do call this API to creteCustomer portal session
can you show the full context of how getCustomerPortal is called?
Ok sur
I mean the code.
Ok
This is the controller Code Route
/**
* @Route("/owner/create-customer-portal-session",name="create-customer-portal-session")
*/
public function createCustomerPortalSession(Request $request)
{
$requestData = $request->request->all();
//dump($requestData);exit;
$stripeService = $this->get('frontend.client.stripe');
$entityManager = $this->getDoctrine()->getManager();
$userData = $this->getUser();
$customerId = $requestData["vStripeCustomerId"] ?? $userData->getVStripeCustomerId();
//FIRST CHECK IF CUSTOMER ID IS NOT CREATED THEN CREATE CUSTOMER ID IN BACKGROUND AND USE IT FOR STRIPE CUSTOMER PORTAL
if(empty($customerId)){
try {
$data= [
"email"=>$userData->getVEmail(),
"name"=>$userData->getVFirstName()." ". $userData->getVLastName()
];
$customer = $stripeService->createCustomer($data);
$customerId = $customer->id;
$userObj = $entityManager->getRepository(User::class)->find($userData->getId());
$userObj->setVStripeCustomerId($customerId);
$userObj->setDtUpdated();
$entityManager->persist($userObj);
$entityManager->flush();
} catch (\Throwable $th) {
dump($th);exit;
//throw $th;
}
}
$url = $stripeService->getCustomerPortal($customerId);
$returnArr["url"] = $url;
if(empty($requestData["vStripeCustomerId"]) && !empty($requestData['ajaxCustPortal'])){
return new JsonResponse($returnArr);
}else{
// Redirect to the customer portal.
header("Location: " . $url);
exit();
}
}
public function getCustomerPortal($stripeCustomerID){
// Authenticate your user.
$session = \Stripe\BillingPortal\Session::create([
'customer' => $stripeCustomerID,
'return_url' => $this->baseURL.'owner/renewal',
]);
return $session->url;
}
ok, and the frontend code that invokes this create-customer-portal-session URL and handles the result, can you share that too?
yes
<p> Stripe.com securely stores all payment information which will be used for future billings.<br>
<a href="{{ url('create-customer-portal-session') }}"><i class="fa fa-solid fa-arrow-right"></i> Manage Auto Renewal payment details on Stripe.com.</a>
</p>
hmm your backend code doesn't seem to match what that expects
though maybe I'm wrong
I don't know what this url(..) function is or how that works, what is that?
also, in the backend code you have this
if(empty($requestData["vStripeCustomerId"]) && !empty($requestData['ajaxCustPortal'])){
return new JsonResponse($returnArr);
}else{
// Redirect to the customer portal.
header("Location: " . $url);
exit();
which of this if-branches do you expect to be happening?
header("Location: " . $url);
exit();
this line redirect users to stripe customer portal.
I am getting this $url from stripe API response, \Stripe\BillingPortal\Session::create() this function return the short-lived url , so i have used this as return value and assinged it to $url.
url() is twig function which generate the full path url from routing name.
if you're doing a redirect then it seems confusing to me to have this <a> tag