mirror of
https://github.com/anikeen-com/id.git
synced 2026-11-06 23:58:35 +00:00
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:
5 files changed
+134
No files matched your search
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user