driesvints / sponsors

A package for PHP to interact with GitHub Sponsors.
MIT License
104 stars 6 forks source link

Check sponsorship tiers #3

Open driesvints opened 3 years ago

driesvints commented 3 years ago

With this library it should be possible to check if users are sponsoring through specific tiers. This will allow for even more fine-graned ACL capabilities and perk-granting.

The API would look as something like below. The used token is that of the "driesvints" GitHub account.

// Check if nunomaduro is sponsoring driesvints on the "$5 a month" tier:
$client->hasTier('nunomaduro', '$5 a month');

// Through the Sponsorable trait...
$user->hasTier('$5 a month');

// If the Sponsorable has its own token set and wants to check if they are sponsoring on a specific account:
$user->hasTierOn('$5 a month', 'nunomaduro');

These requests would always need to be made from the viewer's standpoint so the used token will need to be properly set. These API's probably need to be fleshed out some more.

GraphQL field of "tier":

tier {
    closestLesserValueTier {
        name
    }
    createdAt
    isCustomAmount
    isOneTime
    monthlyPriceInCents
    monthlyPriceInDollars
    name
    updatedAt
}

All tiers also have internal ID's on their node through their GraphQL field. But these aren't surfaced in the UI of GitHub Sponsors.