37 lines
1.7 KiB
OpenEdge ABL
37 lines
1.7 KiB
OpenEdge ABL
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());
|
|
}
|
|
} |