Skip to main content

stripe_pay_core/protocol/
const.rs

1/// Stripe API version this crate is written against.
2///
3/// The value is sent as the `Stripe-Version` request header and is
4/// echoed back in every webhook payload.
5pub const STRIPE_API_VERSION: &str = "2026-08-26.dahlia";
6
7/// Base URL of the Stripe REST API.
8pub const STRIPE_API_BASE_URL: &str = "https://api.stripe.com";
9
10/// Divisor converting a major-unit amount into minor units.
11///
12/// Two-decimal currencies such as USD use 100 minor units per major
13/// unit; zero-decimal currencies such as JPY use 1.
14pub const MINOR_UNITS_DIVISOR: u32 = 100;
15
16/// Number of decimal places a two-decimal currency stores.
17pub const DEFAULT_CURRENCY_EXPONENT: u32 = 2;
18
19/// Number of decimal places a zero-decimal currency stores.
20pub const ZERO_DECIMAL_EXPONENT: u32 = 0;
21
22/// Stripe's `type` discriminator for a successful charge.
23pub const CHARGE_TYPE_CHARGE: &str = "charge";
24
25/// Literal prefix shared by Stripe's legacy object identifiers.
26pub const ID_PREFIX: &str = "id_";
27
28/// Stripe's `object` discriminator shared by every Stripe object.
29pub const OBJECT_DISCRIMINATOR: &str = "object";
30
31/// Default tolerance, in seconds, when validating a webhook timestamp.
32pub const DEFAULT_WEBHOOK_TOLERANCE_SECONDS: i64 = 300;
33
34/// Stripe error code for a request rejected by the rate limiter.
35pub const STRIPE_ERROR_RATE_LIMIT: &str = "rate_limit";
36
37/// Stripe error code for a request that never reached the API.
38pub const STRIPE_ERROR_API_CONNECTION: &str = "api_connection_error";
39
40/// Stripe error code for a lock the account is still holding.
41pub const STRIPE_ERROR_LOCK_TIMEOUT: &str = "lock_timeout";
42
43/// Stripe error code for a declined card, which is a settled answer.
44pub const STRIPE_ERROR_CARD_DECLINED: &str = "card_declined";
45
46/// Separator between two `key=value` pairs in an encoded form body.
47pub const FORM_PAIR_SEPARATOR: char = '&';
48
49/// Separator between a form key and its value.
50pub const FORM_KEY_VALUE_SEPARATOR: char = '=';
51
52/// Prefix of the bracketed key carrying Stripe metadata entries.
53pub const METADATA_PREFIX: &str = "metadata";
54
55/// Prefix of the bracketed key carrying Stripe `expand` entries.
56pub const EXPAND_PREFIX: &str = "expand";
57
58/// Open bracket used in Stripe's bracketed parameter names.
59pub const FORM_OPEN_BRACKET: char = '[';
60
61/// Close bracket used in Stripe's bracketed parameter names.
62pub const FORM_CLOSE_BRACKET: char = ']';
63
64/// Form parameter carrying a PaymentIntent or Refund amount.
65pub const FORM_AMOUNT: &str = "amount";
66
67/// Form parameter carrying an ISO 4217 currency code.
68pub const FORM_CURRENCY: &str = "currency";
69
70/// Form parameter carrying a Stripe customer identifier.
71pub const FORM_CUSTOMER: &str = "customer";
72
73/// Form parameter carrying a Stripe charge identifier.
74pub const FORM_CHARGE: &str = "charge";
75
76/// Form parameter carrying a refund's reason.
77pub const FORM_REASON: &str = "reason";
78
79/// Form parameter naming the PaymentIntent being confirmed.
80pub const FORM_PAYMENT_INTENT: &str = "payment_intent";
81
82/// Form parameter naming the payment method used to confirm.
83pub const FORM_PAYMENT_METHOD: &str = "payment_method";
84
85/// Form parameter requesting immediate confirmation.
86pub const FORM_CONFIRM: &str = "confirm";
87
88/// Form parameter carrying the browser return URL after 3-D Secure.
89pub const FORM_RETURN_URL: &str = "return_url";
90
91/// Form parameter carrying a customer's email address.
92pub const FORM_EMAIL: &str = "email";
93
94/// Form parameter carrying a customer's internal description.
95pub const FORM_DESCRIPTION: &str = "description";
96
97/// Wire value Stripe reads as boolean true in a form body.
98pub const TRUE_LITERAL: &str = "true";
99
100/// Form parameter carrying a non-sensitive card's last four digits.
101pub const FORM_CARD_LAST4: &str = "card[last4]";
102
103/// Form parameter carrying a non-sensitive card's expiry month.
104pub const FORM_CARD_EXP_MONTH: &str = "card[exp_month]";
105
106/// Form parameter carrying a non-sensitive card's expiry year.
107pub const FORM_CARD_EXP_YEAR: &str = "card[exp_year]";
108
109/// Longest metadata key Stripe accepts.
110pub const METADATA_KEY_MAX_CHARS: usize = 40;
111
112/// Longest metadata value Stripe accepts.
113pub const METADATA_VALUE_MAX_CHARS: usize = 500;
114
115/// Diagnostic for a metadata key outside Stripe's documented limit.
116pub const METADATA_KEY_LIMIT_MESSAGE: &str = "metadata key must be 1 to 40 characters";
117
118/// Diagnostic for a metadata value outside Stripe's documented limit.
119pub const METADATA_VALUE_LIMIT_MESSAGE: &str = "metadata value must be at most 500 characters";
120
121/// Byte of the hyphen form encoding passes through unescaped.
122pub const UNRESERVED_DASH: u8 = b'-';
123
124/// Byte of the underscore form encoding passes through unescaped.
125pub const UNRESERVED_UNDERSCORE: u8 = b'_';
126
127/// Byte of the dot form encoding passes through unescaped.
128pub const UNRESERVED_DOT: u8 = b'.';
129
130/// Byte of the tilde form encoding passes through unescaped.
131pub const UNRESERVED_TILDE: u8 = b'~';
132
133/// The byte a space encodes to in a form body.
134pub const SPACE: u8 = b' ';
135
136/// The character a space becomes in a form body.
137pub const PLUS_SIGN: char = '+';