Created
April 6, 2020 14:48
-
-
Save mhamzas/b4cbb0fa907b8ff2f5b08827ea97ffe5 to your computer and use it in GitHub Desktop.
Public Rest service to insert Financial Account and Financial Account Transactions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @RestResource(urlMapping='/DLResult') | |
| global without sharing class DL_Info_Receiver { | |
| @HttpGet | |
| global static void doGet() { | |
| RestContext.response.addHeader('Content-Type', 'text/plain'); | |
| String code = RestContext.request.params.get('rc'); | |
| String CustomerId = RestContext.request.params.get('customerid'); | |
| RestContext.response.responseBody = Blob.valueOf('Hello '+CustomerId); | |
| String Message; | |
| // Debugging Params | |
| system.debug('Params::'+RestContext.request.params); | |
| // CustomerID from DL = SF Contact ID - Passed when requesting iframe code | |
| if(CustomerId != '{customerid}'){ | |
| /* | |
| Id contactId = ApexPages.currentPage().getParameters().get('customerid'); | |
| // Checking if ContactID from param is not null | |
| if(contactId != NULL){ | |
| // Serializing Parameters MAP to JSON STRING | |
| String DL_Response = JSON.serialize(ApexPages.currentPage().getParameters()); | |
| // Updating Parameters data in Contact record in Textarea field | |
| Contact con = new Contact(Id= contactId, DLData__c = DL_Response, DL_Request_Code__c = ApexPages.currentPage().getParameters().get('rc')); | |
| try{ | |
| update con; | |
| // Get Records from DL SOAP Call | |
| DL_MultipleReports(ApexPages.currentPage().getParameters().get('rc')); | |
| } catch(DmlException e) { | |
| System.debug('The following exception has occurred: ' + e.getMessage()); | |
| } | |
| //update new Contact(Id= contactId, DLData__c = DL_Response); | |
| }*/ | |
| //Upsert REQUEST CODE here | |
| Id contactId = CustomerId; | |
| // Checking if ContactID from param is not null | |
| if(contactId != NULL){ | |
| Account acc = [select id from account where PersonContactId =: contactId]; | |
| if(acc<> null) | |
| { | |
| // Serializing Parameters MAP to JSON STRING | |
| String DL_Response = JSON.serialize(RestContext.request.params); | |
| // Updating Parameters data in Contact record in Textarea field | |
| //Contact con = new Contact(Id= contactId, DLData__c = DL_Response, DL_Request_Code__c = ApexPages.currentPage().getParameters().get('rc')); | |
| Request_Code__c rc = new Request_Code__c(Account__c = acc.id, JSON_Data__c = DL_Response, Request_Code__c = code); | |
| try{ | |
| upsert rc Request_Code__c; | |
| //DL_MultipleReports(code, rc.id); | |
| } catch(DmlException e) { | |
| System.debug('The following exception has occurred: ' + e.getMessage()); | |
| } finally { | |
| system.debug('SYA :: Finally scope'); | |
| // Get Records from DL SOAP Call | |
| DL_MultipleReports(code, rc.id); | |
| } | |
| } | |
| } | |
| } else { | |
| Message = 'Invalid Customer ID'; | |
| RestContext.response.responseBody = Blob.valueOf(Message +' '+CustomerId); | |
| } | |
| } | |
| // Getting Multiple Reports from Decision Logic | |
| @future(callout = true) | |
| global static void DL_MultipleReports(String requestCode, id rcId) | |
| { | |
| system.debug('Report Started'); | |
| //Getting Account Id from Request Code | |
| //Id AccountId = [Select Id from Account where DL_Request_Code__pc =: requestCode].Id;//TO CHANGE | |
| //system.debug('AccountId::'+ AccountId); | |
| String serviceKey = 'KR7K6R2TG4SY'; // CUstom MetaData - Custom Setting - ENCRYPTED | |
| //requestCode = 'DQ8TLR'; | |
| DL_SOAPConnector.DecisionLogic_x0020_API_x0020_ver2Soap dlSoap = new DL_SOAPConnector.DecisionLogic_x0020_API_x0020_ver2Soap(); | |
| DL_SOAPConnector.ArrayOfReportDetail5 reportDetails = dlSoap.GetMultipleReportDetailsFromRequestCode7(serviceKey, requestCode); | |
| system.debug('SYA :: '+reportDetails); | |
| DL_SOAPConnector.ReportDetail5[] repDetail5;// = new DL_SOAPConnector.ReportDetail5(); | |
| repDetail5 = reportDetails.ReportDetail5; | |
| system.debug('SYA :: '+ repDetail5.size()); | |
| List<Contact> conLst = new List<Contact>(); | |
| List<FinServ__FinancialAccount__c> faLst = new List<FinServ__FinancialAccount__c>(); | |
| for(integer i=0;i < repDetail5.size(); i++) | |
| { | |
| system.debug('SYA :: AccountName ::'+ repDetail5[i].AccountName); | |
| //Insert Financial Account | |
| //NA repDetail5[i].EmailAddress, | |
| //fa.FinServ__Nickname__c = repDetail5[i].InstitutionName, | |
| //repDetail5[i].RoutingNumberReturned, | |
| //repDetail5[i].AccountNumberFound, | |
| //repDetail5[i].AccountNumberConfidence, | |
| //repDetail5[i].NameFound, | |
| //repDetail5[i].NameConfidence, //// FinServ__PrimaryOwner__c = AccountId, | |
| /*FinServ__FinancialAccount__c fa = new FinServ__FinancialAccount__c( | |
| RecordTypeId = Schema.SObjectType.FinServ__FinancialAccount__c.getRecordTypeInfosByName().get('Bank Account').getRecordTypeId(), | |
| Name = repDetail5[i].AccountName, | |
| FinServ__PrimaryOwner__c = '0010v00000UQN5dAAH', | |
| FinServ__RoutingNumber__c = repDetail5[i].RoutingNumberEntered, | |
| FinServ__FinancialAccountType__c = repDetail5[i].AccountType, | |
| FinServ__FinancialAccountNumber__c = repDetail5[i].AccountNumberEntered, | |
| FinServ__Nickname__c = repDetail5[i].NameEntered, | |
| FinServ__LoanAmount__c = repDetail5[i].AmountInput, | |
| FinServ__Balance__c = repDetail5[i].AvailableBalance, | |
| FinServ__AverageBalance__c = repDetail5[i].AverageBalance, | |
| FinServ__BalanceLastStatement__c = repDetail5[i].AverageBalanceRecent, | |
| Request_Code__c = rcId);*/ | |
| FinServ__FinancialAccount__c fa = new FinServ__FinancialAccount__c( | |
| RecordTypeId = Schema.SObjectType.FinServ__FinancialAccount__c.getRecordTypeInfosByName().get('Bank Account').getRecordTypeId(), | |
| Name = 'Hamza Test'+rcId, | |
| FinServ__PrimaryOwner__c = '0010v00000UQN5dAAH'); | |
| //TODO:: Remove DML as in the loop | |
| //insert fa; | |
| faLst.add(fa); | |
| //Insert Financial Account Transactions | |
| //DL_SOAPConnector.ArrayOfTransactionSummary5 | |
| //TODO: UNCOMMENT | |
| /* | |
| List<FinServ__FinancialAccountTransaction__c> fatLst = new List<FinServ__FinancialAccountTransaction__c>(); | |
| DL_SOAPConnector.ArrayOfTransactionSummary5 ats = repDetail5[i].TransactionSummaries; | |
| for(DL_SOAPConnector.TransactionSummary5 ts : ats.TransactionSummary5) | |
| { | |
| // TypeCodes, | |
| // IsRefresh, | |
| // Category | |
| FinServ__FinancialAccountTransaction__c fat = new FinServ__FinancialAccountTransaction__c( | |
| FinServ__FinancialAccount__c = fa.id, | |
| FinServ__TransactionDate__c = ts.TransactionDate, | |
| FinServ__Amount__c = ts.Amount, | |
| FinServ__RunningBalance__c = ts.RunningBalance, | |
| FinServ__Description__c = ts.Description, | |
| FinServ__TransactionStatus__c = ts.Status | |
| ); | |
| fatLst.add(fat); | |
| } | |
| insert fatLst; | |
| */ | |
| /* | |
| string repDet = JSON.serialize(repDetail5[i]) +''; | |
| if(repDet.length() < 130000) | |
| { | |
| Contact con = new Contact(LastName = requestCode + '::'+i ,DLI_Data__c = repDet);//.EmailAddress | |
| conLst.add(con); | |
| }*/ | |
| } | |
| insertfa(faLst); | |
| //insert conLst; | |
| //system.debug('SYA :: '+ repDetail5[0]); | |
| /*List<String> ReportDetail = new List<String>(); | |
| ReportDetail = reportDetails.ReportDetail5_type_info; | |
| JSON.serialize(ReportDetail));*/ | |
| system.debug(reportDetails.ReportDetail5_type_info + ':::' + reportDetails.apex_schema_type_info + ':::' + reportDetails.field_order_type_info); | |
| //return ''; | |
| } | |
| static public void insertfa (List<FinServ__FinancialAccount__c> falst) | |
| { | |
| insert falst; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment