minor fixes
This commit is contained in:
3
.vscode/launch.json
vendored
3
.vscode/launch.json
vendored
@@ -11,7 +11,8 @@
|
||||
"deviceId": "chrome",
|
||||
"args": [
|
||||
"--dart-define=APP_ENV=test",
|
||||
"--web-port=9005"
|
||||
"--web-port=9005",
|
||||
"--dart-define=BASE_URL=http://localhost:6950/api"
|
||||
]
|
||||
},
|
||||
|
||||
|
||||
@@ -32,7 +32,12 @@ WORKDIR $APP
|
||||
# Run build: 1 - clean, 2 - pub get, 3 - build web
|
||||
RUN flutter clean
|
||||
RUN flutter pub get
|
||||
RUN flutter build web --dart-define=APP_ENV=live
|
||||
RUN flutter build web \
|
||||
--dart-define=APP_ENV=live \
|
||||
--dart-define=BASE_URL=https://payapi.velocityafrica.net/api \
|
||||
--dart-define=CLIENTID=77433712483-ng7pntvcpf6tnjccriuqm8dbna8vvp3b.apps.googleusercontent.com \
|
||||
--dart-define=SIMULATE_PAYMENT_SUCCESS=false \
|
||||
--dart-define=GATEWAY_SCRIPT_URL=https://na.gateway.mastercard.com/static/checkout/checkout.min.js
|
||||
|
||||
# once heare the app will be compiled and ready to deploy
|
||||
|
||||
|
||||
53
lib/config/app_config.dart
Normal file
53
lib/config/app_config.dart
Normal file
@@ -0,0 +1,53 @@
|
||||
/// Application configuration sourced entirely from compile-time
|
||||
/// `--dart-define` flags. No `.env` file is read at runtime, so no
|
||||
/// secrets can leak into the web bundle via asset files.
|
||||
///
|
||||
/// Every value has a sensible default so the project still builds and
|
||||
/// runs locally without specifying any flags.
|
||||
class AppConfig {
|
||||
AppConfig._();
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
// Compile-time values (set via `--dart-define=<KEY>=<VALUE>`)
|
||||
// -----------------------------------------------------------------
|
||||
|
||||
/// Runtime environment: `test`, `live`, etc.
|
||||
static const String env = String.fromEnvironment(
|
||||
'APP_ENV',
|
||||
defaultValue: 'test',
|
||||
);
|
||||
|
||||
/// Base URL of the backend API.
|
||||
static const String baseUrl = String.fromEnvironment(
|
||||
'BASE_URL',
|
||||
defaultValue: 'http://localhost:6950/api',
|
||||
);
|
||||
|
||||
/// Google OAuth web client ID. This is *not* a secret — it is
|
||||
/// intended to be embedded in public-facing web applications.
|
||||
static const String clientId = String.fromEnvironment(
|
||||
'CLIENTID',
|
||||
defaultValue: '',
|
||||
);
|
||||
|
||||
/// When `true` the payment gateway screens skip the real flow and
|
||||
/// return a simulated success immediately. Useful during development.
|
||||
static const bool simulatePaymentSuccess = bool.fromEnvironment(
|
||||
'SIMULATE_PAYMENT_SUCCESS',
|
||||
defaultValue: false,
|
||||
);
|
||||
|
||||
/// URL of the Mastercard Gateway checkout JavaScript bundle.
|
||||
static const String gatewayScriptUrl = String.fromEnvironment(
|
||||
'GATEWAY_SCRIPT_URL',
|
||||
defaultValue:
|
||||
'https://test-gateway.mastercard.com/static/checkout/checkout.min.js',
|
||||
);
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
// Helpers
|
||||
// -----------------------------------------------------------------
|
||||
|
||||
/// `true` when [env] is `live`.
|
||||
static bool get isLive => env.toLowerCase() == 'live';
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:logger/logger.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:qpay/config/app_config.dart';
|
||||
|
||||
var logger = Logger(printer: PrettyPrinter());
|
||||
|
||||
class Http {
|
||||
final Dio dio = Dio();
|
||||
|
||||
final String baseUrl = dotenv.env['BASE_URL'] ?? '';
|
||||
final String baseUrl = AppConfig.baseUrl;
|
||||
|
||||
Http() {
|
||||
dio.options.baseUrl = baseUrl;
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import 'dart:async';
|
||||
import 'dart:js_interop';
|
||||
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:qpay/config/app_config.dart';
|
||||
import 'package:web/web.dart' as web;
|
||||
|
||||
const String _defaultGatewayScriptUrl =
|
||||
'https://test-gateway.mastercard.com/static/checkout/checkout.min.js';
|
||||
|
||||
@JS('Checkout')
|
||||
external JSAny? _checkout;
|
||||
|
||||
@@ -23,8 +20,7 @@ Future<void> ensureCheckoutScriptLoaded() async {
|
||||
return;
|
||||
}
|
||||
|
||||
final scriptUrl =
|
||||
dotenv.env['GATEWAY_SCRIPT_URL'] ?? _defaultGatewayScriptUrl;
|
||||
final scriptUrl = AppConfig.gatewayScriptUrl;
|
||||
|
||||
final scriptElement = web.HTMLScriptElement()
|
||||
..id = 'mastercard-checkout-script'
|
||||
|
||||
@@ -10,23 +10,9 @@ import 'package:qpay/providers/splash_provider.dart';
|
||||
import 'package:qpay/screens/workspaces/workspace_provider.dart';
|
||||
import 'package:qpay/providers/uptime_provider.dart';
|
||||
import 'package:qpay/theme/app_theme.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:firebase_core/firebase_core.dart';
|
||||
import 'firebase_options.dart';
|
||||
|
||||
const String testEnv = 'assets/.env.test';
|
||||
const String liveEnv = 'assets/.env.live';
|
||||
const String appEnv = String.fromEnvironment('APP_ENV', defaultValue: 'test');
|
||||
|
||||
String resolveEnvFile(String env) {
|
||||
switch (env.toLowerCase()) {
|
||||
case 'live':
|
||||
return liveEnv;
|
||||
case 'test':
|
||||
default:
|
||||
return testEnv;
|
||||
}
|
||||
}
|
||||
import 'config/app_config.dart';
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
@@ -35,8 +21,6 @@ void main() async {
|
||||
}
|
||||
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
|
||||
|
||||
await dotenv.load(fileName: resolveEnvFile(appEnv));
|
||||
|
||||
// Read the persisted auth token before the first frame so the router
|
||||
// knows whether the user is already signed in on cold start. Without
|
||||
// this we would briefly treat logged-in users as guests and bounce
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:qpay/config/app_config.dart';
|
||||
import 'package:qpay/screens/gateway/gateway_controller.dart';
|
||||
import 'package:qpay/widgets/app_snack_bar.dart';
|
||||
import 'package:webview_flutter/webview_flutter.dart';
|
||||
@@ -56,7 +56,7 @@ class _GatewayScreenState extends State<GatewayScreen> {
|
||||
)
|
||||
..loadRequest(Uri.parse(url));
|
||||
|
||||
bool simulate = bool.parse(dotenv.env['SIMULATE_PAYMENT_SUCCESS']!);
|
||||
bool simulate = AppConfig.simulatePaymentSuccess;
|
||||
if (simulate) {
|
||||
await Future.delayed(Duration(seconds: 10));
|
||||
String targetUrl = url.replaceAll("/pay/", "/receipt/");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:qpay/config/app_config.dart';
|
||||
import 'package:qpay/models/responsive_policy.dart';
|
||||
import 'package:qpay/screens/gateway/gateway_controller.dart';
|
||||
import 'package:qpay/browser.dart';
|
||||
@@ -34,9 +34,7 @@ class _GatewayWebScreenState extends State<GatewayWebScreen> {
|
||||
redirecting = true;
|
||||
});
|
||||
|
||||
bool simulate = bool.parse(
|
||||
dotenv.env['SIMULATE_PAYMENT_SUCCESS'] ?? 'false',
|
||||
);
|
||||
bool simulate = AppConfig.simulatePaymentSuccess;
|
||||
if (simulate) {
|
||||
// In simulation mode, just go to polling
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
|
||||
@@ -294,14 +294,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.9+2"
|
||||
flutter_dotenv:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_dotenv
|
||||
sha256: b7c7be5cd9f6ef7a78429cabd2774d3c4af50e79cb2b7593e3d5d763ef95c61b
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "5.2.1"
|
||||
flutter_lints:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
|
||||
@@ -46,7 +46,6 @@ dependencies:
|
||||
timeago: ^3.6.1
|
||||
freezed_annotation: ^3.0.0
|
||||
json_annotation: ^4.9.0
|
||||
flutter_dotenv: ^5.2.1
|
||||
logger: ^2.6.0
|
||||
webview_flutter: ^4.13.0
|
||||
widgets_to_image: ^2.0.1
|
||||
|
||||
Reference in New Issue
Block a user