Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mzeitlin11 committed Apr 3, 2024
1 parent 18d653b commit b0676cb
Show file tree
Hide file tree
Showing 545 changed files with 5,351 additions and 2,636 deletions.
5 changes: 5 additions & 0 deletions async-stripe/src/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ impl Client {
Client::from_async(crate::Client::new(secret_key))
}

/// Create a new account pointed at a specific URL. This is useful for testing.
pub fn from_url<'a>(url: impl Into<&'a str>, secret_key: impl Display) -> Self {
Client::from_async(crate::Client::from_url(url, secret_key))
}

fn from_async(inner: crate::Client) -> Client {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_io()
Expand Down
29 changes: 24 additions & 5 deletions async-stripe/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::fmt::Display;
use std::str::FromStr;

use bytes::Bytes;
use http::Uri;
Expand Down Expand Up @@ -26,23 +27,41 @@ fn connector() -> hyper::Client<HttpsConnector<HttpConnector>, Body> {
hyper::Client::builder().pool_max_idle_per_host(0).build(HttpsConnector::new())
}

fn clone_builder(_builder: &Builder) -> Builder {
todo!("skipping for now since easier once hyper bumped to 1")
// TODO: this looks to be much simpler in hyper 1.x
// There's probably also a better way to do this now...
fn clone_builder(builder: &Builder) -> Builder {
let mut req_builder =
Request::builder().uri(builder.uri_ref().unwrap()).method(builder.method_ref().unwrap());
for (k, v) in builder.headers_ref().unwrap() {
req_builder = req_builder.header(k, v);
}
req_builder
}

impl Client {
pub fn new(secret_key: impl Display) -> Self {
fn from_uri_and_key(uri: Uri, secret_key: impl Display) -> Self {
let mut secret_header =
HeaderValue::from_str(&format!("Bearer {secret_key}")).expect("invalid secret key");
HeaderValue::try_from(format!("Bearer {secret_key}")).expect("invalid secret key");
secret_header.set_sensitive(true);
Self {
client: connector(),
secret_header_val: secret_header,
headers: Headers::default(),
api_base: Uri::from_static("https://api.stripe.com/"),
api_base: uri,
}
}

pub fn new(secret_key: impl Display) -> Self {
let base = Uri::from_static("https://api.stripe.com/");
Self::from_uri_and_key(base, secret_key)
}

/// Create a new account pointed at a specific URL. This is useful for testing.
pub fn from_url<'a>(url: impl Into<&'a str>, secret_key: impl Display) -> Self {
let uri = Uri::from_str(url.into()).expect("invalid url provided");
Self::from_uri_and_key(uri, secret_key)
}

async fn send_inner(
&self,
body: Option<Bytes>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use stripe_client_core::{
RequestBuilder, StripeBlockingClient, StripeClient, StripeMethod, StripeRequest,
};

#[derive(Copy, Clone, Debug, Default, serde::Serialize)]
#[derive(Copy, Clone, Debug, serde::Serialize)]
pub struct ListBillingPortalConfigurationBuilder<'a> {
/// Only return configurations that are active or inactive (e.g., pass `true` to only list active configurations).
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -30,7 +30,14 @@ pub struct ListBillingPortalConfigurationBuilder<'a> {
}
impl<'a> ListBillingPortalConfigurationBuilder<'a> {
pub fn new() -> Self {
Self::default()
Self {
active: None,
ending_before: None,
expand: None,
is_default: None,
limit: None,
starting_after: None,
}
}
}
/// Returns a list of configurations that describe the functionality of the customer portal.
Expand Down Expand Up @@ -135,7 +142,7 @@ impl<'a> CreateBillingPortalConfigurationBuilder<'a> {
}
}
/// The business information shown to customers in the portal.
#[derive(Copy, Clone, Debug, Default, serde::Serialize)]
#[derive(Copy, Clone, Debug, serde::Serialize)]
pub struct CreateBillingPortalConfigurationBuilderBusinessProfile<'a> {
/// The messaging shown to customers in the portal.
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -149,11 +156,11 @@ pub struct CreateBillingPortalConfigurationBuilderBusinessProfile<'a> {
}
impl<'a> CreateBillingPortalConfigurationBuilderBusinessProfile<'a> {
pub fn new() -> Self {
Self::default()
Self { headline: None, privacy_policy_url: None, terms_of_service_url: None }
}
}
/// Information about the features available in the portal.
#[derive(Copy, Clone, Debug, Default, serde::Serialize)]
#[derive(Copy, Clone, Debug, serde::Serialize)]
pub struct CreateBillingPortalConfigurationBuilderFeatures<'a> {
/// Information about updating the customer details in the portal.
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -179,7 +186,14 @@ pub struct CreateBillingPortalConfigurationBuilderFeatures<'a> {
}
impl<'a> CreateBillingPortalConfigurationBuilderFeatures<'a> {
pub fn new() -> Self {
Self::default()
Self {
customer_update: None,
invoice_history: None,
payment_method_update: None,
subscription_cancel: None,
subscription_pause: None,
subscription_update: None,
}
}
}
/// Information about updating the customer details in the portal.
Expand Down Expand Up @@ -714,7 +728,7 @@ impl StripeRequest for CreateBillingPortalConfiguration<'_> {
RequestBuilder::new(StripeMethod::Post, "/billing_portal/configurations").form(&self.inner)
}
}
#[derive(Copy, Clone, Debug, Default, serde::Serialize)]
#[derive(Copy, Clone, Debug, serde::Serialize)]
pub struct UpdateBillingPortalConfigurationBuilder<'a> {
/// Whether the configuration is active and can be used to create portal sessions.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -745,11 +759,19 @@ pub struct UpdateBillingPortalConfigurationBuilder<'a> {
}
impl<'a> UpdateBillingPortalConfigurationBuilder<'a> {
pub fn new() -> Self {
Self::default()
Self {
active: None,
business_profile: None,
default_return_url: None,
expand: None,
features: None,
login_page: None,
metadata: None,
}
}
}
/// The business information shown to customers in the portal.
#[derive(Copy, Clone, Debug, Default, serde::Serialize)]
#[derive(Copy, Clone, Debug, serde::Serialize)]
pub struct UpdateBillingPortalConfigurationBuilderBusinessProfile<'a> {
/// The messaging shown to customers in the portal.
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -763,11 +785,11 @@ pub struct UpdateBillingPortalConfigurationBuilderBusinessProfile<'a> {
}
impl<'a> UpdateBillingPortalConfigurationBuilderBusinessProfile<'a> {
pub fn new() -> Self {
Self::default()
Self { headline: None, privacy_policy_url: None, terms_of_service_url: None }
}
}
/// Information about the features available in the portal.
#[derive(Copy, Clone, Debug, Default, serde::Serialize)]
#[derive(Copy, Clone, Debug, serde::Serialize)]
pub struct UpdateBillingPortalConfigurationBuilderFeatures<'a> {
/// Information about updating the customer details in the portal.
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -793,11 +815,18 @@ pub struct UpdateBillingPortalConfigurationBuilderFeatures<'a> {
}
impl<'a> UpdateBillingPortalConfigurationBuilderFeatures<'a> {
pub fn new() -> Self {
Self::default()
Self {
customer_update: None,
invoice_history: None,
payment_method_update: None,
subscription_cancel: None,
subscription_pause: None,
subscription_update: None,
}
}
}
/// Information about updating the customer details in the portal.
#[derive(Copy, Clone, Debug, Default, serde::Serialize)]
#[derive(Copy, Clone, Debug, serde::Serialize)]
pub struct UpdateBillingPortalConfigurationBuilderFeaturesCustomerUpdate<'a> {
/// The types of customer updates that are supported. When empty, customers are not updateable.
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -809,7 +838,7 @@ pub struct UpdateBillingPortalConfigurationBuilderFeaturesCustomerUpdate<'a> {
}
impl<'a> UpdateBillingPortalConfigurationBuilderFeaturesCustomerUpdate<'a> {
pub fn new() -> Self {
Self::default()
Self { allowed_updates: None, enabled: None }
}
}
/// The types of customer updates that are supported. When empty, customers are not updateable.
Expand Down Expand Up @@ -901,7 +930,7 @@ impl UpdateBillingPortalConfigurationBuilderFeaturesPaymentMethodUpdate {
}
}
/// Information about canceling subscriptions in the portal.
#[derive(Copy, Clone, Debug, Default, serde::Serialize)]
#[derive(Copy, Clone, Debug, serde::Serialize)]
pub struct UpdateBillingPortalConfigurationBuilderFeaturesSubscriptionCancel<'a> {
/// Whether the cancellation reasons will be collected in the portal and which options are exposed to the customer.
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -923,7 +952,7 @@ pub struct UpdateBillingPortalConfigurationBuilderFeaturesSubscriptionCancel<'a>
}
impl<'a> UpdateBillingPortalConfigurationBuilderFeaturesSubscriptionCancel<'a> {
pub fn new() -> Self {
Self::default()
Self { cancellation_reason: None, enabled: None, mode: None, proration_behavior: None }
}
}
/// Whether the cancellation reasons will be collected in the portal and which options are exposed to the customer.
Expand Down Expand Up @@ -1120,7 +1149,7 @@ impl serde::Serialize
}
}
/// Information about updating subscriptions in the portal.
#[derive(Copy, Clone, Debug, Default, serde::Serialize)]
#[derive(Copy, Clone, Debug, serde::Serialize)]
pub struct UpdateBillingPortalConfigurationBuilderFeaturesSubscriptionUpdate<'a> {
/// The types of subscription updates that are supported. When empty, subscriptions are not updateable.
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -1139,7 +1168,12 @@ pub proration_behavior: Option<UpdateBillingPortalConfigurationBuilderFeaturesSu
}
impl<'a> UpdateBillingPortalConfigurationBuilderFeaturesSubscriptionUpdate<'a> {
pub fn new() -> Self {
Self::default()
Self {
default_allowed_updates: None,
enabled: None,
products: None,
proration_behavior: None,
}
}
}
/// The types of subscription updates that are supported. When empty, subscriptions are not updateable.
Expand Down Expand Up @@ -1353,15 +1387,15 @@ impl StripeRequest for UpdateBillingPortalConfiguration<'_> {
.form(&self.inner)
}
}
#[derive(Copy, Clone, Debug, Default, serde::Serialize)]
#[derive(Copy, Clone, Debug, serde::Serialize)]
pub struct RetrieveBillingPortalConfigurationBuilder<'a> {
/// Specifies which fields in the response should be expanded.
#[serde(skip_serializing_if = "Option::is_none")]
pub expand: Option<&'a [&'a str]>,
}
impl<'a> RetrieveBillingPortalConfigurationBuilder<'a> {
pub fn new() -> Self {
Self::default()
Self { expand: None }
}
}
/// Retrieves a configuration that describes the functionality of the customer portal.
Expand Down Expand Up @@ -1408,15 +1442,15 @@ impl StripeRequest for RetrieveBillingPortalConfiguration<'_> {
}
}

#[derive(Copy, Clone, Debug, Default, serde::Serialize)]
#[derive(Copy, Clone, Debug, serde::Serialize)]
pub struct SubscriptionPauseParam {
/// Whether the feature is enabled.
#[serde(skip_serializing_if = "Option::is_none")]
pub enabled: Option<bool>,
}
impl SubscriptionPauseParam {
pub fn new() -> Self {
Self::default()
Self { enabled: None }
}
}
#[derive(Copy, Clone, Debug, serde::Serialize)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ impl<'a> CreateBillingPortalSessionBuilderFlowDataAfterCompletion<'a> {
}
}
/// Configuration when `after_completion.type=hosted_confirmation`.
#[derive(Copy, Clone, Debug, Default, serde::Serialize)]
#[derive(Copy, Clone, Debug, serde::Serialize)]
pub struct CreateBillingPortalSessionBuilderFlowDataAfterCompletionHostedConfirmation<'a> {
/// A custom message to display to the customer after the flow is completed.
#[serde(skip_serializing_if = "Option::is_none")]
pub custom_message: Option<&'a str>,
}
impl<'a> CreateBillingPortalSessionBuilderFlowDataAfterCompletionHostedConfirmation<'a> {
pub fn new() -> Self {
Self::default()
Self { custom_message: None }
}
}
/// Configuration when `after_completion.type=redirect`.
Expand Down Expand Up @@ -295,7 +295,7 @@ impl<'a> CreateBillingPortalSessionBuilderFlowDataSubscriptionUpdateConfirm<'a>
}
/// The coupon or promotion code to apply to this subscription update.
/// Currently, only up to one may be specified.
#[derive(Copy, Clone, Debug, Default, serde::Serialize)]
#[derive(Copy, Clone, Debug, serde::Serialize)]
pub struct CreateBillingPortalSessionBuilderFlowDataSubscriptionUpdateConfirmDiscounts<'a> {
/// The ID of the coupon to apply to this subscription update.
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -306,7 +306,7 @@ pub struct CreateBillingPortalSessionBuilderFlowDataSubscriptionUpdateConfirmDis
}
impl<'a> CreateBillingPortalSessionBuilderFlowDataSubscriptionUpdateConfirmDiscounts<'a> {
pub fn new() -> Self {
Self::default()
Self { coupon: None, promotion_code: None }
}
}
/// The [subscription item](https://stripe.com/docs/api/subscription_items) to be updated through this flow.
Expand Down
Loading

0 comments on commit b0676cb

Please sign in to comment.