Skip to content

Complete React Native app with Stripe Payment Sheet integration. Secure payments, TypeScript support, beautiful UI, and production-ready code. Includes backend API and comprehensive documentation.

Notifications You must be signed in to change notification settings

salmanazamdev/stripe-payment-react-native-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

25 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’³ Stripe Payment Sheet - React Native App

A complete, production-ready React Native application demonstrating Stripe Payment Sheet integration with TypeScript, featuring secure payment processing, beautiful UI, and comprehensive error handling.

React Native Stripe TypeScript Node.js

✨ Features

  • πŸ”’ PCI Compliant - Secure payment processing without handling sensitive card data
  • πŸ“± Native UI - Beautiful Payment Sheet that slides up from bottom
  • πŸ’³ Multiple Payment Methods - Cards, Apple Pay, Google Pay support
  • πŸ›‘οΈ Built-in Security - Fraud protection and 3D Secure authentication
  • 🎯 TypeScript Support - Full type safety and IntelliSense
  • πŸ”„ Real-time Validation - Instant card validation and error feedback
  • πŸ“Š Comprehensive Logging - Detailed error handling and debugging
  • 🌍 Production Ready - Best practices for deployment and security

πŸš€ Quick Start

Prerequisites

  • Node.js 16+ installed
  • React Native development environment setup
  • Stripe account (Create free account)
  • Android Studio (for Android development)

Installation

  1. Clone the repository
git clone https://github.com/salmanazamdev/stripe-payment-react-native-app.git
cd stripe-payment-react-native-app
  1. Install dependencies
# Install React Native dependencies
npm install

# Install backend dependencies
cd stripe-backend
npm install
cd ..
  1. Get your Stripe keys

  2. Configure your keys

    Backend (stripe-backend/server.js):

    const stripe = require('stripe')('sk_test_YOUR_SECRET_KEY_HERE');

    Frontend (App.tsx):

    setPublishableKey('pk_test_YOUR_PUBLISHABLE_KEY_HERE');
  3. Run the application

    Terminal 1 - Start Backend:

    cd stripe-backend
    node server.js
    # Should see: βœ… Server running on port 3000

    Terminal 2 - Start React Native:

    npx react-native run-android
  4. Test the payment

    • Tap "Pay Now" button
    • Use test card: 4242 4242 4242 4242
    • Any future expiry date and CVC
    • Complete the payment!

πŸ—οΈ Project Structure

stripe-payment-react-native-app/
β”œβ”€β”€ πŸ“± React Native App
β”‚   β”œβ”€β”€ App.tsx                     # Main app with StripeProvider
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   └── components/
β”‚   β”‚       └── CheckoutScreen.tsx  # Payment UI and logic
β”‚   └── package.json
β”‚
β”œβ”€β”€ πŸ–₯️ Backend Server
β”‚   β”œβ”€β”€ server.js                   # Express server with Stripe
β”‚   β”œβ”€β”€ package.json
β”‚   └── .env.example
β”‚
└── πŸ“š Documentation
    β”œβ”€β”€ README.md
    └── docs/
        β”œβ”€β”€ API.md
        └── DEPLOYMENT.md

πŸ”§ Configuration

Environment Variables

Create stripe-backend/.env:

STRIPE_SECRET_KEY=sk_test_your_secret_key_here
STRIPE_PUBLISHABLE_KEY=pk_test_your_publishable_key_here
PORT=3000

Network Configuration

For Android Emulator:

const API_URL = 'http://10.0.2.2:3000';

For Physical Device:

const API_URL = 'http://YOUR_COMPUTER_IP:3000';

🎯 How It Works

  1. App Initialization - Stripe Provider sets up with publishable key
  2. Payment Setup - App calls backend to create payment intent
  3. Backend Processing - Server creates customer, ephemeral key, and payment intent
  4. Payment Sheet - Beautiful native UI handles card input
  5. Secure Processing - Stripe processes payment securely
  6. Result Handling - App shows success/error feedback

πŸ§ͺ Testing

Test Cards

Card Number Description
4242 4242 4242 4242 Successful payment
4000 0000 0000 0002 Card declined
4000 0000 0000 9995 Insufficient funds
4000 0025 0000 3155 Requires authentication

Running Tests

# Run React Native tests
npm test

# Run backend tests
cd stripe-backend
npm test

πŸš€ Production Deployment

Security Checklist

  • Environment variables for all keys
  • HTTPS enabled for all endpoints
  • Webhook signature verification
  • Rate limiting implemented
  • Error logging configured
  • User authentication added

Backend Deployment

Option 1: Heroku

# Install Heroku CLI
heroku create your-app-name
heroku config:set STRIPE_SECRET_KEY=sk_live_your_live_key
git push heroku main

Option 2: Railway/Vercel

  • Deploy backend to your preferred platform
  • Update API_URL in React Native app
  • Configure environment variables

Mobile App Deployment

Android:

cd android
./gradlew assembleRelease

iOS:

cd ios
xcodebuild -workspace StripePaymentApp.xcworkspace -scheme StripePaymentApp archive

πŸ“Š API Endpoints

POST /payment-sheet

Creates payment intent and returns client secrets for Payment Sheet.

Response:

{
  "paymentIntent": "pi_1234567890_secret_abcdef",
  "ephemeralKey": "ek_test_1234567890",
  "customer": "cus_1234567890",
  "publishableKey": "pk_test_..."
}

GET /

Health check endpoint.

Response:

{
  "message": "βœ… Stripe server is running!"
}

πŸ› οΈ Troubleshooting

Common Issues

❌ "Network request failed"

  • Check if backend server is running
  • Verify API_URL is correct
  • For physical devices, use computer's IP address

❌ "Invalid API key"

  • Double-check your Stripe keys
  • Ensure you're using test keys for development
  • Verify keys are properly set in environment variables

❌ "Payment failed"

  • Use valid test card numbers
  • Check card expiry date is in the future
  • Ensure sufficient test balance

❌ Payment Sheet not opening

  • Check server logs for errors
  • Verify payment intent creation is successful
  • Use "Retry Setup" button to reinitialize

Debug Mode

Enable detailed logging:

// Add to CheckoutScreen.tsx
console.log('πŸ” Debug mode enabled');

πŸ”„ Next Steps

Enhance Your Payment System:

  • Webhooks - Handle payment confirmations
  • Subscriptions - Recurring payments
  • Customers - Save payment methods
  • Analytics - Track payment metrics
  • Multi-currency - Support global payments
  • Discounts - Coupon system
  • Refunds - Handle payment returns

🀝 Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ™ Acknowledgments

πŸ“ž Support


⭐ Star this repository if it helped you!

Built with ❀️ by [Salman]


Tags

react-native stripe payments mobile-payments typescript nodejs express payment-sheet mobile-development fintech pci-compliance android ios

About

Complete React Native app with Stripe Payment Sheet integration. Secure payments, TypeScript support, beautiful UI, and production-ready code. Includes backend API and comprehensive documentation.

Topics

Resources

Stars

Watchers

Forks