1/**
2 * Callable wrapper to exercise the UFA (User Financial Authority) Connect API:
3 * POST /connect/insurance/claims/payment-details/${paymentDetailId}/check-financial-authority
4 *
5 * Backed by CheckFinancialAuthorityResourceImpl -> CheckFinancialAuthorityService.
6 *
7 * Mirrors the EditClaimCoveragePaymentDetailCallable pattern. All debug output is
8 * prefixed with [UFA] so it is easy to grep in the debug logs.
9 */
10public with sharing class CheckFinancialAuthorityCallable implements System.Callable {
11
12 private static final String LOG_PREFIX = '[UFA] ';
13
14 public Object call(String action, Map<String, Object> args) {
15 // Retrieve the input and output maps from the arguments
16 Map<String, Object> inputMap = (Map<String, Object>) args.get('input');
17 Map<String, Object> outputMap = (Map<String, Object>) args.get('output');
18
19 if (action == 'checkFinancialAuthority') {
20 // paymentDetailId is the ClaimCoveragePaymentDetail record Id to evaluate.
21 // It maps to the ${paymentDetailId} URL path parameter.
22 String paymentDetailId = (String) inputMap.get('paymentDetailId');
23
24 // The CheckFinancialAuthorityInputRep body is currently EMPTY (no fields).
25 // We still build/accept one so the call site matches the generated signature.
26 ConnectApi.CheckFinancialAuthorityInputRep checkInputRep =
27 (ConnectApi.CheckFinancialAuthorityInputRep) inputMap.get('CheckFinancialAuthorityInput');
28 if (checkInputRep == null) {
29 checkInputRep = new ConnectApi.CheckFinancialAuthorityInputRep();
30 }
31
32 System.debug(LOG_PREFIX + '==== Start CheckFinancialAuthority Connect API call ====');
33 System.debug(LOG_PREFIX + 'Running as user: ' + UserInfo.getUserId() + ' (' + UserInfo.getName() + ')');
34 System.debug(LOG_PREFIX + 'paymentDetailId (ClaimCoveragePaymentDetail Id): ' + paymentDetailId);
35
36 ConnectApi.CheckFinancialAuthorityRep checkResponse;
37
38 try {
39 // Generated Apex signature: (paymentDetailId, input) — path param first.
40 checkResponse = ConnectApi.InsuranceClaimFamily.CheckFinancialAuthority(
41 paymentDetailId,
42 checkInputRep
43 );
44
45 System.debug(LOG_PREFIX + 'CheckFinancialAuthority completed. Raw response: ' + checkResponse);
46
47 // Surface every field the output representation returns.
48 outputMap.put('checkResponse', checkResponse);
49 if (checkResponse != null) {
50 outputMap.put('isSuccess', checkResponse.isSuccess);
51 outputMap.put('requestedBy', checkResponse.requestedBy);
52 outputMap.put('hasFinancialAuthority', checkResponse.hasFinancialAuthority);
53 outputMap.put('isFinancialAuthorityConfigured', checkResponse.isFinancialAuthorityConfigured);
54 outputMap.put('isPaymentAllowed', checkResponse.isPaymentAllowed);
55 outputMap.put('maximumApprovalAmount', checkResponse.maximumApprovalAmount);
56
57 System.debug(LOG_PREFIX + 'isSuccess = ' + checkResponse.isSuccess);
58 System.debug(LOG_PREFIX + 'requestedBy = ' + checkResponse.requestedBy);
59 System.debug(LOG_PREFIX + 'hasFinancialAuthority = ' + checkResponse.hasFinancialAuthority);
60 System.debug(LOG_PREFIX + 'isFinancialAuthorityConfigured= ' + checkResponse.isFinancialAuthorityConfigured);
61 System.debug(LOG_PREFIX + 'isPaymentAllowed = ' + checkResponse.isPaymentAllowed);
62 System.debug(LOG_PREFIX + 'maximumApprovalAmount = ' + checkResponse.maximumApprovalAmount);
63
64 if (checkResponse.errors != null && !checkResponse.errors.isEmpty()) {
65 outputMap.put('errors', checkResponse.errors);
66 System.debug(LOG_PREFIX + 'Errors returned by service:');
67 for (ConnectApi.ErrorDetail err : checkResponse.errors) {
68 System.debug(LOG_PREFIX + ' code=' + err.code + ', message=' + err.message);
69 }
70 } else {
71 System.debug(LOG_PREFIX + 'No errors returned.');
72 }
73 }
74 } catch (Exception e) {
75 System.debug(LOG_PREFIX + 'EXCEPTION while calling CheckFinancialAuthority: ' + e.getMessage());
76 System.debug(LOG_PREFIX + 'Stack trace: ' + e.getStackTraceString());
77 outputMap.put('error', e.getMessage());
78 outputMap.put('isSuccess', false);
79 }
80
81 System.debug(LOG_PREFIX + '==== End CheckFinancialAuthority Connect API call ====');
82 return checkResponse;
83 }
84
85 System.debug(LOG_PREFIX + 'Unrecognized action: ' + action);
86 return null;
87 }
88}