6177214e-ce7c-49e3-99de-ff9721b26f63 — Commit 3ba56e52

AuthorMikkel Thygesen<mth@dwarf.dk>
Date2025-01-20 15:06:18 +0100
464: addressed PR comments

Changed files

.../models/add_card_payment_method.g.dart          | 30 ++++++++++
 .../.generated/profile_settings/model/user.g.dart  |  2 -
 comwell_key_app/lib/database/comwell_db.dart       | 66 +++++++++++-----------
 .../overview/repository/overview_repository.dart   |  2 +-
 .../pregistration/bloc/preregistration_cubit.dart  | 13 +++--
 .../lib/pregistration/components/add_card.dart     | 19 ++++---
 .../lib/pregistration/components/card_item.dart    |  2 +-
 .../models/add_card_payment_method.dart            | 25 ++++++++
 .../pregistration/pregistration_repository.dart    | 36 +++++++-----
 .../lib/services/adyen/adyen_amount.dart           |  6 +-
 10 files changed, 134 insertions(+), 67 deletions(-)

Diff

diff --git a/comwell_key_app/lib/.generated/pregistration/models/add_card_payment_method.g.dart b/comwell_key_app/lib/.generated/pregistration/models/add_card_payment_method.g.dart
new file mode 100644
index 00000000..465b9cd5
--- /dev/null
+++ b/comwell_key_app/lib/.generated/pregistration/models/add_card_payment_method.g.dart
@@ -0,0 +1,30 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of '../../../pregistration/models/add_card_payment_method.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+AddCardPaymentMethod _$AddCardPaymentMethodFromJson(
+ Map<String, dynamic> json) =>
+ AddCardPaymentMethod(
+ brands: (json['brands'] as List<dynamic>)
+ .map((e) => $enumDecode(_$CardTypeEnumMap, e)),
+ name: json['name'] as String,
+ type: json['type'] as String,
+ );
+
+Map<String, dynamic> _$AddCardPaymentMethodToJson(
+ AddCardPaymentMethod instance) =>
+ <String, dynamic>{
+ 'brands': instance.brands.map((e) => _$CardTypeEnumMap[e]!).toList(),
+ 'name': instance.name,
+ 'type': instance.type,
+ };
+
+const _$CardTypeEnumMap = {
+ CardType.visa: 'visa',
+ CardType.mc: 'mc',
+ CardType.amex: 'amex',
+};
diff --git a/comwell_key_app/lib/.generated/profile_settings/model/user.g.dart b/comwell_key_app/lib/.generated/profile_settings/model/user.g.dart
index 6c98b890..9134fbeb 100644
--- a/comwell_key_app/lib/.generated/profile_settings/model/user.g.dart
+++ b/comwell_key_app/lib/.generated/profile_settings/model/user.g.dart
@@ -8,7 +8,6 @@ part of '../../../profile_settings/model/user.dart';
User _$UserFromJson(Map<String, dynamic> json) => User(
id: json['id'] as String,
- shopperReference: json['shopperReference'] as String?,
firstName: json['firstName'] as String,
lastName: json['lastName'] as String,
countryCode: json['countryCode'] as String,
@@ -27,5 +26,4 @@ Map<String, dynamic> _$UserToJson(User instance) => <String, dynamic>{
'email': instance.email,
'address': instance.address,
'birthday': instance.birthday.toIso8601String(),
- 'shopperReference': instance.shopperReference,
};
diff --git a/comwell_key_app/lib/database/comwell_db.dart b/comwell_key_app/lib/database/comwell_db.dart
index df65458b..9db049be 100644
--- a/comwell_key_app/lib/database/comwell_db.dart
+++ b/comwell_key_app/lib/database/comwell_db.dart
@@ -22,6 +22,9 @@ const secureStorage = FlutterSecureStorage();
@DriftDatabase(
tables: [BookingEntity, UserEntity], daos: [BookingsDao, UserDAO])
class ComwellDatabase extends _$ComwellDatabase {
+ static const String _cipherKey = "sql_cipher";
+ static const String _dbFileName = "comwell.db.enc";
+
ComwellDatabase() : super(_openDatabase()) {
deleteDatabase();
}
@@ -40,42 +43,41 @@ class ComwellDatabase extends _$ComwellDatabase {
await databaseDir.delete();
}
}
-}
-Future<String> getCipher() async {
- final cipher = await secureStorage.read(key: "sql_cipher");
- if (cipher == null || cipher.isEmpty) {
- final newCipher =
- const uuid.Uuid().v4obj().toString(); //.uuid.replaceAll("-", "");
- await secureStorage.write(key: "sql_cipher", value: newCipher);
- } else {
- return cipher;
- }
+ static Future<String> getCipher() async {
+ final cipher = await secureStorage.read(key: _cipherKey);
+ if (cipher == null || cipher.isEmpty) {
+ final newCipher = const uuid.Uuid().v4obj().toString();
+ await secureStorage.write(key: _cipherKey, value: newCipher);
+ } else {
+ return cipher;
+ }
- return getCipher();
-}
+ return getCipher();
+ }
-QueryExecutor _openDatabase() {
- return LazyDatabase(() async {
- final path = await getApplicationSupportDirectory();
- final file = File(p.join(path.path, "app.db.enc"));
- final cipher = await getCipher();
- Future<void> isolateSetup() async {
- await applyWorkaroundToOpenSqlCipherOnOldAndroidVersions();
- open.overrideFor(OperatingSystem.android, openCipherOnAndroid);
- }
+ static QueryExecutor _openDatabase() {
+ return LazyDatabase(() async {
+ final path = await getApplicationSupportDirectory();
+ final file = File(p.join(path.path, _dbFileName));
+ final cipher = await getCipher();
+ Future<void> isolateSetup() async {
+ await applyWorkaroundToOpenSqlCipherOnOldAndroidVersions();
+ open.overrideFor(OperatingSystem.android, openCipherOnAndroid);
+ }
- void setup(Database db) {
- final result = db.select("pragma cipher_version");
- if (result.isEmpty) {
- throw UnsupportedError(
- "This database needs to run with SQLCipher, but that library is unavailable");
+ void setup(Database db) {
+ final result = db.select("pragma cipher_version");
+ if (result.isEmpty) {
+ throw UnsupportedError(
+ "This database needs to run with SQLCipher, but that library is unavailable");
+ }
+ db.execute("pragma key = \"$cipher\"");
+ db.execute("select count(*) from sqlite_master");
}
- db.execute("pragma key = \"$cipher\"");
- db.execute("select count(*) from sqlite_master");
- }
- return NativeDatabase.createInBackground(file,
- isolateSetup: isolateSetup, setup: setup);
- });
+ return NativeDatabase.createInBackground(file,
+ isolateSetup: isolateSetup, setup: setup);
+ });
+ }
}
diff --git a/comwell_key_app/lib/overview/repository/overview_repository.dart b/comwell_key_app/lib/overview/repository/overview_repository.dart
index 61a98ec4..16b5b869 100644
--- a/comwell_key_app/lib/overview/repository/overview_repository.dart
+++ b/comwell_key_app/lib/overview/repository/overview_repository.dart
@@ -14,7 +14,7 @@ class OverviewRepository {
//final response = await api.fetchAllBookingsForUser(userId);
//if (response != null) {
final bookings = Bookings.fromJson(response);
- await database.bookingsDao.insertBookings(bookings);
+ //await database.bookingsDao.insertBookings(bookings);
return bookings;
// } else {
// throw Exception('Failed to fetch bookings');
diff --git a/comwell_key_app/lib/pregistration/bloc/preregistration_cubit.dart b/comwell_key_app/lib/pregistration/bloc/preregistration_cubit.dart
index cae287b2..e0ee0953 100644
--- a/comwell_key_app/lib/pregistration/bloc/preregistration_cubit.dart
+++ b/comwell_key_app/lib/pregistration/bloc/preregistration_cubit.dart
@@ -3,6 +3,7 @@ import 'package:bloc/bloc.dart';
import 'package:comwell_key_app/pregistration/bloc/preregistration_state.dart';
import 'package:comwell_key_app/pregistration/pregistration_repository.dart';
import 'package:comwell_key_app/pregistration/preregistration_flow.dart';
+import 'package:comwell_key_app/services/adyen/adyen_amount.dart';
import 'package:comwell_key_app/services/adyen/stored_payment_method.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/cupertino.dart';
@@ -197,9 +198,11 @@ class PreregistrationCubit extends Cubit<PreregistrationState> {
emit(state.copyWith(termsAndConditionsAccepted: toggle));
}
- Checkout advancedCheckout() {
+ Checkout advancedCheckout(AdyenAmount amount) {
return AdvancedCheckout(
- onSubmit: _preregistrationRepository.onSubmit,
+ onSubmit: (data, [extra]) async {
+ return _preregistrationRepository.onSubmit(amount, data, extra);
+ },
onAdditionalDetails: _preregistrationRepository.onAdditionalDetails,
);
}
@@ -224,8 +227,10 @@ class PreregistrationCubit extends Cubit<PreregistrationState> {
void fetchPaymentMethods() async {
emit(state.copyWith(loading: true, error: null));
try {
- final paymentMethods = await _preregistrationRepository.getPaymentMethods();
- emit(state.copyWith(loading: false, storedPaymentMethods: paymentMethods));
+ final paymentMethods =
+ await _preregistrationRepository.getPaymentMethods();
+ emit(
+ state.copyWith(loading: false, storedPaymentMethods: paymentMethods));
} on Exception catch (e) {
emit(state.copyWith(error: e));
}
diff --git a/comwell_key_app/lib/pregistration/components/add_card.dart b/comwell_key_app/lib/pregistration/components/add_card.dart
index 12c75aa3..8d5bead9 100644
--- a/comwell_key_app/lib/pregistration/components/add_card.dart
+++ b/comwell_key_app/lib/pregistration/components/add_card.dart
@@ -1,5 +1,7 @@
import 'package:adyen_checkout/adyen_checkout.dart';
import 'package:comwell_key_app/pregistration/bloc/preregistration_cubit.dart';
+import 'package:comwell_key_app/pregistration/models/add_card_payment_method.dart';
+import 'package:comwell_key_app/services/adyen/adyen_amount.dart';
import 'package:comwell_key_app/themes/light_theme.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
@@ -18,16 +20,19 @@ class AddCard extends StatelessWidget {
_extractPaymentMethod(cubit.state.availablePaymentMethods);
final config = CardComponentConfiguration(
environment: Environment.test,
- clientKey: "ComwellHotelsECOM",
+ clientKey: "test_BY456IM6H5DRHEVXE7CPJEPGKMUCBRYO",
countryCode: "DK",
shopperLocale: "da-DK",
cardConfiguration:
const CardConfiguration(showStorePaymentField: true));
-
+
+ final amount = AdyenAmount(currency: "DKK", value: 0);
+ final paymentMethodConfig = AddCardPaymentMethod(
+ brands: [CardType.mc, CardType.visa], name: "Cards", type: "scheme");
return InkWell(
onTap: () async {
try {
- await showModalBottomSheet(
+ await showModalBottomSheet<void>(
isDismissible: false,
isScrollControlled: true,
context: context,
@@ -37,12 +42,8 @@ class AddCard extends StatelessWidget {
padding: MediaQuery.of(context).viewInsets,
child: AdyenCardComponent(
configuration: config,
- paymentMethod: const {
- "brands": ["mc", "visa", "amex"],
- "name": "Cards",
- "type": "scheme"
- },
- checkout: cubit.advancedCheckout(),
+ paymentMethod: paymentMethodConfig.toJson(),
+ checkout: cubit.advancedCheckout(amount),
onPaymentResult: cubit.onPaymentResult,
),
));
diff --git a/comwell_key_app/lib/pregistration/components/card_item.dart b/comwell_key_app/lib/pregistration/components/card_item.dart
index 2eab51e4..278a90cf 100644
--- a/comwell_key_app/lib/pregistration/components/card_item.dart
+++ b/comwell_key_app/lib/pregistration/components/card_item.dart
@@ -1,4 +1,4 @@
-import 'package:comwell_key_app/common/components/payment_card_image.dart';
+ import 'package:comwell_key_app/common/components/payment_card_image.dart';
import 'package:comwell_key_app/overview/models/payment_details.dart';
import 'package:comwell_key_app/pregistration/bloc/preregistration_cubit.dart';
import 'package:comwell_key_app/services/adyen/stored_payment_method.dart';
diff --git a/comwell_key_app/lib/pregistration/models/add_card_payment_method.dart b/comwell_key_app/lib/pregistration/models/add_card_payment_method.dart
new file mode 100644
index 00000000..6c71825f
--- /dev/null
+++ b/comwell_key_app/lib/pregistration/models/add_card_payment_method.dart
@@ -0,0 +1,25 @@
+import 'package:comwell_key_app/utils/json.dart';
+import 'package:json_annotation/json_annotation.dart';
+
+part '../../.generated/pregistration/models/add_card_payment_method.g.dart';
+
+enum CardType {
+ visa,
+ mc,
+ amex
+}
+
+@JsonSerializable()
+class AddCardPaymentMethod {
+ final Iterable<CardType> brands;
+ final String name;
+ final String type;
+
+ AddCardPaymentMethod({
+ required this.brands,
+ required this.name,
+ required this.type,
+ });
+
+ Json toJson() => _$AddCardPaymentMethodToJson(this);
+}
\ No newline at end of file
diff --git a/comwell_key_app/lib/pregistration/pregistration_repository.dart b/comwell_key_app/lib/pregistration/pregistration_repository.dart
index afe1a89d..a7cd95f4 100644
--- a/comwell_key_app/lib/pregistration/pregistration_repository.dart
+++ b/comwell_key_app/lib/pregistration/pregistration_repository.dart
@@ -1,3 +1,5 @@
+import 'dart:io';
+
import 'package:adyen_checkout/adyen_checkout.dart';
import 'package:comwell_key_app/common/const.dart';
import 'package:comwell_key_app/profile_settings/repostiory/profile_settings_repository.dart';
@@ -5,6 +7,7 @@ import 'package:comwell_key_app/services/adyen/extensions.dart';
import 'package:comwell_key_app/services/adyen/payment_event_handler.dart';
import 'package:comwell_key_app/services/adyen/stored_payment_method.dart';
import 'package:comwell_key_app/services/api.dart';
+import 'package:comwell_key_app/utils/json.dart';
import '../services/adyen/adyen_amount.dart';
import '../services/adyen/payment_request_data.dart';
@@ -14,38 +17,38 @@ import '../utils/payment_utils.dart';
class PreregistrationRepository {
final Api api = Api();
final ProfileSettingsRepository profileSettingsRepository =
- locator<ProfileSettingsRepository>();
+ locator<ProfileSettingsRepository>();
PreregistrationRepository();
Future<Iterable<StoredPaymentMethod>> getPaymentMethods() async {
+ return mockStoredPaymentData;
final response = await api.getPaymentMethods();
return response.data!.storedPaymentMethods;
}
- Future<PaymentEvent> onSubmit(Map<String, dynamic> data, [Map<String, dynamic>? extra]) async {
+ Future<PaymentEvent> onSubmit(AdyenAmount amount, Json data, [Json? extra]) async {
String returnUrl = await determineBaseReturnUrl();
returnUrl += "/adyenPayment";
final paymentsRequestData = PaymentsRequestData(
merchantAccount: AdyenConstants.merchantAccount,
- reference: "booking_${DateTime.now().millisecondsSinceEpoch}",
+ reference: "booking_${DateTime
+ .now()
+ .millisecondsSinceEpoch}",
returnUrl: returnUrl,
- amount: AdyenAmount.named(
- value: 0,
- currency: "DKK",
- ),
- countryCode: "da-DK",
+ amount: amount,
+ countryCode: Platform.localeName,
channel: determineChannel(),
recurringProcessingModel: RecurringProcessingModel.cardOnFile,
shopperInteraction:
- ShopperInteractionModel.ecommerce.shopperInteractionModelString,
+ ShopperInteractionModel.ecommerce.shopperInteractionModelString,
authenticationData: {
"threeDSRequestData": {
"nativeThreeDS": "preferred",
},
},
);
- final Map<String, dynamic> mergedJson = <String, dynamic>{};
+ Json mergedJson = <String, dynamic>{};
mergedJson.addAll(data);
mergedJson.addAll(paymentsRequestData.toJson());
final response = await api.postPaymentsDetails(mergedJson);
@@ -58,11 +61,16 @@ class PreregistrationRepository {
return PaymentEventHandler.fromJson(jsonResponse: response);
}
- static final Iterable<StoredPaymentMethod> mockStoredPaymentData = [1, 2, 3, 4].map((i) =>
+ static final Iterable<StoredPaymentMethod> mockStoredPaymentData = [
+ 1,
+ 2,
+ 3,
+ 4
+ ].map((i) =>
StoredPaymentMethod(
- expiryMonth: "expiryMonth",
- expiryYear: "expiryYear",
- holderName: "holderName",
+ expiryMonth: "12",
+ expiryYear: "2035",
+ holderName: "holder name",
id: "id $i",
lastFour: "$i$i$i$i",
type: "visa"));
diff --git a/comwell_key_app/lib/services/adyen/adyen_amount.dart b/comwell_key_app/lib/services/adyen/adyen_amount.dart
index 54b31cb8..f3b6c863 100644
--- a/comwell_key_app/lib/services/adyen/adyen_amount.dart
+++ b/comwell_key_app/lib/services/adyen/adyen_amount.dart
@@ -8,11 +8,9 @@ class AdyenAmount {
final String currency;
final int value;
- AdyenAmount.named({required this.currency, required this.value});
-
- AdyenAmount(this.currency, this.value);
-
factory AdyenAmount.fromJson(Json json) => _$AdyenAmountFromJson(json);
+ AdyenAmount({required this.currency, required this.value});
+
Json toJson() => _$AdyenAmountToJson(this);
}