Skip to content

Instantly share code, notes, and snippets.

@ravikant-pal
Created July 12, 2025 10:26
Show Gist options
  • Save ravikant-pal/b0ea146ea1a5a1ffb9d14d7b87ef59f1 to your computer and use it in GitHub Desktop.
Save ravikant-pal/b0ea146ea1a5a1ffb9d14d7b87ef59f1 to your computer and use it in GitHub Desktop.
Simulated UPI Payment Interface

Mock Pay — Simulated UPI Payment in Bash

⏱ Duration: 30 minutes

🧪 Concepts: Functions, Arrays, CLI Arguments, Input Validation, Shell UX


🎯 Objective

Simulate a UPI-style payment system using a Bash script that:

  • Accepts the receiver’s name and amount as arguments
  • Displays a list of popular payment methods (e.g., GPay, PhonePe, etc.)
  • Prompts the user to select one
  • Uses functions, arrays, and case logic to simulate payment processing
  • Displays a confirmation message with emoji ✨

🛠 How to Use

  1. Make the script executable:

    chmod +x mock_pay.sh
  2. Run the script with receiver name and amount:

    ./mock_pay.sh Ravi 250
  3. Follow the on-screen instructions to pick a payment method.


💡 Sample Output

👋 Welcome to Mock UPI Bash App!
Paying ₹250 to: Ravi
🧾 Available Payment Methods:
1. PhonePe
2. GPay
3. Paytm
4. AmazonPay
5. BHIM UPI
💳 Choose a payment method [1-5]: 2
🔐 Initiating payment of ₹250 to Ravi via GPay...
⌛ Processing...
✅ Payment Successful! Thank you for using GPay 🙏

🧠 Concepts Covered

Feature Purpose
declare -a Store multiple payment methods in array
$1, $2 Accept command-line arguments
functions Encapsulate logic like simulate_payment()
read -p User input for method choice
case, if Validate and branch logic
sleep Simulate real-time delay in response

💎 Bonus Challenges (For Enthusiasts)

  • Add fake UPI ID entry + OTP screen using $RANDOM
  • Introduce a 10% random chance of “Transaction Failed ❌”
  • Log all successful payments to a transactions.log file
  • Add difficulty levels: prepaid wallet, credit card, UPI

🏁 Why This Exercise?

Because it's fun, contextual (India-based UPI), and teaches real scripting concepts:

  • CLI apps
  • Argument parsing
  • User interaction
  • Basic stateful logic

“This is how we teach core scripting — with real-life stuff students already use daily.” 🇮🇳

#!/bin/bash
# mock_pay.sh — Simulated UPI Payment CLI App
declare -a methods=("PhonePe" "GPay" "Paytm" "AmazonPay" "BHIM UPI")
# Function to show available methods
show_methods() {
echo "🧾 Available Payment Methods:"
for i in "${!methods[@]}"; do
echo "$((i+1)). ${methods[$i]}"
done
}
# Function to simulate payment
simulate_payment() {
name="$1"
amount="$2"
method="$3"
echo "🔐 Initiating payment of ₹$amount to $name via $method..."
sleep 1
echo "⌛ Processing..."
sleep 1
echo "✅ Payment Successful! Thank you for using $method 🙏"
}
# Input validation
if [ $# -lt 2 ]; then
echo "Usage: $0 <ReceiverName> <Amount>"
exit 1
fi
receiver="$1"
amount="$2"
echo "👋 Welcome to Mock UPI Bash App!"
echo "Paying ₹$amount to: $receiver"
# Show and choose method
show_methods
read -p "💳 Choose a payment method [1-${#methods[@]}]: " choice
if ! [[ "$choice" =~ ^[1-5]$ ]]; then
echo "❌ Invalid choice. Exiting."
exit 1
fi
selected_method="${methods[$((choice-1))]}"
simulate_payment "$receiver" "$amount" "$selected_method"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment