I am exploring the possibility of implementing a Stripe Customer Portal (https://stripe.com/docs/billing/subscriptions/customer-portal) using the Stripe PHP API (https://stripe.com/docs/billing/subscriptions/integrating-customer-portal).
The Portal call would be made available on a button once users are authenticated so that customer IDs can be retrieved from external DB using the session's log-in credentials.
form method="POST" action="/customer_portal.php"
Action would run the following command nested in the PHP file. This snippet sends a POST request to Stripe servers and triggers a response from Stripe servers which contains 7 attributes:
POST Request
\Stripe\Stripe::setApiKey('secret_key');
\Stripe\BillingPortal\Session::create([
'customer' => 'customer_id'
]);
Response Body
{
"id": "portal_session_X",
"object": "billing_portal.session",
"created": 2569878511,
"customer": "customer_id",
"livemode": false,
"return_url": "https://example.com/account",
"url": "https://billing.stripe.com/session/{SESSION_SECRET}"
}
The next step is to fetch the "URL" attribute contained in the response body and use it to redirect the user to his/her customized Customer Portal. I am having trouble with this step.
Any help would be greatly appreciated! Thanks a lot.