Designing APIs for humans: Object IDs π§π»βπ»
Ever wondered why Stripe uses foloowing format to generate unique IDs? Letβs dive in and break down how and why Stripe IDs are structured the way they are:
pi_3LKQhvGUcADgqoEM3bh6pslE
ββββββββββββββββ
ββ Prefix ββ Randomly generated characters
You might have noticed that all Stripe Objects have a prefix at the beginning of the ID. The reason for this is quite simple: adding a prefix makes the ID human readable.βοΈ
Without knowing anything else about the ID we can immediately confirm that weβre talking about a PaymentIntent object here, thanks to the pi_ prefix. This helps Stripe employees internally just as much as it helps developers integrating with Stripe.
The above snippet is trying to retrieve a PaymentIntent from a connected account, however without even looking at the code you can immediately spot the error: a Customer ID (cus_) is being used instead of an Account ID (acct_).π
Without prefixes this would be much harder to debug; if Stripe used UUIDs instead then weβd have to look up the ID to find out what kind of object it is and if itβs even valid.π¨βπ»
[ Read More ] : https://dev.to/stripe/designing-apis-for-humans-object-ids-3o5a
γ°οΈγ°οΈγ°οΈγ°οΈγ°οΈγ°οΈ
#UUID #Stripe
@ProgrammingTip
Ever wondered why Stripe uses foloowing format to generate unique IDs? Letβs dive in and break down how and why Stripe IDs are structured the way they are:
pi_3LKQhvGUcADgqoEM3bh6pslE
ββββββββββββββββ
ββ Prefix ββ Randomly generated characters
You might have noticed that all Stripe Objects have a prefix at the beginning of the ID. The reason for this is quite simple: adding a prefix makes the ID human readable.
Without knowing anything else about the ID we can immediately confirm that weβre talking about a PaymentIntent object here, thanks to the pi_ prefix. This helps Stripe employees internally just as much as it helps developers integrating with Stripe.
$pi = $stripe->paymentIntents->retrieve(
$id,
[],
['stripe_account' => 'cus_1KrJdMGUcADgqoEM']
);
The above snippet is trying to retrieve a PaymentIntent from a connected account, however without even looking at the code you can immediately spot the error: a Customer ID (cus_) is being used instead of an Account ID (acct_).
Without prefixes this would be much harder to debug; if Stripe used UUIDs instead then weβd have to look up the ID to find out what kind of object it is and if itβs even valid.
[ Read More ] : https://dev.to/stripe/designing-apis-for-humans-object-ids-3o5a
γ°οΈγ°οΈγ°οΈγ°οΈγ°οΈγ°οΈ
#UUID #Stripe
@ProgrammingTip
Please open Telegram to view this post
VIEW IN TELEGRAM
Telegram
Programming Tips Resources