File tree Expand file tree Collapse file tree 1 file changed +15
-7
lines changed Expand file tree Collapse file tree 1 file changed +15
-7
lines changed Original file line number Diff line number Diff line change 26
26
27
27
// check what type of event notification we have
28
28
if ($ event_notification instanceof Stripe \Events \V1BillingMeterErrorReportTriggeredEventNotification) {
29
- $ meter = $ event_notification -> fetchRelatedObject ();
30
- $ meter_id = $ meter -> id ;
29
+ // there's basic info about the related object in the notification
30
+ echo " Meter with id { $ event_notification -> related_object -> id } reported an error \n" ;
31
31
32
- // Record the failures and alert your team
33
- // Add your logic here
32
+ // or you can fetch the full object form the API for more details
33
+ $ meter = $ event_notification ->fetchRelatedObject ();
34
+ echo "Meter {$ meter ->display_name } ( {$ meter ->id }) had a problem \n" ;
34
35
35
- // can fetch full event w/ data
36
+ // And you can always fetch the full event:
36
37
$ event = $ event_notification ->fetchEvent ();
37
- // data is fully typed
38
- $ event ->data ->developer_message_summary ;
38
+ echo "More info: {$ event ->data ->developer_message_summary }\n" ;
39
+ } elseif ($ event_notification instanceof Stripe \Events \UnknownEventNotification) {
40
+ // Events that were introduced after this SDK version release are
41
+ // represented as `UnknownEventNotification`s.
42
+ // They're valid, the SDK just doesn't have corresponding classes for them.
43
+ // You must match on the "type" property instead.
44
+ if ('some.new.event ' === $ event_notification ->type ) {
45
+ // handle it the same way as above
46
+ }
39
47
}
40
48
41
49
return $ response ->withStatus (200 );
You can’t perform that action at this time.
0 commit comments