2017 © Pedro Peláez
 

silverstripe-vendormodule silverstripe-stripewebhook

A delegation interface for handling Stripe webhook events

image

vulcandigital/silverstripe-stripewebhook

A delegation interface for handling Stripe webhook events

  • Tuesday, February 27, 2018
  • by vulcandigital
  • Repository
  • 2 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

silverstripe-stripewebhook

This module is a Stripe webhook event handling delegation interface, a subclass can handle one or more event and an event can be handled by one or more subclass, (*1)

Requirements

  • silverstripe/framework: ^4

Configuration

Vulcan\StripeWebhook\StripeWebhook:
  secret_key: "your-live-secret-key"
  endpoint_secret: "your-endpoint-live-secret-key

You can also use test keys and the webhook simulator will work fine with this module, (*2)

Usage

  1. Install and dev/build
  2. Add a webhook endpoint to Stripe that points to https://yourdomain.com/stripe-webhook and ensure that it sends the events you require
  3. Create your functionality for your event(s):
<?php
use Stripe\Event;
use Vulcan\StripeWebhook\Handlers\StripeEventHandler;
use SilverStripe\Security\Member;

class CustomerEventsHandler extends StripeEventHandler
{
    private static $events = [
        'customer.created',
        'customer.deleted'
    ];

    public static function handle($event, Event $data)
    {
        // $event is the string identifier of the event
        if ($event == 'customer.created') {
            // create member
            return "Member created";        
        }

        $member = Member::get()->filter('Email', $event->data->object->email)->first();

        if (!$member) {
            return "Member did not exist";
        }

        $member->delete();
        return "Member deleted";
    }
}

Any subclass of StripeEventHandler is detected and requires both the private static $events and public static function handle($event, $data) to be defined., (*3)

private static $events must be defined and can be a string containing a single event identifier or an array with multiple, (*4)

public static function handle($event,$data) must be defined and should not call the parent. $data will be a \Stripe\Event object which has the exact same hierarchy as the JSON response depicted in their examples., (*5)

Features

  • All handled events are logged, along with the responses from their handlers.
  • Duplicates are ignored, if Stripe sends the same event more than once it won't be processed, but the logged event will count the occurence
  • All events are verified to have been sent from Stripe using your endpoint_secret you defined in the configuration above

Why?

Easily introduce new event handling functionality without needing to touch any files relating to other event handling classes., (*6)

License

BSD-3-Clause - Vulcan Digital Ltd, (*7)

The Versions

27/02 2018

dev-master

9999999-dev

A delegation interface for handling Stripe webhook events

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

27/02 2018

1.0.0

1.0.0.0

A delegation interface for handling Stripe webhook events

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires