Skip to main content

ElementConfig

Struct ElementConfig 

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

The configuration a checkout page hands to the payment element.

The struct is transport-free on purpose: the browser binds it to Stripe.js at mount time, so every field can be exercised without a DOM and stays unit-testable on the host target.

Accessors are generated by #[derive(Data)]. The client secret is pinned at construction: it authenticates a mount against Stripe, so allowing it to be swapped after the fact would let a caller who already holds the config redirect the element at another intent.

Implementations§

Source§

impl ElementConfig

Source

pub fn new(client_secret: String) -> Self

Build a configuration for a client secret.

§Arguments
  • String - the client secret Stripe issued for the intent.
§Returns
  • Self - the configuration, defaulting to the payment variant.
Source

pub fn with_kind(self, kind: ElementKind) -> Self

Return a copy of this configuration rendering the given variant.

§Arguments
  • ElementKind - the variant the page should mount.
§Returns
  • Self - the configuration with the variant switched.
Source

pub fn with_locale(self, locale: String) -> Self

Return a copy of this configuration with an explicit locale.

§Arguments
  • String - the locale tag, such as en or zh-CN.
§Returns
  • Self - the configuration with the locale set.
Source

pub fn effective_locale(&self) -> &str

Return the locale actually sent to Stripe.js.

An empty locale means the host page did not choose one, so the element falls back to the crate default rather than sending an empty string Stripe would reject.

§Returns
  • &str - the effective locale.
Source

pub fn is_mountable(&self) -> bool

Return whether the configuration can mount an element.

Stripe rejects an empty client secret, so a blank one has to fail before the element is ever created.

§Returns
  • bool - true when a client secret is present.
Source

pub fn build_options(&self) -> Result<String, ElementError>

Render the options object Stripe.js expects for an element.

Stripe.js is called from JavaScript, so the crate passes a JSON options object rather than typed arguments. Building it here keeps the payload identical to what a hand-written mount would send and lets the tests assert on it without a browser.

§Returns
  • Result<String, ElementError> - the JSON options, or MissingClientSecret when the configuration is unusable.
Source

pub fn require_stripe_js(available: bool) -> Result<(), ElementError>

Return whether the page has loaded the Stripe.js global.

The check is a pure boolean test against the global registry, which keeps it callable from both wasm and the host target.

§Arguments
  • bool - whether window.Stripe resolved when probed.
§Returns
  • Result<(), ElementError> - Ok(()) when Stripe.js is present, StripeJsUnavailable otherwise.
Source

pub fn preflight( &self, has_mount_target: bool, stripe_js_loaded: bool, ) -> Result<(), ElementError>

Check every precondition a mount needs, in the order a caller hits them.

§Arguments
  • bool - whether the page has a mount target.
  • bool - whether Stripe.js is loaded.
§Returns
  • Result<(), ElementError> - Ok(()) when the element can mount, or the first unmet precondition.
Source§

impl ElementConfig

Source

pub fn get_client_secret(&self) -> &String

Source

pub fn get_mut_client_secret(&mut self) -> &mut String

Source

pub fn get_kind(&self) -> ElementKind

Source

pub fn get_mut_kind(&mut self) -> &mut ElementKind

Source

pub fn set_kind(&mut self, val: ElementKind) -> &mut Self

Source

pub fn set_locale(&mut self, val: impl AsRef<str>) -> &mut Self

Source

pub fn get_locale(&self) -> &String

Source

pub fn get_mut_locale(&mut self) -> &mut String

Trait Implementations§

Source§

impl Clone for ElementConfig

Source§

fn clone(&self) -> Self

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 ElementConfig

Source§

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

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

impl Eq for ElementConfig

Source§

impl PartialEq for ElementConfig

Source§

fn eq(&self, other: &Self) -> 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 ElementConfig

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> 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.