Forwarded from Programming Tips 💡 (Moien Tajik)
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