getStateByOrder method
Fetches the current split payment state by order ID.
Calls GET /api/SplitPayment/state-by-order/{orderId}?businessId={businessId}
to retrieve the splitPaymentId and current state from the backend.
Returns null when no split session exists for the given order.
Implementation
Future<SplitPaymentStateResponse?> getStateByOrder(
String orderId,
String businessId, {
String? operationId,
}) async {
return _monitoring.monitorAction<SplitPaymentStateResponse?>(
actionName: 'split_get_state_by_order',
provider: 'split_payments',
action: (_) async {
final url =
'$_paymentsUrl/SplitPayment/state-by-order/$orderId?businessId=$businessId';
_logger.info(
this,
'getStateByOrder: fetching — orderId=$orderId, '
'businessId=$businessId, operationId=$operationId',
);
try {
final response = await _httpClient.get(
url: url,
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,
'getStateByOrder: succeeded — '
'state=${data['state']}, splitPaymentId=${data['splitPaymentId']}, '
'operationId=$operationId',
);
return SplitPaymentStateResponse.fromJson(data);
}
if (response != null && response.statusCode == 404) {
_logger.info(
this,
'getStateByOrder: no split session found for orderId=$orderId',
);
return null;
}
_logger.error(
this,
'getStateByOrder failed: ${response?.statusCode} ${response?.statusMessage}',
);
throw PlatformException(
code: 'GET_STATE_BY_ORDER_FAILED',
message:
'Failed to get split state by order: ${response?.statusCode ?? 'no response'}',
);
} catch (e, st) {
_logger.error(
this,
'Error getting split state by order: $e',
error: e,
stackTrace: st,
);
rethrow;
}
},
logAnalytics: true,
analyticsEventName: 'split_state_fetched',
);
}