Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(setup_intent): add mandate_data for confirm #547

Merged
merged 3 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/resources/customer_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,40 @@ use crate::resources::{

#[derive(Clone, Debug, Serialize, 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 {
pub fn new() -> Self {
CustomerPaymentMethodRetrieval {
ending_before: None,
expand: &[],
limit: None,
starting_after: None,
type_: the_type,
type_: None,
}
}
}
Expand Down
55 changes: 48 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 @@ -42,6 +75,14 @@ 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> {
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
Loading