minor fixes
This commit is contained in:
3
.vscode/launch.json
vendored
3
.vscode/launch.json
vendored
@@ -11,7 +11,8 @@
|
|||||||
"deviceId": "chrome",
|
"deviceId": "chrome",
|
||||||
"args": [
|
"args": [
|
||||||
"--dart-define=APP_ENV=test",
|
"--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 build: 1 - clean, 2 - pub get, 3 - build web
|
||||||
RUN flutter clean
|
RUN flutter clean
|
||||||
RUN flutter pub get
|
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
|
# 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:dio/dio.dart';
|
||||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
|
||||||
import 'package:logger/logger.dart';
|
import 'package:logger/logger.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
import 'package:qpay/config/app_config.dart';
|
||||||
|
|
||||||
var logger = Logger(printer: PrettyPrinter());
|
var logger = Logger(printer: PrettyPrinter());
|
||||||
|
|
||||||
class Http {
|
class Http {
|
||||||
final Dio dio = Dio();
|
final Dio dio = Dio();
|
||||||
|
|
||||||
final String baseUrl = dotenv.env['BASE_URL'] ?? '';
|
final String baseUrl = AppConfig.baseUrl;
|
||||||
|
|
||||||
Http() {
|
Http() {
|
||||||
dio.options.baseUrl = baseUrl;
|
dio.options.baseUrl = baseUrl;
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:js_interop';
|
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;
|
import 'package:web/web.dart' as web;
|
||||||
|
|
||||||
const String _defaultGatewayScriptUrl =
|
|
||||||
'https://test-gateway.mastercard.com/static/checkout/checkout.min.js';
|
|
||||||
|
|
||||||
@JS('Checkout')
|
@JS('Checkout')
|
||||||
external JSAny? _checkout;
|
external JSAny? _checkout;
|
||||||
|
|
||||||
@@ -23,8 +20,7 @@ Future<void> ensureCheckoutScriptLoaded() async {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final scriptUrl =
|
final scriptUrl = AppConfig.gatewayScriptUrl;
|
||||||
dotenv.env['GATEWAY_SCRIPT_URL'] ?? _defaultGatewayScriptUrl;
|
|
||||||
|
|
||||||
final scriptElement = web.HTMLScriptElement()
|
final scriptElement = web.HTMLScriptElement()
|
||||||
..id = 'mastercard-checkout-script'
|
..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/screens/workspaces/workspace_provider.dart';
|
||||||
import 'package:qpay/providers/uptime_provider.dart';
|
import 'package:qpay/providers/uptime_provider.dart';
|
||||||
import 'package:qpay/theme/app_theme.dart';
|
import 'package:qpay/theme/app_theme.dart';
|
||||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
|
||||||
import 'package:firebase_core/firebase_core.dart';
|
import 'package:firebase_core/firebase_core.dart';
|
||||||
import 'firebase_options.dart';
|
import 'firebase_options.dart';
|
||||||
|
import 'config/app_config.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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
@@ -35,8 +21,6 @@ void main() async {
|
|||||||
}
|
}
|
||||||
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
|
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
|
||||||
|
|
||||||
await dotenv.load(fileName: resolveEnvFile(appEnv));
|
|
||||||
|
|
||||||
// Read the persisted auth token before the first frame so the router
|
// Read the persisted auth token before the first frame so the router
|
||||||
// knows whether the user is already signed in on cold start. Without
|
// knows whether the user is already signed in on cold start. Without
|
||||||
// this we would briefly treat logged-in users as guests and bounce
|
// this we would briefly treat logged-in users as guests and bounce
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
|
||||||
import 'package:go_router/go_router.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/screens/gateway/gateway_controller.dart';
|
||||||
import 'package:qpay/widgets/app_snack_bar.dart';
|
import 'package:qpay/widgets/app_snack_bar.dart';
|
||||||
import 'package:webview_flutter/webview_flutter.dart';
|
import 'package:webview_flutter/webview_flutter.dart';
|
||||||
@@ -56,7 +56,7 @@ class _GatewayScreenState extends State<GatewayScreen> {
|
|||||||
)
|
)
|
||||||
..loadRequest(Uri.parse(url));
|
..loadRequest(Uri.parse(url));
|
||||||
|
|
||||||
bool simulate = bool.parse(dotenv.env['SIMULATE_PAYMENT_SUCCESS']!);
|
bool simulate = AppConfig.simulatePaymentSuccess;
|
||||||
if (simulate) {
|
if (simulate) {
|
||||||
await Future.delayed(Duration(seconds: 10));
|
await Future.delayed(Duration(seconds: 10));
|
||||||
String targetUrl = url.replaceAll("/pay/", "/receipt/");
|
String targetUrl = url.replaceAll("/pay/", "/receipt/");
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
|
||||||
import 'package:go_router/go_router.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/models/responsive_policy.dart';
|
||||||
import 'package:qpay/screens/gateway/gateway_controller.dart';
|
import 'package:qpay/screens/gateway/gateway_controller.dart';
|
||||||
import 'package:qpay/browser.dart';
|
import 'package:qpay/browser.dart';
|
||||||
@@ -34,9 +34,7 @@ class _GatewayWebScreenState extends State<GatewayWebScreen> {
|
|||||||
redirecting = true;
|
redirecting = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
bool simulate = bool.parse(
|
bool simulate = AppConfig.simulatePaymentSuccess;
|
||||||
dotenv.env['SIMULATE_PAYMENT_SUCCESS'] ?? 'false',
|
|
||||||
);
|
|
||||||
if (simulate) {
|
if (simulate) {
|
||||||
// In simulation mode, just go to polling
|
// In simulation mode, just go to polling
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
|||||||
@@ -294,14 +294,6 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.9+2"
|
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:
|
flutter_lints:
|
||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
description:
|
description:
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ dependencies:
|
|||||||
timeago: ^3.6.1
|
timeago: ^3.6.1
|
||||||
freezed_annotation: ^3.0.0
|
freezed_annotation: ^3.0.0
|
||||||
json_annotation: ^4.9.0
|
json_annotation: ^4.9.0
|
||||||
flutter_dotenv: ^5.2.1
|
|
||||||
logger: ^2.6.0
|
logger: ^2.6.0
|
||||||
webview_flutter: ^4.13.0
|
webview_flutter: ^4.13.0
|
||||||
widgets_to_image: ^2.0.1
|
widgets_to_image: ^2.0.1
|
||||||
|
|||||||
Reference in New Issue
Block a user