Create billing portal links for users as a trusted app

AnikeenId::createBillingPortalLinkForUser() and $user->appBillingPortalUrl()
create a short-lived link to a user's billing pages with the app's token
(return_url, group, flow), e.g. for a Manage billing button of an app
that bills a team owner's account.
This commit is contained in:
Maurice Preuß committed 2026-11-04 21:27:26 +01:00
1 parent e45a871ca7
commit 35ca9ddd2b
5 files changed
+134

No files matched your search

+17
View File
@@ -2,6 +2,8 @@
namespace Anikeen\Id\Concerns;
use Anikeen\Id\AnikeenId;
use Anikeen\Id\Exceptions\ApiException;
use Anikeen\Id\Resources\AppCheckoutSessions;
use Anikeen\Id\Resources\AppOrders;
use Anikeen\Id\Resources\AppSubscriptions;
@@ -65,4 +67,19 @@ trait ManagesSubscriptions
{
return new AppOrders($this);
}
/**
* A short-lived link to the user's billing pages on Anikeen ID, created with the app's own
* token (trusted apps only, scope subscriptions:client or orders:client), e.g. for a "Manage
* billing" button; see AnikeenId::createBillingPortalLinkForUser() for the attributes
* (return_url, group, flow). Create it when the user clicks, it expires after about 15 minutes.
*
* @param array{return_url?: null|string, group?: null|string, flow?: null|string} $attributes
*
* @throws ApiException
*/
public function appBillingPortalUrl(array $attributes = []): string
{
return app(AnikeenId::class)->createBillingPortalLinkForUser($this->appSubscriptions()->userId(), $attributes)->url;
}
}