Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pluggable "Benefits" API #3

Open
AugustMiller opened this issue Jan 4, 2022 · 0 comments
Open

Pluggable "Benefits" API #3

AugustMiller opened this issue Jan 4, 2022 · 0 comments

Comments

@AugustMiller
Copy link
Member

AugustMiller commented Jan 4, 2022

This is likely a separate feature from Grants—and maybe best suited for a different plugin, entirely.

The notion of "Benefits" here is something that is made available either for the duration of a subscription (perhaps a Grant, in the case of the existing plugin), or an artifact created as part of the renewal process.

Could make #1 a pluggable (or even CP-managed) thing—especially with Craft 4's new Condition Builder coming down the pipeline!

Examples

Grant

A new class Grant implements BenefitInterface or class Grant extends Benefit (TBD) might be registered and have its own handlers for Subscription events (Create, Renew, Expire, etc.)

// Unsure about `implements`, here, or what kind of interfaces we'd have to provide!
class Grant extends Benefit implements TemporalGate
{
    public function events()
    {
        return [
            // Grant a group...
            self::EVENT_ON_SUBSCRIPTION_START => [$this, 'onSubscriptionStart'],
            // ...or revoke it:
            self::EVENT_ON_SUBSCRIPTION_END => [$this, 'onSubscriptionEnd'],
        ];
    }

    // ...
}

Coupon

Monthly one-time-use Commerce coupon (i.e. for a snack service), emitted from the renewal lifecycle.

class Grant extends Benefit implements RecurringArtifact
{
    public function events()
    {
        return [
            // Create a coupon record with a unique code (or no code, and let it be automatically consumed with their Order):
            self::EVENT_ON_SUBSCRIPTION_RENEW => [$this, 'onSubscriptionRenew'],
        ];
    }

    // ...
}

Daily Digest

A frequent CRON task/clock could trigger things at a given "while subscribed" tick/interval? Say, "every n days at `time," send an email, sync the User's content with an external service, etc.

class Grant extends Benefit implements ScheduledService
{
    public function events()
    {
        return [
            // “Ticks” every [[DateInterval expression]]? Not a Stripe concept. Emit a job, or otherwise collect content at that moment to deliver:
            self::EVENT_ON_SUBSCRIPTION_TICK => [$this, 'onSubscriptionTick'],
        ];
    }

    // ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant