Skip to main content

FormParams

Struct FormParams 

Source
pub struct FormParams { /* private fields */ }
Expand description

An ordered collection of Stripe form parameters.

Stripe rejects duplicate keys inside one request, so the builder overwrites a key rather than pushing a second entry, keeping the encoding deterministic: the same builder always produces the same body regardless of the order fields were added.

The field list is deliberately kept off the generated accessors: a caller holding a mutable Vec<FormField> could append a duplicate key and break the one-entry-per-key invariant the encoder relies on, so get_fields hands out a slice and the mutable view stays crate-private. Both are written by hand because #[derive(Getter)] can express neither a slice nor a GetterMut that coexists with it.

Implementations§

Source§

impl FormParams

Source

pub const fn new() -> FormParams

Build an empty parameter set.

§Returns
  • Self - a builder with no fields.
Source

pub fn get_fields(&self) -> &[FormField]

Return the fields in insertion order.

#[derive(Getter)] cannot express this accessor: a clone getter hands back an owned Vec whose borrow dies at the end of the statement, and a deref getter breaks the matching GetterMut signature. A slice is the only return type that lets encode sort the fields in place.

§Returns
  • &[FormField] - the fields, in insertion order.
Source

pub fn len(&self) -> usize

Return the number of fields in the builder.

§Returns
  • usize - the field count.
Source

pub fn is_empty(&self) -> bool

Return whether the builder holds no fields.

§Returns
  • bool - true when there is nothing to encode.
Source

pub fn set(&mut self, key: String, value: String) -> &mut FormParams

Add a field, replacing any existing field with the same key.

§Arguments
  • String - the bracketed parameter name.
  • String - the field’s value.
§Returns
  • &mut Self - the builder with the field added or replaced.
Source

pub fn with(self, key: String, value: String) -> FormParams

Add a field and return the builder by value.

§Arguments
  • String - the bracketed parameter name.
  • String - the field’s value.
§Returns
  • Self - the builder with the field added or replaced.
Source

pub fn with_metadata( self, key: String, value: String, ) -> Result<FormParams, StripeError>

Add a nested metadata entry using Stripe’s bracket notation.

Stripe limits metadata keys to 40 characters and values to 500; both are checked here so a bad key fails at build time rather than as an opaque 400 from the API.

§Arguments
  • String - the metadata key.
  • String - the metadata value.
§Returns
  • Result<Self, StripeError> - the builder, or the reason the key or value exceeded Stripe’s documented limits.
Source

pub fn encode(&self) -> String

Return the body as a percent-encoded key=value string.

Keys are sorted so the same logical request always produces the same body, which makes request signing and test fixtures reproducible.

§Returns
  • String - the encoded body.
Source

pub fn encode_create_payment_intent( amount: Money, customer: Option<String>, ) -> String

Build the request body for creating a PaymentIntent.

Stripe creates a PaymentIntent with a flat form body; the amount travels as a minor-unit integer and the currency as its ISO 4217 code, exactly as Money stores them.

§Arguments
  • Money - the amount to capture.
  • Option<String> - the customer to charge, or None for an intent that is not yet attached to a customer.
§Returns
  • String - the encoded request body.
Source

pub fn encode_create_refund( charge: &str, amount: Option<Money>, reason: RefundReason, ) -> String

Build the request body for refunding part or all of a charge.

§Arguments
  • &str - the charge being refunded.
  • Option<Money> - the amount to return, or None to refund the charge’s full remaining balance.
  • RefundReason - why the money is being returned.
§Returns
  • String - the encoded request body.
Source

pub fn encode_confirm_payment_intent( payment_intent: &str, payment_method: &str, return_url: Option<&str>, ) -> String

Build the request body for confirming a PaymentIntent.

Confirmation names the payment method and may set the return URL the browser lands on once 3-D Secure finishes.

§Arguments
  • &str - the PaymentIntent to confirm.
  • &str - the payment method to charge.
  • Option<&str> - the browser return URL, or None when the payment method owes no redirect.
§Returns
  • String - the encoded request body.
Source

pub fn encode_create_customer( email: Option<&str>, description: Option<&str>, ) -> String

Build the request body for creating a Customer.

Stripe accepts a customer’s email and description as flat form fields; both are optional.

§Arguments
  • Option<&str> - the customer’s email, or None to omit it.
  • Option<&str> - an internal description, or None to omit it.
§Returns
  • String - the encoded request body.

Trait Implementations§

Source§

impl Clone for FormParams

Source§

fn clone(&self) -> FormParams

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FormParams

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for FormParams

Source§

fn default() -> FormParams

Returns the “default value” for a type. Read more
Source§

impl Eq for FormParams

Source§

impl PartialEq for FormParams

Source§

fn eq(&self, other: &FormParams) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for FormParams

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.