driesvints / sponsors

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

Automatically grant and revoke perks #7

Open driesvints opened 2 years ago

driesvints commented 2 years ago

One of the bigger features I'd like to develop over time for this library is the ability to automatically grant and revoke perks. The way that this would work is that the library would offer a common interface for granting and revoking perks as well as an integration with either GitHub Webhooks or the Laravel Scheduler to check periodically for updates and then handle revoking or granting perks.

The actual implementations of whatever perk would be a custom implementation for the consumer of the library. This would open the door for an entire ecosystem of perks like a collection of integrations with different services and what not.

The interface would look as follows:

interface Perk
{
    public function grant(): bool;
    public function revoke(): bool;
    public function tiers(): array;
}

A practical example could be to grant access to a Discord server when you're sponsoring someone:

final class DiscordServerPerk implements Perk
{
    public function grant(): bool
    {
        // handle the logic to grant access to the server...
    }

    public function revoke(): bool
    {
        // handle the logic to revoke access to the server...
    }

    public function tiers(): array
    {
        // return the tiers that allow access to this perk...
    }
}

By returning the tiers that allow access to the perk the library should be able to automatically grant or revoke the perk depending when a user is changing tiers. If they're changing to a new tier that's also in the tiers list of the perk, nothing would change of course.

This idea is a little rough and there's probably tons of edge cases but it would be worth to explore a PoC for this.