mirror of
https://github.com/anikeen-com/id.git
synced 2026-11-06 15:48:36 +00:00
Add checkout sessions and webhook event type constants
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a0470111fa
commit
3acd36ca29
12 files changed
+708
-7
No files matched your search
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Anikeen\Id\Resources;
|
||||
|
||||
use Anikeen\Id\Concerns\HasBillable;
|
||||
use Anikeen\Id\Contracts\Billable;
|
||||
use Anikeen\Id\Exceptions\ResourceException;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Checkout sessions of the signed-in user, with the user's access token (any app): several
|
||||
* subscriptions the user confirms together on Anikeen ID. Nothing is requested until a method is
|
||||
* called.
|
||||
*/
|
||||
class CheckoutSessions
|
||||
{
|
||||
use HasBillable;
|
||||
|
||||
public function __construct(Billable|Model $billable)
|
||||
{
|
||||
$this->billable = $billable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a checkout session with new subscriptions and/or existing drafts of the app
|
||||
* (`['id' => …]`); see AppCheckoutSessions::create() for the attributes (no user_id here,
|
||||
* vat_rate only for trusted apps).
|
||||
*
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function create(array $attributes): CheckoutSession
|
||||
{
|
||||
return (new CheckoutSession(fn () => $this->billable->anikeenId()
|
||||
->request('POST', 'v1/checkout-sessions', $attributes)))
|
||||
->setBillable($this->billable);
|
||||
}
|
||||
|
||||
/**
|
||||
* A session the app created for the user; null when it doesn't exist.
|
||||
*
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function find(string $id): ?CheckoutSession
|
||||
{
|
||||
try {
|
||||
return (new CheckoutSession(fn () => $this->billable->anikeenId()
|
||||
->request('GET', sprintf('v1/checkout-sessions/%s', $id))))
|
||||
->setBillable($this->billable);
|
||||
} catch (ResourceException $e) {
|
||||
if ($e->getCode() === 404) {
|
||||
return null;
|
||||
}
|
||||
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user