Example: Payment Gateway API (PayPal/Stripe)
Imagine you have an e-commerce website, and a customer wants to buy a
product using PayPal. Instead of handling the payment yourself, your website
uses PayPal’s API to process the transaction securely.
How It Works:
1. Your Website (Client) Sends a Payment Request
When a customer clicks “Pay with PayPal,” your website sends a request to
the PayPal API:
bash
CopyEdit
POST https://api.paypal.com/v1/payments/payment
With payment details in JSON format:
json
CopyEdit
{
"amount": "100.00",
"currency": "USD",
"payment_method": "paypal",
"intent": "sale"
}
2. PayPal API (Server) Processes the Payment
o PayPal validates the request.
o It redirects the customer to PayPal’s login page to confirm the
payment.
3. PayPal API Responds with Confirmation
After successful payment, PayPal sends a response:
json
CopyEdit
{
"status": "success",
"transaction_id": "PAY-123456789",
"amount": "100.00",
"currency": "USD"
}
4. Your Website Updates the Order Status
Your website receives the response and marks the order as paid.
🔹 Why Use the API?
You don’t have to handle sensitive credit card data.
PayPal manages security and fraud detection.
It simplifies online payments without building your own payment system.