A modern Android application demonstrating secure payment processing with Stripe, built with Kotlin and Jetpack Compose.
- π³ Secure payment processing with Stripe
- π Server-side payment intent creation
- π± Modern UI with Jetpack Compose
- π§© MVC architecture with Dagger DI
- β‘ Responsive payment flow
- Frontend: Android (Kotlin) with Jetpack Compose
- Architecture: MVC (Model-View-Controller)
- Networking: Google Volley
- Dependency Injection: Dagger
- Payment Processing: Stripe Android SDK
- Backend: PHP endpoint for creating payment intents
- Android Studio
- PHP hosting environment with Stripe PHP SDK installed
- Stripe account (for test and live API keys)
-
Clone the repository
git clone https://github.com/rameshwx/stripepaymentapp.git cd stripepaymentapp -
Open in Android Studio
-
Configure Stripe publishable key Update
Constants.ktwith your Stripe publishable key:const val STRIPE_PUBLISHABLE_KEY = "pk_test_your_key_here"
-
Update API endpoint In
StripeApiService.kt, set the URL to your PHP backend:private val PAYMENT_API_URL = "https://yourserver.com/stripe/create-payment-intent.php"
-
Build and run the application
-
Install Stripe PHP SDK via cPanel
cd public_html/stripe curl -sS https://getcomposer.org/installer | php php composer.phar require stripe/stripe-php
-
Create payment intent endpoint Create
create-payment-intent.phpwith this content:<?php header('Content-Type: application/json'); header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: POST'); header('Access-Control-Allow-Headers: Content-Type'); if ($_SERVER['REQUEST_METHOD'] !== 'POST') { http_response_code(405); echo json_encode(['error' => 'Method not allowed']); exit; } $data = json_decode(file_get_contents('php://input'), true); if (!isset($data['amount']) || !isset($data['orderNumber'])) { http_response_code(400); echo json_encode(['error' => 'Missing required parameters']); exit; } require_once('vendor/autoload.php'); // Set your secret key $stripeSecretKey = 'sk_test_your_key_here'; \Stripe\Stripe::setApiKey($stripeSecretKey); try { // Create payment intent $paymentIntent = \Stripe\PaymentIntent::create([ 'amount' => round($data['amount'] * 100), // Convert to cents 'currency' => 'usd', 'description' => 'Order #' . $data['orderNumber'], 'automatic_payment_methods' => [ 'enabled' => true, ], ]); echo json_encode([ 'clientSecret' => $paymentIntent->client_secret, 'paymentIntentId' => $paymentIntent->id ]); } catch (\Exception $e) { http_response_code(500); echo json_encode(['error' => $e->getMessage()]); } ?>
com.rameshwx.stripepaymentapp/
βββ di/ # Dependency injection
β βββ AppModule.kt
β βββ AppComponent.kt
βββ model/ # Data models
β βββ Order.kt
β βββ PaymentResponse.kt
βββ controller/ # Business logic
β βββ PaymentController.kt
βββ view/ # UI components
β βββ MainActivity.kt
β βββ PaymentScreen.kt
β βββ PaymentResultScreen.kt
βββ network/ # Volley networking
β βββ StripeApiService.kt
βββ util/ # Utilities
β βββ Constants.kt
βββ StripePaymentApp.kt # Application class
The application follows the MVC architectural pattern:
Data classes representing payment entities:
data class Order(val orderNumber: String, val amount: Double)
data class PaymentResponse(
val success: Boolean,
val message: String,
val paymentIntentId: String? = null,
val clientSecret: String? = null
)Jetpack Compose screens for UI rendering:
@Composable
fun PaymentScreen(
paymentController: PaymentController,
onPaymentComplete: (Boolean, String) -> Unit
) {
// UI implementation
}Business logic for processing payments:
class PaymentController @Inject constructor(
private val stripeApiService: StripeApiService
) {
fun processPayment(
order: Order,
onSuccess: (PaymentResponse) -> Unit,
onError: (String) -> Unit
) {
// Payment processing logic
}
}- User enters order number and amount
- App validates input
- Request sent to PHP backend
- Backend creates Stripe payment intent
- Client secret returned to app
- App presents Stripe payment sheet
- User completes payment
- Result screen displays success/failure
For testing payments in the app, use Stripe's test cards:
| Card Number | Scenario |
|---|---|
| 4242 4242 4242 4242 | Successful payment |
| 4000 0025 0000 3155 | Requires authentication |
| 4000 0000 0000 9995 | Payment declined |
- Client authentication should be implemented in production
- HTTPS is required for production deployments
- API rate limiting should be implemented on the backend
- Server should validate payment amounts and order data
This project is licensed under the MIT License - see the LICENSE file for details.
Note: Replace placeholder API keys with your actual Stripe test API keys. Never include production API keys in source code.


