StripeKit 0.1.1
Stripe integration toolkit for C++
Loading...
Searching...
No Matches
stripekit::HTTPClient Class Referenceabstract

Sends StripeKit's requests to Stripe. More...

#include <HTTPClient.h>

Inheritance diagram for stripekit::HTTPClient:
[legend]

Public Types

using Completion = std::function<void(std::variant<HttpResponse, std::exception_ptr>)>
 Completion callback for the callback form of send().

Public Member Functions

virtual ~HTTPClient ()=default
 Destroys the HTTP client instance.
virtual Task< HttpResponse > send_async (const HttpRequest &request)=0
 Sends a request to Stripe.
virtual void send (const HttpRequest &request, Completion completion)=0
 Sends a request to Stripe, reporting the result through a callback.

Detailed Description

Sends StripeKit's requests to Stripe.

This is the outbound half of an adapter. Implement it to put StripeKit on top of an existing HTTP stack; applications normally use a ready-made adapter such as stripekit::drogon::HTTPClient instead.

A rejected request is not an error here. Report a 4xx or 5xx from Stripe as a normal HttpResponse and let StripeKit parse Stripe's error document and throw StripeApiException itself. Reserve exceptions for failures that stopped the request reaching Stripe at all, such as DNS, TLS, or timeout failures.

Implementations must be thread-safe and must tolerate several requests being in flight at once.

See also
Writing an Adapter

Definition at line 110 of file HTTPClient.h.

Member Typedef Documentation

◆ Completion

using stripekit::HTTPClient::Completion = std::function<void(std::variant<HttpResponse, std::exception_ptr>)>

Completion callback for the callback form of send().

Definition at line 113 of file HTTPClient.h.

Constructor & Destructor Documentation

◆ ~HTTPClient()

virtual stripekit::HTTPClient::~HTTPClient ( )
virtualdefault

Destroys the HTTP client instance.

Reimplemented in stripekit::drogon::HTTPClient.

Member Function Documentation

◆ send_async()

virtual Task< HttpResponse > stripekit::HTTPClient::send_async ( const HttpRequest & request)
pure virtual

Sends a request to Stripe.

Parameters
requestWhat to send, including the options to honour.
Returns
A task producing Stripe's response.
Exceptions
std::exceptionStripe could not be reached. A response with an error status is returned normally, not thrown.

Implemented in stripekit::drogon::HTTPClient.

◆ send()

virtual void stripekit::HTTPClient::send ( const HttpRequest & request,
Completion completion )
pure virtual

Sends a request to Stripe, reporting the result through a callback.

The callback must be invoked exactly once, on every path including the failure paths. Calling it twice corrupts whatever is waiting on it; never calling it hangs the request. OnceCallback exists to enforce this.

Parameters
requestWhat to send, including the options to honour.
completionReceives Stripe's response, or the transport failure.

Implemented in stripekit::drogon::HTTPClient.


The documentation for this class was generated from the following file: