1public with sharing class PayClaimCoveragePaymentDetailCallable implements System.Callable {
2
3 public Object call(String action, Map<String, Object> args) {
4 // Retrieve the input and output maps from the arguments
5 Map<String, Object> inputMap = (Map<String, Object>) args.get('input');
6 Map<String, Object> outputMap = (Map<String, Object>) args.get('output');
7
8 // Check the action type
9 if (action == 'payClaimCoveragePaymentDetail') {
10 // Retrieve the required parameters from the input map
11 String claimId = (String) inputMap.get('claimId');
12 String claimCoverageId = (String) inputMap.get('claimCoverageId');
13 String claimCoveragePaymentDetailId = (String) inputMap.get('claimCoveragePaymentDetailId');
14
15 System.debug('Start of connect API call to pay claim coverage payment detail');
16 System.debug('Claim ID: ' + claimId);
17 System.debug('Claim Coverage ID: ' + claimCoverageId);
18 System.debug('Claim Coverage Payment Detail ID: ' + claimCoveragePaymentDetailId);
19
20 // Initialize the input representation and optional pre-payment checks
21 ConnectApi.PayClaimCoveragePaymentDetailInputRepresentation payInput =
22 new ConnectApi.PayClaimCoveragePaymentDetailInputRepresentation();
23 payInput.options = new ConnectApi.PayClaimCoveragePaymentDetailOptionsInputRep();
24 payInput.options.shouldCheckFinancialAuthority = true;
25 payInput.options.shouldVerifyReserveLimit = true;
26
27 // Initialize the output representation
28 ConnectApi.PayClaimCoveragePaymentDetailRep paymentDetailData;
29
30 // Call the Connect API to pay claim coverage payment detail
31 try {
32 // Call the Connect API resource directly using the correct method signature
33 // The endpoint is: /connect/insurance/claims/${claimId}/coverages/${coverageId}/payment-details/${paymentDetailId}/pay
34 paymentDetailData = ConnectApi.InsuranceClaimFamily.payClaimCoveragePaymentDetail(
35 claimId,
36 claimCoverageId,
37 claimCoveragePaymentDetailId,
38 payInput
39 );
40
41 System.debug('Claim coverage payment detail paid successfully: ' + paymentDetailData);
42
43 // Put the payment detail data in the output map
44 outputMap.put('paymentDetailData', paymentDetailData);
45 outputMap.put('isPaid', paymentDetailData.isSuccess);
46
47 // Check if there are any errors
48 if (paymentDetailData.errors != null && !paymentDetailData.errors.isEmpty()) {
49 outputMap.put('errors', paymentDetailData.errors);
50 System.debug('Errors found: ' + paymentDetailData.errors);
51 }
52 }
53 catch (Exception e) {
54 System.debug('Error while paying claim coverage payment detail: ' + e.getMessage());
55 outputMap.put('error', e.getMessage());
56 outputMap.put('isPaid', false);
57 }
58
59 // Return the payment detail data
60 return paymentDetailData;
61 }
62
63 // If the action is not recognized, return null
64 return null;
65 }
66}
67// Usage Example:
68PayClaimCoveragePaymentDetailCallable callable = new PayClaimCoveragePaymentDetailCallable();
69// Prepare the input arguments
70Map<String, Object> input = new Map<String, Object>();
71// Set the required parameters
72input.put('claimId', '0Zkxx000000002ZCAQ'); // Claim ID
73input.put('claimCoverageId', '0kPxx000000000cEAA'); // Claim Coverage ID
74input.put('claimCoveragePaymentDetailId', '0l2xx000000002cAAA'); // Claim Coverage Payment Detail ID
75// Prepare the output map
76Map<String, Object> output = new Map<String, Object>();
77// Prepare the args map
78Map<String, Object> args = new Map<String, Object>();
79args.put('input', input);
80args.put('output', output);
81// Call the 'payClaimCoveragePaymentDetail' action
82Object result = callable.call('payClaimCoveragePaymentDetail', args);
83// Check the result
84if (result != null) {
85 System.debug('Claim coverage payment detail processed successfully: ' + result);
86
87 // Access the processed payment detail data
88 ConnectApi.PayClaimCoveragePaymentDetailRep paymentDetailData =
89 (ConnectApi.PayClaimCoveragePaymentDetailRep) result;
90
91 // Process the result as needed
92 System.debug('Payment Detail Data: ' + paymentDetailData);
93
94 // Check if the payment was successful
95 if (paymentDetailData.isSuccess) {
96 System.debug('Payment was successful');
97 } else {
98 System.debug('Payment failed');
99 if (paymentDetailData.errors != null) {
100 System.debug('Error details: ' + paymentDetailData.errors);
101 }
102 }
103} else {
104 System.debug('Error occurred: ' + output.get('error'));
105}