What you'll build
In this part you'll build the full checkout flow — a summary screen, Paystack payment, and an order record saved to Firestore when payment succeeds.
By the end of this part:
- A checkout screen summarising the order and collecting a delivery address
- Paystack payment sheet launched from the app
- A confirmed order saved to Firestore on payment success
- The cart cleared automatically after a successful order
Set up Paystack
Go to dashboard.paystack.com and sign up or sign in. Under Settings → API Keys, copy your Test Public Key — it starts with pk_test_.
Use test keys during development. Paystack test mode lets you pay with test card numbers without real money moving. Switch to live keys (pk_live_) only when you're ready to go live.
Add your Paystack public key to your .env file or as a constant in a config file:
// lib/config.dart
const kPaystackPublicKey = 'pk_test_your_key_here';
The flutter_paystack package should already be in your pubspec.yaml from Part 1. If not:
flutter pub add flutter_paystack
Initialize the plugin in main.dart:
await PaystackPlugin.initialize(publicKey: kPaystackPublicKey);
Create the order model
Create the order data model at lib/models/order.dart.
An Order has fields: id (String), userId (String), items (List
Build the checkout screen
Build the checkout screen at lib/features/checkout/checkout_screen.dart.
The screen shows:
1. An order summary section — list of cart items with quantities and prices, and a total
2. A delivery details form — fields for full name, phone number, delivery address, and city. All fields are required.
3. A "Pay GHS X.XX with Paystack" button at the bottom
When the Pay button is tapped:
- Validate the form; show inline errors if any field is empty
- Generate a unique payment reference: "SHOP_
Build the order service
Create lib/services/order_service.dart with two methods:
1. Future
Add an order confirmation screen
Create lib/features/checkout/order_confirmation_screen.dart. Show a success animation (use Flutter's built-in AnimatedContainer or a simple checkmark that scales in), the order reference number, a summary of what was ordered, and two buttons: "Continue shopping" (navigates to /) and "View my orders" (navigates to /orders).
Test the payment flow
- Fill the cart with a few products
- Tap Checkout — the checkout screen should show the items and total
- Fill in delivery details
- Tap Pay — Paystack's payment sheet should open
- Use Paystack's test card:
4084 0840 8408 4081, expiry01/99, CVV408, PIN0000 - Payment should complete — the confirmation screen appears
- Check Firestore — an order document should exist under
orders/ - Check the cart — it should be empty
Pesewas vs GHS: Paystack amounts are in the smallest currency unit. For GHS, that's pesewas (100 pesewas = 1 GHS). Multiply your GHS amount by 100 before passing it to the Charge object. A GHS 180.00 dress should be passed as 18000.
Project structure after Part 5
lib/
features/
checkout/
checkout_screen.dart
order_confirmation_screen.dart
models/
order.dart
services/
order_service.dart
What's next
In Part 6 we build the order history screen — a list of the user's past orders with status indicators and an expandable detail view showing what was in each order.
BlocWeave