Skip to content

Commit

Permalink
Merge branch 'arlyon:master' into invoice-void-feature
Browse files Browse the repository at this point in the history
  • Loading branch information
ferrohd authored May 30, 2024
2 parents c88a164 + 0a00d31 commit 94816f9
Show file tree
Hide file tree
Showing 14 changed files with 154 additions and 42 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/async-stripe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ jobs:
echo "Some files changed after code generation: $CHANGED_FILES"
exit 1
clippy-codegen:
runs-on: ubuntu-20.04
env:
RUSTFLAGS: -D warnings
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@v1
with:
toolchain: stable
components: clippy
- run: cargo clippy -p stripe-openapi-codegen --tests

clippy:
runs-on: ubuntu-20.04
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
@semantic-release/changelog
@semantic-release/git
@semantic-release/github
@semantic-release-cargo/semantic-release-cargo
semantic-release-cargo
env:
GITHUB_TOKEN: ${{ secrets.REPO_SCOPED_TOKEN }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
7 changes: 3 additions & 4 deletions .releaserc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
[
"@semantic-release-cargo/semantic-release-cargo",
"semantic-release-cargo",
{
"features": {
"async-stripe": ["runtime-tokio-hyper"]
}
"check": false,
"publishArgs": ["--features", "runtime-tokio-hyper"]
}
],
[
Expand Down
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
## [0.37.1](https://github.com/arlyon/async-stripe/compare/v0.37.0...v0.37.1) (2024-05-24)


### Bug Fixes

* Leftover clippy warnings ([888307d](https://github.com/arlyon/async-stripe/commit/888307d23d852ebc2f453e788e7fd682efb9dd6f))
* Run clippy on openapi generator ([c63c197](https://github.com/arlyon/async-stripe/commit/c63c197e7cd6f73c0183345c82be77ef2a4c06f5))

# [0.37.0](https://github.com/arlyon/async-stripe/compare/v0.36.0...v0.37.0) (2024-04-30)


### Bug Fixes

* **customer-ext,PM query:** type field is optional ([362659e](https://github.com/arlyon/async-stripe/commit/362659e3e7ace2706fae172e7936efdc5c17929d))


### Features

* **setup_intent:** add mandate_data for confirm ([51e34d6](https://github.com/arlyon/async-stripe/commit/51e34d6fec2238d27e937f361d9e0b60f1bc564c))
* **setup_intent:** verify microdeposits flow ([15b3663](https://github.com/arlyon/async-stripe/commit/15b3663336561ccf55d78dc66668d28627b4d59b))

# [0.36.0](https://github.com/arlyon/async-stripe/compare/v0.35.3...v0.36.0) (2024-04-30)


### Features

* Add `retrieve_line_items` function for `CheckoutSession` ([5c74b3b](https://github.com/arlyon/async-stripe/commit/5c74b3b13fc30e7f81191c43016ab46c3d8ef9d6))

## [0.35.3](https://github.com/arlyon/async-stripe/compare/v0.35.2...v0.35.3) (2024-04-26)


Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ members = [

[package]
name = "async-stripe"
version = "0.35.3"
version = "0.37.1"
description = "API bindings for the Stripe HTTP API"
rust-version = "1.74.0"
authors = [
Expand Down
10 changes: 5 additions & 5 deletions openapi/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn gen_struct(
let obj = as_object_type(schema).expect("Expected object type");
let schema_title = schema.schema_data.title.as_ref().unwrap_or_else(|| {
tracing::warn!("{} has no title", object);
&object
object
});

let deleted_schema = meta.spec.component_schemas().get(&format!("deleted_{}", object));
Expand Down Expand Up @@ -575,7 +575,7 @@ pub fn gen_inferred_params(
self.starting_after = Some(item.id());
}",
);
out.push_str("}");
out.push('}');
}
}
}
Expand Down Expand Up @@ -716,8 +716,8 @@ pub fn gen_variant_name(wire_name: &str, meta: &Metadata) -> String {
"*" => "All".to_string(),
"self" => "Self_".to_string(),
n => {
if n.chars().next().unwrap().is_digit(10) {
format!("V{}", n.to_string().replace('-', "_").replace('.', "_"))
if n.chars().next().unwrap().is_ascii_digit() {
format!("V{}", n.to_string().replace(['-', '.'], "_"))
} else {
meta.schema_to_rust_type(wire_name)
}
Expand Down Expand Up @@ -1341,7 +1341,7 @@ pub fn gen_impl_requests(
// from the spec already
let request = meta
.spec
.get_request_unwrapped(*path)
.get_request_unwrapped(path)
.as_item()
.expect("Expected item, not path reference");
let segments = path.trim_start_matches("/v1/").split('/').collect::<Vec<_>>();
Expand Down
5 changes: 2 additions & 3 deletions openapi/src/file_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use crate::{
url_finder::UrlFinder,
};

///
#[derive(Default, Debug)]
pub struct FileGenerator {
pub name: String,
Expand Down Expand Up @@ -206,7 +205,7 @@ impl FileGenerator {

pub fn add_use(&mut self, use_path: &str) {
for path in use_path.split(',') {
match path.into() {
match path {
"" | "String" => {}
"Metadata" => {
self.use_params.insert("Metadata");
Expand Down Expand Up @@ -235,7 +234,7 @@ impl Eq for FileGenerator {}

impl PartialOrd for FileGenerator {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
self.name.partial_cmp(&other.name)
Some(self.cmp(other))
}
}

Expand Down
1 change: 1 addition & 0 deletions openapi/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::spec::Spec;
use crate::spec_fetch::fetch_spec;
use crate::{metadata::Metadata, url_finder::UrlFinder};

#[allow(clippy::too_many_arguments)]
mod codegen;
mod file_generator;
mod mappings;
Expand Down
4 changes: 2 additions & 2 deletions openapi/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl<'a> Metadata<'a> {
out.push_str("}\n");
}

write(&out_path.as_ref().join("placeholders.rs"), out.as_bytes()).unwrap();
write(out_path.as_ref().join("placeholders.rs"), out.as_bytes()).unwrap();
}

pub fn write_version<T>(&self, out_path: T)
Expand All @@ -151,7 +151,7 @@ impl<'a> Metadata<'a> {
self.spec.version().replace('-', "_")
));

write(&out_path.as_ref().join("version.rs"), out.as_bytes()).unwrap();
write(out_path.as_ref().join("version.rs"), out.as_bytes()).unwrap();
}

#[tracing::instrument(skip_all)]
Expand Down
2 changes: 1 addition & 1 deletion openapi/src/url_finder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl UrlFinder {
let initial_state: StripeInitialState = serde_json::from_str(
line.trim()
.trim_start_matches("window.__INITIAL_STATE__ = ")
.trim_end_matches(";"),
.trim_end_matches(';'),
)
.expect("should be valid json");
Ok(Self { url_lookup: initial_state.into() })
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
//! > Want to implement your own? If it is a common strategy, please consider opening a PR to add it to the library.
//! Otherwise, we are open to turning this into an open trait so that you can implement your own strategy.
#![allow(clippy::map_clone, clippy::large_enum_variant)]
#![warn(clippy::unwrap_used, clippy::missing_panics_doc)]
#![allow(clippy::large_enum_variant)]
#![warn(clippy::missing_panics_doc)]
#![forbid(unsafe_code)]
// Workaround
#![allow(ambiguous_glob_reexports)]
Expand Down
36 changes: 36 additions & 0 deletions src/resources/checkout_session_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,31 @@ use crate::client::{Client, Response};
use crate::ids::CheckoutSessionId;
use crate::params::Expand;
use crate::resources::CheckoutSession;
use crate::{CheckoutSessionItem, List};

/// The parameters for `CheckoutSession::retrieve_line_items`.
#[derive(Clone, Debug, serde::Serialize, Default)]
pub struct RetrieveCheckoutSessionLineItems {
/// A cursor for use in pagination.
///
/// `ending_before` is an object ID that defines your place in the list.
/// For instance, if you make a list request and receive 100 objects, starting with `obj_bar`, your subsequent call can include `ending_before=obj_bar` in order to fetch the previous page of the list.
#[serde(skip_serializing_if = "Option::is_none")]
pub ending_before: Option<CheckoutSessionId>,

/// A limit on the number of objects to be returned.
///
/// Limit can range between 1 and 100, and the default is 10.
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<u64>,

/// A cursor for use in pagination.
///
/// `starting_after` is an object ID that defines your place in the list.
/// For instance, if you make a list request and receive 100 objects, ending with `obj_foo`, your subsequent call can include `starting_after=obj_foo` in order to fetch the next page of the list.
#[serde(skip_serializing_if = "Option::is_none")]
pub starting_after: Option<CheckoutSessionId>,
}

impl CheckoutSession {
/// Retrieves a Session object.
Expand All @@ -21,4 +46,15 @@ impl CheckoutSession {
pub fn expire(client: &Client, id: &CheckoutSessionId) -> Response<CheckoutSession> {
client.post(&format!("/checkout/sessions/{}/expire", id))
}

/// Retrieves a Checkout Session's line items
///
/// For more details see <https://docs.stripe.com/api/checkout/sessions/line_items>
pub fn retrieve_line_items(
client: &Client,
id: &CheckoutSessionId,
params: &RetrieveCheckoutSessionLineItems,
) -> Response<List<CheckoutSessionItem>> {
client.get_query(&format!("/checkout/sessions/{}/line_items", id), params)
}
}
27 changes: 11 additions & 16 deletions src/resources/customer_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,37 @@ use crate::resources::{
BankAccount, Customer, PaymentMethod, PaymentSource, PaymentSourceParams, Source,
};

#[derive(Clone, Debug, Serialize, Eq, PartialEq)]
#[derive(Clone, Debug, Serialize, Default, Eq, PartialEq)]
pub struct CustomerPaymentMethodRetrieval<'a> {
///A cursor for use in pagination. `ending_before` is an object ID that defines your place in the list.
/// A cursor for use in pagination. `ending_before` is an object ID that defines your place in the list.
///For instance, if you make a list request and receive 100 objects, starting with `obj_bar`,
///your subsequent call can include `ending_before=obj_bar` in order to fetch the previous page of the list.
#[serde(skip_serializing_if = "Option::is_none")]
pub ending_before: Option<String>,

///Specifies which fields in the response should be expanded.
/// Specifies which fields in the response should be expanded.
#[serde(skip_serializing_if = "Expand::is_empty")]
pub expand: &'a [&'a str],

///A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10.
/// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10.
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<i32>,

///A cursor for use in pagination. `starting_after` is an object ID that defines your place in the list.
/// A cursor for use in pagination. `starting_after` is an object ID that defines your place in the list.
///For instance, if you make a list request and receive 100 objects, ending with `obj_foo`,
///your subsequent call can include `starting_after=obj_foo` in order to fetch the next page of the list.
#[serde(skip_serializing_if = "Option::is_none")]
pub starting_after: Option<String>,

///A required filter on the list, based on the object `type` field.
/// An optional filter on the list, based on the object type field. Without the filter, the list includes all current and future payment method types. If your integration expects only one type of payment method in the response, make sure to provide a type value in the request.
#[serde(rename = "type")]
pub type_: CustomerPaymentMethodRetrievalType,
#[serde(skip_serializing_if = "Option::is_none")]
pub type_: Option<CustomerPaymentMethodRetrievalType>,
}

impl<'a> CustomerPaymentMethodRetrieval<'a> {
pub fn new(the_type: CustomerPaymentMethodRetrievalType) -> Self {
CustomerPaymentMethodRetrieval {
ending_before: None,
expand: &[],
limit: None,
starting_after: None,
type_: the_type,
}
pub fn new() -> Self {
CustomerPaymentMethodRetrieval::default()
}
}

Expand Down Expand Up @@ -82,7 +77,7 @@ pub struct CustomerSearchParams<'a> {

impl<'a> CustomerSearchParams<'a> {
pub fn new() -> CustomerSearchParams<'a> {
CustomerSearchParams { query: String::new(), limit: None, page: None, expand: &[] }
CustomerSearchParams::default()
}
}

Expand Down
56 changes: 49 additions & 7 deletions src/resources/setup_intent_ext.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,42 @@
use serde::Serialize;

use crate::client::{Client, Response};
use crate::params::Expand;
use crate::resources::SetupIntent;
use crate::{SetupIntentCancellationReason, SetupIntentId};
use crate::{PaymentMethodId, SetupIntentCancellationReason, SetupIntentId};

/// The set of parameters that can be used when confirming a setup_intent object.
///
/// For more details see <https://stripe.com/docs/api/setup_intents/confirm>
#[derive(Clone, Debug, Serialize)]
pub struct ConfirmSetupIntent {
/// The client secret if on the client side
/// ID of the payment method (a PaymentMethod, Card, or saved Source object) to attach to this SetupIntent.
#[serde(skip_serializing_if = "Option::is_none")]
pub client_secret: Option<String>,
pub payment_method: Option<PaymentMethodId>,

/// Specifies which payment method
/// This hash contains details about the mandate to create
#[serde(skip_serializing_if = "Option::is_none")]
pub payment_method: Option<String>,
pub mandate_data: Option<MandateData>,

/// When included, this hash creates a PaymentMethod that is set as the payment_method value in the SetupIntent.
#[serde(skip_serializing_if = "Option::is_none")]
pub payment_method_data: Option<crate::UpdatePaymentIntentPaymentMethodData>,

/// Payment method-specific configuration for this SetupIntent.
#[serde(skip_serializing_if = "Option::is_none")]
pub payment_method_options: Option<crate::UpdatePaymentIntentPaymentMethodOptions>,

// Mandate data and payment method options not implemented. If you want
// something better, create an issue and lets fix
/// The URL to redirect your customer back to after they authenticate on the payment method’s app or site.
#[serde(skip_serializing_if = "Option::is_none")]
pub return_url: Option<String>,

/// Set to `true` when confirming server-side and using Stripe.js, iOS, or Android client-side SDKs to handle the next actions.
pub use_stripe_sdk: bool,
}

#[derive(Clone, Debug, Default, Serialize)]
pub struct MandateData {
pub customer_acceptance: crate::CustomerAcceptance,
}

/// The set of parameters that can be used when canceling a setup_intent object.
Expand All @@ -33,6 +48,24 @@ pub struct CancelSetupIntent {
pub cancellation_reason: Option<SetupIntentCancellationReason>,
}

/// Verifies microdeposits on a SetupIntent object.
///
/// For more details see <https://stripe.com/docs/api/setup_intents/verify_microdeposits>
#[derive(Clone, Debug, Default, Serialize)]
pub struct VerifyMicrodeposits<'a> {
/// Two positive integers, in cents, equal to the values of the microdeposits sent to the bank account.
#[serde(skip_serializing_if = "Option::is_none")]
pub amounts: Option<Vec<i64>>,

/// A six-character code starting with SM present in the microdeposit sent to the bank account.
#[serde(skip_serializing_if = "Option::is_none")]
pub descriptor_code: Option<&'a str>,

/// Specifies which fields in the response should be expanded.
#[serde(skip_serializing_if = "Expand::is_empty")]
pub expand: &'a [&'a str],
}

impl SetupIntent {
pub fn confirm(
client: &Client,
Expand All @@ -43,6 +76,15 @@ impl SetupIntent {
client.post_form(&format!("/setup_intents/{}/confirm", setup_id), &params)
}

pub fn verify_micro_deposits(
client: &Client,
setup_id: &SetupIntentId,
params: VerifyMicrodeposits,
) -> Response<SetupIntent> {
#[allow(clippy::needless_borrows_for_generic_args)]
client.post_form(&format!("/setup_intents/{}/verify_microdeposits", setup_id), &params)
}

/// A SetupIntent object can be canceled when it is in one of these statuses: requires_payment_method, requires_confirmation, or requires_action.
///
/// For more details see <https://stripe.com/docs/api/setup_intents/cancel>.
Expand Down

0 comments on commit 94816f9

Please sign in to comment.