Mobile Banking & UPI – Fundamentals
Tools & Setup
(IIT‑JEE / competitive exam style notes – rigorous, derivations, key formulae, tricky points & a hard practice question)
1. Why “Tools & Setup” matters in UPI development
| Aspect | Why it matters | Typical exam‑style question |
|---|---|---|
| Environment | Rapid prototyping vs production | “Explain the differences between UPI sandbox and production APIs.” |
| SDKs & Libraries | Speed up integration, reduce boilerplate | “What are the advantages of using the official UPI SDK over custom HTTP implementation?” |
| Security | UPI is a payment channel; any flaw can lead to fraud | “List the cryptographic primitives used in UPI transaction signing.” |
| Testing & QA | Guarantees compliance with RBI & NPCI guidelines | “How does the ‘UPI transaction simulation’ tool help in regression testing?” |
2. Core Tools & Frameworks
| Tool | Purpose | Key Features | Typical Usage |
|---|---|---|---|
| Android Studio (or Xcode for iOS) | IDE for mobile app development | • Gradle build system • Emulator/Device Manager • Debugger & Profiler |
Build UPI‑enabled mobile wallets, integrate SDKs |
| UPI SDK (Android SDK, iOS SDK) | Provides ready‑made UI & API wrappers | • PayRequest & PayResponse classes • Digital signature helper |
Replace custom HTTP calls |
| Postman / Insomnia | API testing & mock server | • Environment variables • Pre‑request scripts |
Test UPI APIs in sandbox |
| OpenSSL / BouncyCastle | Cryptography (RSA/ECDSA, SHA‑256) | • Key generation • Signing & verification |
Generate UPI PIN‑block, sign transaction |
| Git | Version control | • Branching, merging, pull requests | Collaborative development |
| Jenkins / GitHub Actions | CI/CD | • Automated build, lint, test | Continuous delivery of wallet releases |
| Robolectric / Espresso | Unit & UI testing | • Mock Android context • UI interactions |
Verify UPI flow UI |
| Firebase Analytics | User analytics & crash reporting | • Deep‑linking • Crashlytics |
Monitor app health |
| Log4j / Timber | Logging | • Structured logging • Log filtering |
Debug transaction logs |
| Rider (or IntelliJ) | Alternative IDE for Kotlin/Java | • Better performance for large projects | Optional |
3. Setup Walk‑through
3.1 Project Skeleton (Android)
gradle init --type java-application
Add dependencies in build.gradle:
implementation 'com.upi.sdk:upi-android:1.4.0' // official SDK
implementation 'org.bouncycastle:bcprov-jdk15on:1.69'
implementation 'com.squareup.retrofit2:retrofit:2.9.0' // optional
3.2 Environment Variables
| Variable | Sandbox | Production |
|---|---|---|
UPI_SDK_KEY |
sandbox_key |
prod_key |
UPI_SDK_SECRET |
sandbox_secret |
prod_secret |
UPI_API_URL |
https://sandbox.upi/api |
https://api.upi/ |
RISK_SCORE_ENDPOINT |
https://sandbox.upi/risk |
https://api.upi/risk |
Use gradle.properties or Android buildConfigField.
3.3 Digital Signature Workflow
- Generate ECDSA key pair (curve
secp256r1). - Create JSON payload for
PayRequest. - Hash using SHA‑256.
- Sign the hash with private key → Signature.
- Base64‑encode payload + signature →
payload&signaturefields.
fun signPayload(json: String, privateKey: PrivateKey): String {
val digest = MessageDigest.getInstance("SHA-256").digest(json.toByteArray())
val signature = Signature.getInstance("SHA256withECDSA")
signature.initSign(privateKey)
signature.update(digest)
return Base64.encodeToString(signature.sign(), Base64.NO_WRAP)
}
3.4 API Endpoints (Key Ones)
| Endpoint | Method | Description | Tricky Point |
|---|---|---|---|
/v1/pay |
POST | Initiate payment | Must include txnId, amount, payerVpa, payeeVpa. |
/v1/txnStatus |
GET | Check status | txnId must be unique per session. |
/v1/upiAuth |
POST | Generate UPI QR or PIN‑block | Requires appId, txnId, amount. |
/v1/riskScore |
POST | Fraud detection | Must be called before /v1/pay. |
4. Derivations & Formulae
4.1 UPI Transaction ID Generation
TXN_ID = <APP_ID> + "_" + <TIMESTAMP> + "_" + <RANDOM_6_DIGIT>
- APP_ID: 10‑digit alphanumeric.
- TIMESTAMP: Unix epoch in seconds.
- RANDOM_6_DIGIT:
Math.random()scaled.
Proof of uniqueness – collision probability < 1e‑6 per day.
4.2 PIN‑Block Calculation (ISO 9564)
PIN_BLOCK = (PIN_LENGTH << 4) | (PIN_VALUE)
MASKED_PIN = PIN_BLOCK XOR 0xFF
- PIN_LENGTH: number of digits (0‑9).
- PIN_VALUE: BCD encoded PIN.
Used for UPI PIN‑based payments.
4.3 Risk Score Formula (Simplified)
RiskScore =
0.4 * (TransactionAmount / MaxDailyLimit) +
0.2 * (NumberOfTransactionsLast24h / 10) +
0.4 * (GeolocationRiskFactor)
- GeolocationRiskFactor: 0–1 based on location anomaly.
Threshold: `RiskScore > 0.