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
impl ElementConfig
Sourcepub fn with_kind(self, kind: ElementKind) -> Self
pub fn with_kind(self, kind: ElementKind) -> Self
Sourcepub fn with_locale(self, locale: String) -> Self
pub fn with_locale(self, locale: String) -> Self
Sourcepub fn effective_locale(&self) -> &str
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.
Sourcepub fn is_mountable(&self) -> bool
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-truewhen a client secret is present.
Sourcepub fn build_options(&self) -> Result<String, ElementError>
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, orMissingClientSecretwhen the configuration is unusable.
Sourcepub fn require_stripe_js(available: bool) -> Result<(), ElementError>
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- whetherwindow.Striperesolved when probed.
§Returns
Result<(), ElementError>-Ok(())when Stripe.js is present,StripeJsUnavailableotherwise.