Programming Tips πŸ’‘
51.5K subscribers
67 photos
10 videos
30 files
354 links
Programming & AI:
Tips πŸ’‘
Articles πŸ“•
Resources πŸ‘Ύ
Design Patterns πŸ’Ž
Software Principles βœ…

πŸ‡³πŸ‡± Contact: @MoienTajik

🎯 Buy ads: https://telega.io/c/ProgrammingTip
Download Telegram
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.

$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