StripeKit 0.1.1
Stripe integration toolkit for C++
Loading...
Searching...
No Matches
Events.h
1/** Events.h
2 *
3 * Verified webhook signal structures and dispatch interfaces.
4 *
5 * @author Hans de Ruiter
6 *
7 * @license See LICENSE.md for details.
8 */
9
10#pragma once
11
12#include "StripeKit/Models.h"
13
14#include <chrono>
15#include <string>
16
17namespace stripekit {
18
19/**
20 * @addtogroup webhooks
21 * @{
22 */
23
24/**
25 * What a webhook handler reports back about an event.
26 *
27 * Used by EventDispatcher and, as stripekit::webhooks::ProcessResult, by
28 * coroutine handlers.
29 */
31 Handled, /**< Dealt with. Stripe is told the delivery succeeded. */
32 Ignored, /**< Not interesting to this application. Also reported as success. */
33 RetryableFailure, /**< Something was temporarily unavailable. Stripe will deliver again. */
34 FatalFailure /**< Needs intervention. Logged as an error; Stripe is asked to retry. */
35};
36
37/**
38 * A verified event, with the delivery details that came with it.
39 */
41 /** The event itself. */
43
44 /** Identifier the adapter assigned to this delivery, for tracing. May be empty. */
45 std::string delivery_id;
46
47 /** When the adapter received the delivery. */
48 std::chrono::system_clock::time_point received_at;
49};
50
51/**
52 * Handles verified webhook events, for applications using WebhookProcessor.
53 *
54 * Implement this when webhook handling is better expressed as a class than as
55 * a callback; otherwise use stripekit::webhooks::EventHandler.
56 *
57 * dispatch() is called after the signature has been checked and the event id
58 * claimed. Completed events are skipped; failed or interrupted attempts may
59 * run again, so make the handler safe to retry. It must
60 * return quickly, since Stripe treats a slow endpoint as a failed delivery.
61 */
63public:
64 /**
65 * Destroys the dispatcher instance.
66 */
67 virtual ~EventDispatcher() = default;
68
69 /**
70 * Handles one verified event.
71 *
72 * @param signal The event and its delivery details.
73 * @return What happened, which decides what Stripe is told. Returning
74 * EventDispatchResult::RetryableFailure asks Stripe to deliver
75 * again later.
76 */
78};
79
80/** @} */
81
82} // namespace stripekit
Handles verified webhook events, for applications using WebhookProcessor.
Definition Events.h:62
virtual EventDispatchResult dispatch(const VerifiedEventSignal &signal)=0
Handles one verified event.
virtual ~EventDispatcher()=default
Destroys the dispatcher instance.
EventDispatchResult
What a webhook handler reports back about an event.
Definition Events.h:30
@ FatalFailure
Needs intervention.
Definition Events.h:34
@ RetryableFailure
Something was temporarily unavailable.
Definition Events.h:33
@ Ignored
Not interesting to this application.
Definition Events.h:32
Async.h.
Definition Async.h:20
A Stripe event, as delivered by a webhook.
Definition Models.h:196
A verified event, with the delivery details that came with it.
Definition Events.h:40
EventEnvelope envelope
The event itself.
Definition Events.h:42
std::chrono::system_clock::time_point received_at
When the adapter received the delivery.
Definition Events.h:48
std::string delivery_id
Identifier the adapter assigned to this delivery, for tracing.
Definition Events.h:45