-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZoozAPIRequest.cls
34 lines (32 loc) · 1.5 KB
/
ZoozAPIRequest.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public class ZoozAPIRequest {
private final static ZoozAPIMerchantAppProfile settings = ZoozAPIMerchantAppProfile.getInstance();
private HttpRequest req;
public ZoozAPIRequest() {
req = new HttpRequest();
}
public ZoozAPIResponse send(IZoozCommand zoozCommand){
Http http = new Http();
configureMerchantAppProfile();
String body = zoozCommand.buildCommandBody();
req.setBody(body);
req.setMethod('POST');
req.setHeader('Content-Length', String.valueOf(body.length()));
HttpResponse res = http.send(req);
System.debug('ZoozAPIRequest.send - request: ' + body);
System.debug('ZoozAPIRequest.send - EndPoint: ' + req.getEndpoint());
System.debug('ZoozAPIRequest.send - statusCode: ' + res.getStatus());
System.debug('ZoozAPIRequest.send - response: ' + res.getBody());
//System.debug('ZoozAPIRequest.send - content type: ' + res.getHeader('Content-Type'));
return new ZoozAPIResponse(res.getBody());
}
private void configureMerchantAppProfile(){
req.setEndpoint(settings.getValue('Environment').toLowerCase() == 'production' ? settings.getValue('productionUrl') : settings.getValue('sandboxUrl'));
req.setHeader('Content-Type', 'Application/Json');
req.setHeader('ZoozResponseType', 'Json');
req.setHeader('programId', settings.getValue('programId'));
req.setHeader('programKey', settings.getValue('programKey'));
req.setHeader('ZoozDeveloperId', settings.getValue('ZoozDeveloperId'));
req.setHeader('ZoozServerAPIKey', settings.getValue('ZoozServerAPIKey'));
req.setTimeout(30000);
}
}