12#include "StripeKit/HTTPClient.h"
13#include "StripeKit/Logging.h"
14#include "StripeKit/StripeApiClient.h"
15#include "StripeKit/WebhookProcessor.h"
16#include "StripeKit/Webhooks.h"
18#include <drogon/HttpClient.h>
29namespace stripekit::drogon {
80 trantor::EventLoop*
loop =
nullptr;
128 std::chrono::seconds
tolerance = std::chrono::minutes(5);
156 std::string api_base_url =
"https://api.stripe.com",
187 std::unique_ptr<trantor::EventLoopThread> event_loop_thread;
188 ::drogon::HttpClientPtr client;
222 std::string endpoint_secret;
Sends StripeKit's requests to Stripe.
std::function< void(std::variant< HttpResponse, std::exception_ptr >)> Completion
Completion callback for the callback form of send().
Receives StripeKit's log entries.
The result of an asynchronous StripeKit operation.
Remembers which webhook events have been handled.
Handles incoming webhook deliveries through an EventDispatcher.
void send(const HttpRequest &request, Completion completion) override
Sends a request to Stripe, reporting the result through a callback.
HTTPClient(std::string api_key, std::string api_base_url="https://api.stripe.com", EventLoopOptions event_loop={})
Creates a client for a Stripe account.
Task< HttpResponse > send_async(const HttpRequest &request) override
Sends a request to Stripe.
~HTTPClient() override
Destroys the client, stopping its event loop thread if it owns one.
LogBridge(LogLevel threshold=LogLevel::Info)
Creates a bridge.
bool should_log(LogLevel level) const override
Reports whether entries at this level are wanted.
void log(LogLevel level, std::string_view message, const LogContext &context) override
Writes one entry through Drogon's matching log level.
void register_handler(std::string path) const
Adds the route to the Drogon application.
WebhookEndpoint(WebhookProcessor &processor, std::string endpoint_secret)
Creates an endpoint.
std::unique_ptr< StripeClient > make_stripe_client(ClientOptions options)
Creates a Stripe client that talks through Drogon.
void register_webhook_handler(WebhookHandlerOptions options)
Adds a Stripe webhook route to the Drogon application.
LogLevel
Severity of a log entry.
@ Info
Normal, noteworthy activity.
constexpr std::chrono::minutes defaultStaleInflightTimeout
How long an unfinished claim is honoured before another process may take it.
std::function< Task< ProcessResult >(const Event &)> EventHandler
The application's webhook handler.
A request StripeKit wants sent to Stripe.
Extra identifiers attached to a log entry.
Settings for make_stripe_client().
std::string api_base_url
Stripe API base URL.
std::string api_key
Stripe secret key, of the form "sk_test_..." or "sk_live_...".
EventLoopOptions event_loop
Which event loop outbound requests run on.
Chooses which event loop outbound Stripe requests run on.
static EventLoopOptions own()
Runs requests on a loop StripeKit starts and owns.
static EventLoopOptions external(trantor::EventLoop &loop)
Runs requests on a loop the application already owns.
Mode mode
Which loop to use.
trantor::EventLoop * loop
The loop to use when mode is Mode::External.
static EventLoopOptions drogon_framework()
Runs requests on the loop of the running Drogon application.
@ DrogonFramework
Use the loop of the running Drogon application.
@ Own
StripeKit starts and owns a loop thread.
@ External
Use a loop the application already owns.
Settings for register_webhook_handler().
std::string path
Route to register, for example "/stripe/webhook".
std::chrono::minutes stale_inflight_timeout
How long before a claim left behind by a crashed process is reclaimed.
webhooks::EventHandler handler
Called for claimed events after verification.
std::chrono::seconds tolerance
How far the signature's timestamp may be from the current time.
std::string endpoint_secret
Signing secret for this endpoint, of the form "whsec_...".
WebhookDedupStore & dedup_store
Where processed event ids are recorded, so each event runs once.
Logger * logger
Where to report failures.