first commit Riabu
This commit is contained in:
37
force-app/main/default/classes/CustomerCreationService.cls
Normal file
37
force-app/main/default/classes/CustomerCreationService.cls
Normal file
@@ -0,0 +1,37 @@
|
||||
public with sharing class CustomerCreationService {
|
||||
public static void createCustomer(Id accountId) {
|
||||
System.Debug('Triggering Account' +accountId
|
||||
);
|
||||
Account acc = [
|
||||
SELECT Id, Name, Registration_Number__c, CreatedDate, Days_to_Pay__c, Procurement_Portal__c
|
||||
FROM Account WHERE Id = :accountId
|
||||
|
||||
];
|
||||
|
||||
RIABU_Integration__mdt cfg = RiabuConfigUtil.getConfig();
|
||||
String token = RiabuAuthService.getValidAccessToken();
|
||||
String baseUrl = cfg.Endpoint__c.replace('/oauth/token', ''); // adjust base
|
||||
|
||||
HttpRequest req = new HttpRequest();
|
||||
req.setEndpoint(cfg.Endpoint__c + '/api/v1/wizard/customer');
|
||||
req.setMethod('POST');
|
||||
req.setHeader('Content-Type', 'application/x-www-form-urlencoded');
|
||||
req.setHeader('Authorization', 'Bearer ' + token);
|
||||
|
||||
String body =
|
||||
'company_name=' + EncodingUtil.urlEncode(acc.Name,'UTF-8') +
|
||||
'&company_uen=' + EncodingUtil.urlEncode(acc.Registration_Number__c,'UTF-8') +
|
||||
'&customer_since=' + EncodingUtil.urlEncode(acc.CreatedDate.format('yyyy-MM-dd'),'UTF-8') +
|
||||
'&agreed_credit_terms_day=' + EncodingUtil.urlEncode(String.valueOf(acc.Days_to_Pay__c),'UTF-8') +
|
||||
'&procurement_portal=' + EncodingUtil.urlEncode(acc.Procurement_Portal__c,'UTF-8');
|
||||
|
||||
req.setBody(body);
|
||||
System.Debug('Request Body' + body);
|
||||
System.Debug('Endpoint' + req.getEndpoint());
|
||||
|
||||
Http http = new Http();
|
||||
HttpResponse res = http.send(req);
|
||||
System.debug('Customer Response: ' + res.getBody());
|
||||
System.debug('Response Code: ' + res.getStatusCode());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user