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
impl FormParams
Sourcepub const fn new() -> FormParams
pub const fn new() -> FormParams
Sourcepub fn get_fields(&self) -> &[FormField]
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.
Sourcepub fn set(&mut self, key: String, value: String) -> &mut FormParams
pub fn set(&mut self, key: String, value: String) -> &mut FormParams
Sourcepub fn with(self, key: String, value: String) -> FormParams
pub fn with(self, key: String, value: String) -> FormParams
Sourcepub fn with_metadata(
self,
key: String,
value: String,
) -> Result<FormParams, StripeError>
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.
Sourcepub fn encode(&self) -> String
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.
Sourcepub fn encode_create_payment_intent(
amount: Money,
customer: Option<String>,
) -> String
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, orNonefor an intent that is not yet attached to a customer.
§Returns
String- the encoded request body.
Sourcepub fn encode_create_refund(
charge: &str,
amount: Option<Money>,
reason: RefundReason,
) -> String
pub fn encode_create_refund( charge: &str, amount: Option<Money>, reason: RefundReason, ) -> String
Sourcepub fn encode_confirm_payment_intent(
payment_intent: &str,
payment_method: &str,
return_url: Option<&str>,
) -> String
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, orNonewhen the payment method owes no redirect.
§Returns
String- the encoded request body.
Sourcepub fn encode_create_customer(
email: Option<&str>,
description: Option<&str>,
) -> String
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, orNoneto omit it.Option<&str>- an internal description, orNoneto omit it.
§Returns
String- the encoded request body.
Trait Implementations§
Source§impl Clone for FormParams
impl Clone for FormParams
Source§fn clone(&self) -> FormParams
fn clone(&self) -> FormParams
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more