Skip to content

hotabics/orderweather

Repository files navigation

OrderWeather β˜€οΈ

Order weather is an app where everyone can order specific weather at a specific time and place.

πŸ“‹ Overview

OrderWeather is a full-stack application that allows users to "order" good weather for a specific date and location. Users pay upfront, and if the weather conditions are met (no rain, temperature β‰₯20Β°C), the payment is captured. If the conditions are not met, the payment is automatically refunded.

Features

  • 🌀️ Weather Ordering: Select a date and location to order good weather
  • πŸ’³ Stripe Payment Integration: Secure payment processing with manual capture
  • πŸ” Weather Verification: Automatic weather checking using OpenWeatherMap API
  • πŸ’° Automatic Refunds: Money returned if weather conditions aren't met
  • ⏰ Cron Job Processing: Scheduled weather checks and payment processing
  • πŸ“Š Order Tracking: Real-time order status updates

πŸ—οΈ Project Structure

orderweather/
β”œβ”€β”€ backend/                    # Node.js/Express backend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ config/            # Database configuration
β”‚   β”‚   β”œβ”€β”€ controllers/       # Route controllers
β”‚   β”‚   β”œβ”€β”€ models/            # MongoDB models
β”‚   β”‚   β”œβ”€β”€ routes/            # API routes
β”‚   β”‚   β”œβ”€β”€ services/          # Business logic (weather, payment, cron)
β”‚   β”‚   └── server.js          # Main server file
β”‚   β”œβ”€β”€ package.json
β”‚   └── .env.example
β”‚
β”œβ”€β”€ frontend/                   # React frontend
β”‚   β”œβ”€β”€ public/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/        # React components
β”‚   β”‚   β”œβ”€β”€ services/          # API service layer
β”‚   β”‚   β”œβ”€β”€ App.js
β”‚   β”‚   └── index.js
β”‚   β”œβ”€β”€ package.json
β”‚   └── .env.example
β”‚
β”œβ”€β”€ .gitignore
└── README.md

πŸš€ Getting Started

Prerequisites

  • Node.js (v16 or higher)
  • MongoDB (local or Atlas)
  • Stripe account
  • OpenWeatherMap API key

Installation

  1. Clone the repository

    git clone https://github.com/hotabics/orderweather.git
    cd orderweather
  2. Setup Backend

    cd backend
    npm install
    
    # Copy and configure environment variables
    cp .env.example .env
    # Edit .env with your credentials

    Required environment variables:

    PORT=5000
    NODE_ENV=development
    MONGODB_URI=mongodb://localhost:27017/orderweather
    OPENWEATHER_API_KEY=your_openweather_api_key
    STRIPE_SECRET_KEY=your_stripe_secret_key
    STRIPE_WEBHOOK_SECRET=your_stripe_webhook_secret
    FRONTEND_URL=http://localhost:3000
    
  3. Setup Frontend

    cd ../frontend
    npm install
    
    # Copy and configure environment variables
    cp .env.example .env
    # Edit .env with your credentials

    Required environment variables:

    REACT_APP_API_URL=http://localhost:5000/api
    REACT_APP_STRIPE_PUBLIC_KEY=your_stripe_public_key
    

Running the Application

  1. Start MongoDB (if running locally)

    mongod
  2. Start Backend Server

    cd backend
    npm run dev

    Server will run on http://localhost:5000

  3. Start Frontend

    cd frontend
    npm start

    App will open on http://localhost:3000

πŸ”‘ API Keys Setup

OpenWeatherMap API

  1. Sign up at https://openweathermap.org/
  2. Generate an API key
  3. Add to backend .env file

Stripe

  1. Sign up at https://stripe.com/
  2. Get your test API keys from the dashboard
  3. Add both public and secret keys to respective .env files

πŸ“‘ API Endpoints

Orders

  • POST /api/orders - Create a new order
  • GET /api/orders/:orderId - Get order details
  • GET /api/[email protected] - Get user orders
  • POST /api/orders/:orderId/confirm - Confirm payment

Health Check

  • GET /api/health - Check API status

πŸ”„ How It Works

  1. User Orders Weather

    • User selects date (1-5 days in future) and location
    • Creates payment intent with Stripe (manual capture)
    • Order stored in MongoDB with status "pending"
  2. Payment Processing

    • User completes payment with credit card
    • Payment is authorized but not captured (held)
    • Order status updated to "succeeded"
  3. Weather Verification (Cron Job runs hourly)

    • Checks orders where date has passed
    • Fetches actual weather from OpenWeatherMap
    • Compares with required conditions:
  4. Payment Finalization

    • If conditions met: Payment captured, order marked "fulfilled"
    • If conditions not met: Payment cancelled/refunded, order marked "not_fulfilled"

πŸ› οΈ Technology Stack

Backend

  • Node.js - Runtime environment
  • Express - Web framework
  • MongoDB - Database
  • Mongoose - ODM
  • Stripe - Payment processing
  • Axios - HTTP client
  • node-cron - Task scheduling

Frontend

  • React - UI framework
  • Stripe React Elements - Payment UI
  • React DatePicker - Date selection
  • React Toastify - Notifications
  • Axios - API client

πŸ“ MongoDB Schema

Order Model

{
  userId: String,
  email: String,
  date: Date,
  location: {
    city: String,
    lat: Number,
    lon: Number
  },
  amount: Number,
  currency: String,
  paymentIntentId: String,
  paymentStatus: String,
  weatherConditions: {
    requiredTemp: Number,
    noRain: Boolean
  },
  status: String,
  weatherCheckResult: {
    actualTemp: Number,
    hasRain: Boolean,
    checkedAt: Date,
    fulfilled: Boolean
  }
}

πŸ§ͺ Testing

# Backend tests
cd backend
npm test

# Frontend tests
cd frontend
npm test

🚒 Deployment

Backend (e.g., Heroku)

  1. Set environment variables
  2. Deploy code
  3. Ensure MongoDB is accessible
  4. Cron jobs will run automatically

Frontend (e.g., Vercel)

  1. Set environment variables
  2. Deploy code
  3. Update backend CORS settings

πŸ“„ License

ISC

πŸ‘₯ Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

πŸ”’ Security Notes

  • Never commit .env files
  • Use environment variables for all sensitive data
  • Stripe webhooks should be verified in production
  • Implement rate limiting for production
  • Add authentication/authorization for user-specific operations

⚠️ Important: This is an MVP implementation. See SECURITY.md for comprehensive security considerations and production requirements.

πŸ“ž Support

For issues or questions, please open an issue on GitHub.

orderweather

Order weather is app where everyone can order specific weather in specific time and place

OpenWeatherMap API key:

  • Within the next couple of hours, your API key ba8dcc457360639fc97cd4ea1903ed1f will be activated and ready to use
  • You can later create more API keys on your account page
  • Please, always use your API key in each API call

Endpoint:

  • Please, use the endpoint api.openweathermap.org for your API calls

Example of API call: api.openweathermap.org/data/2.5/weather?q=London,uk&APPID=ba8dcc457360639fc97cd4ea1903ed1f

Useful links:

About

Order weather is app where everyone can order specific weather in specific time and place

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •