processSplitRefund method
Processes a split payment refund.
Calls POST /api/SplitPayment/refund to update the
CheckoutTransaction with refund details after the payment gateway
has processed the refund via PaymentManager.processRefund().
Returns the updated SplitPaymentStateResponse reflecting the new
refund state, or null when the split session cannot be found.
Implementation
Future<SplitPaymentStateResponse?> processSplitRefund({
required String splitPaymentId,
required String businessId,
required String orderId,
required double refundAmount,
required String parentEventId,
required String paymentType,
String? refundEventId,
String? operationId,
}) async {
return _monitoring.monitorAction<SplitPaymentStateResponse?>(
actionName: 'split_process_refund',
provider: 'split_payments',
action: (_) async {
final url = '$_paymentsUrl/SplitPayment/refund';
_logger.info(
this,
'processSplitRefund: posting — '
'splitPaymentId=$splitPaymentId, '
'refundAmount=$refundAmount, '
'parentEventId=$parentEventId, '
'paymentType=$paymentType, '
'operationId=$operationId',
);
try {
final response = await _httpClient.post(
url: url,
additionalHeaders: {'Content-Type': 'application/json'},
requestData: {
'businessId': businessId,
'orderId': orderId,
'refundAmount': refundAmount,
'parentEventId': parentEventId,
'paymentType': paymentType,
if (refundEventId != null) 'refundEventId': refundEventId,
},
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,
'processSplitRefund: succeeded — '
'state=${data['state']}, splitPaymentId=$splitPaymentId, '
'operationId=$operationId',
);
return SplitPaymentStateResponse.fromJson(data);
}
if (response != null && response.statusCode == 404) {
_logger.info(
this,
'processSplitRefund: no session found '
'for splitPaymentId=$splitPaymentId',
);
return null;
}
_logger.error(
this,
'processSplitRefund failed: '
'${response?.statusCode} ${response?.statusMessage}',
);
throw PlatformException(
code: 'PROCESS_SPLIT_REFUND_FAILED',
message:
'Failed to process split refund: '
'${response?.statusCode ?? 'no response'}',
);
} catch (e, st) {
_logger.error(
this,
'Error processing split refund: $e',
error: e,
stackTrace: st,
);
rethrow;
}
},
logAnalytics: true,
analyticsEventName: 'split_refund_processed',
);
}