close method
Closes a split payment order.
Calls POST /api/SplitPayment/close to authoritatively mark the
split session as fully paid on the backend.
Returns null when no events are found for the given splitPaymentId.
Implementation
Future<SplitCloseResult?> close(
String splitPaymentId, {
String? operationId,
}) async {
return _monitoring.monitorAction<SplitCloseResult?>(
actionName: 'split_close_order',
provider: 'split_payments',
action: (_) async {
final url = '$_paymentsUrl/SplitPayment/close';
_logger.info(
this,
'close: closing — splitPaymentId=$splitPaymentId, '
'operationId=$operationId',
);
try {
final response = await _httpClient.post(
url: url,
additionalHeaders: {'Content-Type': 'application/json'},
requestData: {
'splitPaymentId': splitPaymentId,
},
user: _authService.user,
);
if (response != null && response.statusCode == 200) {
final data = response.data is String
? jsonDecode(response.data as String) as Map<String, dynamic>
: response.data as Map<String, dynamic>;
_logger.info(
this,
'close: succeeded — '
'state=${data['state']}, totalAmountPaid=${data['totalAmountPaid']}, '
'operationId=$operationId',
);
return SplitCloseResult.fromJson(data);
}
if (response != null && response.statusCode == 404) {
_logger.info(
this,
'close: no events found for splitPaymentId=$splitPaymentId',
);
return null;
}
_logger.error(
this,
'close failed: ${response?.statusCode} ${response?.statusMessage}',
);
throw PlatformException(
code: 'CLOSE_SPLIT_FAILED',
message:
'Failed to close split payment: ${response?.statusCode ?? 'no response'}',
);
} catch (e, st) {
_logger.error(
this,
'Error closing split payment: $e',
error: e,
stackTrace: st,
);
rethrow;
}
},
logAnalytics: true,
analyticsEventName: 'split_order_closed',
);
}