stripe_pay_core/form/struct.rs
1use super::*;
2
3/// A form field destined for Stripe's `application/x-www-form-urlencoded`
4/// request body.
5///
6/// Stripe's REST API takes nested parameters as bracketed keys rather
7/// than JSON, so `metadata[order_id]=42` is the wire form. A
8/// `FormField` is one such key and value pair; the builder below
9/// assembles the whole body.
10///
11/// Read accessors are generated by `#[derive(Getter)]`.
12#[derive(Clone, Debug, Eq, Getter, PartialEq)]
13pub struct FormField {
14 /// The bracketed parameter name, such as `amount` or
15 /// `metadata[order_id]`.
16 pub(super) key: String,
17 /// The field's value, already stringified.
18 pub(super) value: String,
19}
20
21/// An ordered collection of Stripe form parameters.
22///
23/// Stripe rejects duplicate keys inside one request, so the builder
24/// overwrites a key rather than pushing a second entry, keeping the
25/// encoding deterministic: the same builder always produces the same
26/// body regardless of the order fields were added.
27///
28/// The field list is deliberately kept off the generated accessors: a
29/// caller holding a mutable `Vec<FormField>` could append a duplicate
30/// key and break the one-entry-per-key invariant the encoder relies on,
31/// so `get_fields` hands out a slice and the mutable view stays
32/// crate-private. Both are written by hand because `#[derive(Getter)]`
33/// can express neither a slice nor a `GetterMut` that coexists with it.
34#[derive(Clone, Debug, Default, Eq, PartialEq)]
35pub struct FormParams {
36 /// The fields in insertion order.
37 pub(super) fields: Vec<FormField>,
38}