Change event data object pattern

Created on 2 November 2023, over 1 year ago

Problem/Motivation

The current event pattern followed by dispatcher events is to supply the Stripe Event for the named class event type:

   * @param \Drupal\stripe_webhooks\Event\SubscriptionEvent $event
   */
  public function notifyNewSubscription(SubscriptionEvent $event) {
    try {
      // Get the Stripe event.
      $subscription = $event->getSubscription();
      ...
      $message[] = 'Quantity: ' . $subscription->__get('data')['object']['quantity'];

The Stripe event object should be named a Stripe event, and the documented data object should also be made available.

Proposed resolution

Change the implementation throughout the Event classes such that the following would be true:

   * @param \Drupal\stripe_webhooks\Event\SubscriptionEvent $event
   */
  public function notifyNewSubscription(SubscriptionEvent $event) {
    try {
      // The Drupal EventDispatcher Event.
      // $event

      // Get the Stripe event.
      $stripe_event = $event->getStripeEvent();

      // Get the Subscription object.
      // The named data object is available via a getter.
      $subscription = $event->getSubscription();
      ...
      $message[] = 'Quantity: ' . $subscription->quantity;

Remaining tasks

TBD

API changes

This is obviously a breaking change, but such a change makes sense for the major version bump to 2.0.x.

Data model changes

TBD

✨ Feature request
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States jcandan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @jcandan
  • πŸ‡ΊπŸ‡ΈUnited States jcandan
  • πŸ‡ΊπŸ‡ΈUnited States jcandan

    Since we've already release a Beta, and considering the docs β†’ suggests that, in

    Beta releases...APIs are frozen enough so that contributed module and theme authors can start upgrading their projects.

    I would normally suggest this requires a bump to 2.1.x. However, considering our current usage stats for 2.0.x, what say we keep the current version when we adopt this API change?

  • First commit to issue fork.
Production build 0.71.5 2024