Download the PHP package samandeggs/silverstripe-stripewebhook without Composer
On this page you can find all versions of the php package samandeggs/silverstripe-stripewebhook. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download samandeggs/silverstripe-stripewebhook
More information about samandeggs/silverstripe-stripewebhook
Files in samandeggs/silverstripe-stripewebhook
Package silverstripe-stripewebhook
Short Description A delegation interface for handling Stripe webhook events. Forked from vulcandigital/silverstripe-stripewebhook.
License BSD-3-Clause
Informations about the package silverstripe-stripewebhook
silverstripe-stripewebhook
Fork from vulcandigital/silverstripe-stripewebhook to update its use in a few ways:
- Replace yml configuration with .env variables
- Updated version of
stripe/stripe-php
and updated composer.json - Support multiple stripe accounts
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
Requirements
- silverstripe/framework: ^4
- stripe/stripe-php: ^7.43
Configuration
replace <key>
, and write within the ""
.
You can also use test keys and the webhook simulator will work fine with this module
Usage
- Install and dev/build
- Add a webhook endpoint to Stripe that points to https://yourdomain.com/stripe-webhook and ensure that it sends the events you require
- Create your functionality for your event(s):
Any subclass of StripeEventHandler
is detected and requires both the private static $events
and public static function handle($event, $data)
to be defined.
private static $events
must be defined and can be a string containing a single event identifier or an array with multiple
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.
Handling multiple Stripe accounts
If you would like to utilize more than one Stripe account, you need to make two changes. The first is so enter both or more sets of env vars in the following format:
STRIPE_<NAME>_SECRET
eg.STRIPE_STANDARD_SECRET
andSTRIPE_SECONDARY_SECRET
STRIPE_<NAME>_WEBHOOK_SECRET
eg.STRIPE_STANDARD_WEBHOOK_SECRET
andSTRIPE_SECONDARY_WEBHOOK_SECRET
You should also, for your own use, create STRIPE_<NAME>_PUBLIC
, but this is not utilized by the webhook package.
Secondly - when generating a payment that requires the webhook, or, from Stripe itself, you need to include under the data -> object -> metadata, a variable named stripe_account
that includes the naming, including case, such as STANDARD
or SECONDARY
. Otherwise the webhook will assume that the standard naming conventions of the envrionment variables will be present.
An example of when using Stripe checkout, when generating the Stripe Session, you would internally have used the correct stripe keys to generate the correct URLs, and when parsing the following information (as an example) you would use the correct naming in the metadata:
When this same payment is uncaptured, or whatever your requirements are - and the webhook returns this information to your website - the metadata is present and the correct env variable is used when handling the webhook return, whatever your desired result is. I have only been needing this functionality on stripe checkout, with standard non-product based payments via payment_intent_data. Other circumstances are not currently supported.
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.
License
Vulcan Digital Ltd (original authors - all rights remain theirs.)