6177214e-ce7c-49e3-99de-ff9721b26f63 — Commit 65be35ce
Changed files
.../.generated/services/adyen/adyen_line_item.g.dart | 20 +++++++++++--------- .../lib/pregistration/pregistration_repository.dart | 18 +++--------------- .../lib/services/adyen/payment_event_handler.dart | 12 ++++++------ 3 files changed, 20 insertions(+), 30 deletions(-)
Diff
diff --git a/comwell_key_app/lib/.generated/services/adyen/adyen_line_item.g.dart b/comwell_key_app/lib/.generated/services/adyen/adyen_line_item.g.dart
index 594dc84c..68228837 100644
--- a/comwell_key_app/lib/.generated/services/adyen/adyen_line_item.g.dart
+++ b/comwell_key_app/lib/.generated/services/adyen/adyen_line_item.g.dart
@@ -21,13 +21,15 @@ AdyenLineItem _$AdyenLineItemFromJson(Map<String, dynamic> json) =>
Map<String, dynamic> _$AdyenLineItemToJson(AdyenLineItem instance) =>
<String, dynamic>{
- 'quantity': instance.quantity,
- 'amountExcludingTax': instance.amountExcludingTax,
- 'taxPercentage': instance.taxPercentage,
- 'description': instance.description,
- 'id': instance.id,
- 'taxAmount': instance.taxAmount,
- 'amountIncludingTax': instance.amountIncludingTax,
- 'productUrl': instance.productUrl,
- 'imageUrl': instance.imageUrl,
+ if (instance.quantity case final value?) 'quantity': value,
+ if (instance.amountExcludingTax case final value?)
+ 'amountExcludingTax': value,
+ if (instance.taxPercentage case final value?) 'taxPercentage': value,
+ if (instance.description case final value?) 'description': value,
+ if (instance.id case final value?) 'id': value,
+ if (instance.taxAmount case final value?) 'taxAmount': value,
+ if (instance.amountIncludingTax case final value?)
+ 'amountIncludingTax': value,
+ if (instance.productUrl case final value?) 'productUrl': value,
+ if (instance.imageUrl case final value?) 'imageUrl': value,
};
diff --git a/comwell_key_app/lib/pregistration/pregistration_repository.dart b/comwell_key_app/lib/pregistration/pregistration_repository.dart
index 713e8ffe..77dfdcd9 100644
--- a/comwell_key_app/lib/pregistration/pregistration_repository.dart
+++ b/comwell_key_app/lib/pregistration/pregistration_repository.dart
@@ -25,17 +25,11 @@ class PreregistrationRepository {
return response.data!.storedPaymentMethods;
}
- Future<PaymentEvent> onSubmit(
- Map<String, dynamic> data, [
- Map<String, dynamic>? extra,
- ]) async {
- final user = await profileSettingsRepository.fetchProfileSettings();
- if (user == null) throw Exception("User not logged in");
+ Future<PaymentEvent> onSubmit(Map<String, dynamic> data, [Map<String, dynamic>? extra]) async {
String returnUrl = await determineBaseReturnUrl();
returnUrl += "/adyenPayment";
final paymentsRequestData = PaymentsRequestData(
merchantAccount: AdyenConstants.merchantAccount,
- shopperReference: user.shopperReference,
reference: "booking_${DateTime.now().millisecondsSinceEpoch}",
returnUrl: returnUrl,
amount: AdyenAmount.named(
@@ -57,27 +51,21 @@ class PreregistrationRepository {
mergedJson.addAll(data);
mergedJson.addAll(paymentsRequestData.toJson());
final response = await api.postPaymentsDetails(mergedJson);
- return PaymentEventHandler().handleResponse(jsonResponse: response);
+ return PaymentEventHandler.fromJson(jsonResponse: response);
}
Future<PaymentEvent> onAdditionalDetails(
Map<String, dynamic> additionalDetails) async {
final response = await api.postPaymentsDetails(additionalDetails);
- return PaymentEventHandler().handleResponse(jsonResponse: response);
+ return PaymentEventHandler.fromJson(jsonResponse: response);
}
static final Iterable<StoredPaymentMethod> _mockData = [1, 2, 3, 4].map((i) =>
StoredPaymentMethod(
- brand: "brand",
expiryMonth: "expiryMonth",
expiryYear: "expiryYear",
holderName: "holderName",
id: "id $i",
lastFour: "$i$i$i$i",
- name: "name $i",
- shopperEmail: "shopperEmail",
- supportedRecurringProcessingModels: const [
- "supportedRecurringProcessingModels"
- ],
type: "visa"));
}
diff --git a/comwell_key_app/lib/services/adyen/payment_event_handler.dart b/comwell_key_app/lib/services/adyen/payment_event_handler.dart
index e64a4d28..b1c15ddf 100644
--- a/comwell_key_app/lib/services/adyen/payment_event_handler.dart
+++ b/comwell_key_app/lib/services/adyen/payment_event_handler.dart
@@ -9,7 +9,7 @@ class PaymentEventHandler {
static const messageKey = "message";
static const refusalReasonKey = "refusalReason";
- PaymentEvent handleResponse({
+ static PaymentEvent fromJson({
required Json jsonResponse,
Json updatedPaymentMethodsJson = const {},
}) {
@@ -49,7 +49,7 @@ class PaymentEventHandler {
return Finished(resultCode: "EMPTY");
}
- bool _isError(Json jsonResponse) {
+ static bool _isError(Json jsonResponse) {
final hasErrorCodeKey = jsonResponse.containsKey(errorCodeKey);
final hasErrorResultCode = (jsonResponse[resultCodeKey] as String?)
?.toUpperCase()
@@ -58,17 +58,17 @@ class PaymentEventHandler {
return hasErrorCodeKey || hasErrorResultCode;
}
- bool _isRefusedInPartialPaymentFlow(Json jsonResponse) =>
+ static bool _isRefusedInPartialPaymentFlow(Json jsonResponse) =>
_isRefused(jsonResponse) && _isNonFullyPaidOrder(jsonResponse);
- bool _isRefused(Json jsonResponse) => jsonResponse[resultCodeKey]
+ static bool _isRefused(Json jsonResponse) => jsonResponse[resultCodeKey]
.toString()
.toUpperCase()
.contains(ResultCode.refused.name.toUpperCase());
- bool _isAction(Json jsonResponse) => jsonResponse.containsKey(actionKey);
+ static bool _isAction(Json jsonResponse) => jsonResponse.containsKey(actionKey);
- bool _isNonFullyPaidOrder(Json jsonResponse) {
+ static bool _isNonFullyPaidOrder(Json jsonResponse) {
if (jsonResponse.containsKey("order")) {
final num remainingAmount =
jsonResponse["order"]["remainingAmount"]["value"] as num;