Skip to content

Commit

Permalink
Improved naming of orderCancelResult class properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert-SD committed Nov 21, 2024
1 parent 3858cae commit d79c350
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1183,22 +1183,22 @@ data class ActionComponentConfigurationDTO (

/** Generated class from Pigeon that represents data sent in messages. */
data class OrderCancelResultDTO (
val orderCancelJson: Map<String?, Any?>,
val updatedPaymentMethodsJson: Map<String?, Any?>? = null
val orderCancelResponseBody: Map<String?, Any?>,
val updatedPaymentMethodsResponseBody: Map<String?, Any?>? = null

) {
companion object {
@Suppress("UNCHECKED_CAST")
fun fromList(list: List<Any?>): OrderCancelResultDTO {
val orderCancelJson = list[0] as Map<String?, Any?>
val updatedPaymentMethodsJson = list[1] as Map<String?, Any?>?
return OrderCancelResultDTO(orderCancelJson, updatedPaymentMethodsJson)
val orderCancelResponseBody = list[0] as Map<String?, Any?>
val updatedPaymentMethodsResponseBody = list[1] as Map<String?, Any?>?
return OrderCancelResultDTO(orderCancelResponseBody, updatedPaymentMethodsResponseBody)
}
}
fun toList(): List<Any?> {
return listOf<Any?>(
orderCancelJson,
updatedPaymentMethodsJson,
orderCancelResponseBody,
updatedPaymentMethodsResponseBody,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,11 @@ class AdvancedDropInService : DropInService(), LifecycleOwner {
orderCancelResponseDTO: OrderCancelResultDTO?
): DropInServiceResult? {
try {
val orderCancelResponseBody = orderCancelResponseDTO?.orderCancelJson?.let { JSONObject(it) }
val orderCancelResponseBody = orderCancelResponseDTO?.orderCancelResponseBody?.let { JSONObject(it) }
return when (val resultCode = orderCancelResponseBody?.optString(Constants.RESULT_CODE_KEY)) {
"Received" -> {
if (orderCancelResponseDTO.updatedPaymentMethodsJson?.isNotEmpty() == true) {
val updatedPaymentMethods = orderCancelResponseDTO.updatedPaymentMethodsJson
if (orderCancelResponseDTO.updatedPaymentMethodsResponseBody?.isNotEmpty() == true) {
val updatedPaymentMethods = orderCancelResponseDTO.updatedPaymentMethodsResponseBody
val paymentMethods =
PaymentMethodsApiResponse.SERIALIZER.deserialize(JSONObject(updatedPaymentMethods))
val orderResponse = OrderResponse.SERIALIZER.deserialize(orderCancelResponseBody)
Expand Down
25 changes: 13 additions & 12 deletions example/lib/repositories/adyen_drop_in_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,11 @@ class AdyenDropInRepository extends AdyenBaseRepository {
);
}

Future<Map<String, dynamic>> onCheckBalance(
Map<String, dynamic> balanceRequestBody) async {
balanceRequestBody.addAll({"merchantAccount": Config.merchantAccount});
return service.postPaymentMethodsBalance(balanceRequestBody);
Future<Map<String, dynamic>> onCheckBalance({
required Map<String, dynamic> balanceCheckRequestBody,
}) async {
balanceCheckRequestBody.addAll({"merchantAccount": Config.merchantAccount});
return service.postPaymentMethodsBalance(balanceCheckRequestBody);
}

Future<Map<String, dynamic>> onRequestOrder() async {
Expand All @@ -184,21 +185,21 @@ class AdyenDropInRepository extends AdyenBaseRepository {
return service.postOrders(orderRequestBody);
}

Future<OrderCancelResult> onCancelOrder(
bool shouldUpdatePaymentMethods,
Map<String, dynamic> order,
) async {
Future<OrderCancelResult> onCancelOrder({
required bool shouldUpdatePaymentMethods,
required Map<String, dynamic> order,
}) async {
final orderCancelRequestBody = <String, dynamic>{
"merchantAccount": Config.merchantAccount,
"order": order,
};
final Map<String, dynamic> orderCancelJson =
final Map<String, dynamic> cancelResponse =
await service.postOrdersCancel(orderCancelRequestBody);
final OrderCancelResult orderCancelResult =
OrderCancelResult(orderCancelJson: orderCancelJson);
OrderCancelResult(orderCancelResponseBody: cancelResponse);
if (shouldUpdatePaymentMethods == true) {
final paymentMethodsJson = await fetchPaymentMethods();
orderCancelResult.updatedPaymentMethodsJson = paymentMethodsJson;
orderCancelResult.updatedPaymentMethodsResponseBody =
await fetchPaymentMethods();
}

return orderCancelResult;
Expand Down
16 changes: 8 additions & 8 deletions ios/Classes/PlatformApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1242,23 +1242,23 @@ struct ActionComponentConfigurationDTO {

/// Generated class from Pigeon that represents data sent in messages.
struct OrderCancelResultDTO {
var orderCancelJson: [String?: Any?]
var updatedPaymentMethodsJson: [String?: Any?]?
var orderCancelResponseBody: [String?: Any?]
var updatedPaymentMethodsResponseBody: [String?: Any?]?

static func fromList(_ list: [Any?]) -> OrderCancelResultDTO? {
let orderCancelJson = list[0] as! [String?: Any?]
let updatedPaymentMethodsJson: [String?: Any?]? = nilOrValue(list[1])
let orderCancelResponseBody = list[0] as! [String?: Any?]
let updatedPaymentMethodsResponseBody: [String?: Any?]? = nilOrValue(list[1])

return OrderCancelResultDTO(
orderCancelJson: orderCancelJson,
updatedPaymentMethodsJson: updatedPaymentMethodsJson
orderCancelResponseBody: orderCancelResponseBody,
updatedPaymentMethodsResponseBody: updatedPaymentMethodsResponseBody
)
}

func toList() -> [Any?] {
[
orderCancelJson,
updatedPaymentMethodsJson
orderCancelResponseBody,
updatedPaymentMethodsResponseBody
]
}
}
Expand Down
8 changes: 4 additions & 4 deletions lib/src/common/model/partial_payment/order_cancel_result.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class OrderCancelResult {
final Map<String, dynamic> orderCancelJson;
Map<String, dynamic>? updatedPaymentMethodsJson;
final Map<String, dynamic> orderCancelResponseBody;
Map<String, dynamic>? updatedPaymentMethodsResponseBody;

OrderCancelResult({
required this.orderCancelJson,
this.updatedPaymentMethodsJson,
required this.orderCancelResponseBody,
this.updatedPaymentMethodsResponseBody,
});
}
15 changes: 9 additions & 6 deletions lib/src/common/model/partial_payment/partial_payment.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import 'package:adyen_checkout/src/common/model/partial_payment/order_cancel_result.dart';

class PartialPayment {
Future<Map<String, dynamic>> Function(Map<String, dynamic> requestBody)
onCheckBalance;
Future<Map<String, dynamic>> Function({
required Map<String, dynamic> balanceCheckRequestBody,
}) onCheckBalance;

Future<Map<String, dynamic>> Function() onRequestOrder;
Future<OrderCancelResult> Function(
bool shouldUpdatePaymentMethods,
Map<String, dynamic> order,
) onCancelOrder;

Future<OrderCancelResult> Function({
required bool shouldUpdatePaymentMethods,
required Map<String, dynamic> order,
}) onCancelOrder;

PartialPayment({
required this.onCheckBalance,
Expand Down
17 changes: 9 additions & 8 deletions lib/src/drop_in/drop_in.dart
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ class DropIn {
Constants.paymentMethodKey: data[Constants.paymentMethodKey],
Constants.amountKey: data[Constants.amountKey],
};
final balanceCheckResponse =
await partialPayment?.onCheckBalance(balanceCheckRequestBody);
final balanceCheckResponse = await partialPayment?.onCheckBalance(
balanceCheckRequestBody: balanceCheckRequestBody);
dropInPlatformApi.onBalanceCheckResult(jsonEncode(balanceCheckResponse));
} catch (error) {
dropInPlatformApi.onBalanceCheckResult(error.toString());
Expand All @@ -318,16 +318,17 @@ class DropIn {
try {
final orderResponse = jsonDecode(event.data as String);
final orderCancelResponse = await partialPayment?.onCancelOrder(
orderResponse[Constants.shouldUpdatePaymentMethodsKey] as bool? ??
false,
orderResponse[Constants.orderKey],
shouldUpdatePaymentMethods:
orderResponse[Constants.shouldUpdatePaymentMethodsKey] as bool? ??
false,
order: orderResponse[Constants.orderKey],
);
final orderCancelResponseDTO = orderCancelResponse?.toDTO() ??
OrderCancelResultDTO(orderCancelJson: {});
OrderCancelResultDTO(orderCancelResponseBody: {});
dropInPlatformApi.onOrderCancelResult(orderCancelResponseDTO);
} catch (error) {
dropInPlatformApi
.onOrderCancelResult(OrderCancelResultDTO(orderCancelJson: {}));
dropInPlatformApi.onOrderCancelResult(
OrderCancelResultDTO(orderCancelResponseBody: {}));
}
}
}
16 changes: 8 additions & 8 deletions lib/src/generated/platform_api.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1386,27 +1386,27 @@ class ActionComponentConfigurationDTO {

class OrderCancelResultDTO {
OrderCancelResultDTO({
required this.orderCancelJson,
this.updatedPaymentMethodsJson,
required this.orderCancelResponseBody,
this.updatedPaymentMethodsResponseBody,
});

Map<String?, Object?> orderCancelJson;
Map<String?, Object?> orderCancelResponseBody;

Map<String?, Object?>? updatedPaymentMethodsJson;
Map<String?, Object?>? updatedPaymentMethodsResponseBody;

Object encode() {
return <Object?>[
orderCancelJson,
updatedPaymentMethodsJson,
orderCancelResponseBody,
updatedPaymentMethodsResponseBody,
];
}

static OrderCancelResultDTO decode(Object result) {
result as List<Object?>;
return OrderCancelResultDTO(
orderCancelJson:
orderCancelResponseBody:
(result[0] as Map<Object?, Object?>?)!.cast<String?, Object?>(),
updatedPaymentMethodsJson:
updatedPaymentMethodsResponseBody:
(result[1] as Map<Object?, Object?>?)?.cast<String?, Object?>(),
);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/util/dto_mapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ extension ActionComponentConfigurationMapper on ActionComponentConfiguration {

extension OrderCancelResponseMapper on OrderCancelResult {
OrderCancelResultDTO toDTO() => OrderCancelResultDTO(
orderCancelJson: orderCancelJson,
updatedPaymentMethodsJson: updatedPaymentMethodsJson,
orderCancelResponseBody: orderCancelResponseBody,
updatedPaymentMethodsResponseBody: updatedPaymentMethodsResponseBody,
);
}
8 changes: 4 additions & 4 deletions pigeons/platform_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -577,12 +577,12 @@ class ActionComponentConfigurationDTO {
}

class OrderCancelResultDTO {
final Map<String?, Object?> orderCancelJson;
final Map<String?, Object?>? updatedPaymentMethodsJson;
final Map<String?, Object?> orderCancelResponseBody;
final Map<String?, Object?>? updatedPaymentMethodsResponseBody;

OrderCancelResultDTO(
this.orderCancelJson,
this.updatedPaymentMethodsJson,
this.orderCancelResponseBody,
this.updatedPaymentMethodsResponseBody,
);
}

Expand Down

0 comments on commit d79c350

Please sign in to comment.