1111 *
1212 */
1313public class Config {
14- private final static String version = "1 .0.2 " ;
14+ private final static String version = "2 .0.0 " ;
1515 private JSONObject conf = new JSONObject ();
1616 private JSONObject endpoints = new JSONObject ();
1717 private JSONObject urls = new JSONObject ();
18+ private JSONObject options = new JSONObject ();
1819
1920 public Config (JSONObject options , JSONObject config ) throws Exception {
20-
21- if (config .has ("ENDPOINTS" )) {
22- this .endpoints = (JSONObject ) config .get ("ENDPOINTS" );
23- if (setPix (options )) {
24- if (this .endpoints .has ("PIX" )) {
25- this .endpoints = (JSONObject ) this .endpoints .get ("PIX" );
26- }
27- } else {
28- if (this .endpoints .has ("DEFAULT" )) {
29- this .endpoints = (JSONObject ) this .endpoints .get ("DEFAULT" );
30- }
31- }
32- } else
33- throw new Exception ("Problems to get ENDPOINTS in file config.json" );
34-
35- if (config .has ("URL" )) {
36- this .urls = (JSONObject ) config .get ("URL" );
37- if (setPix (options )) {
38- if (this .urls .has ("PIX" )) {
39- this .urls = (JSONObject ) this .urls .get ("PIX" );
40- }
41- } else if (this .urls .has ("DEFAULT" )) {
42- this .urls = (JSONObject ) this .urls .get ("DEFAULT" );
43- }
44- } else
45- throw new Exception ("Problems to get URLs in file config.json" );
46-
47- this .setConf (options );
21+ this .endpoints = config ;
22+ this .options = options ;
4823 }
4924
5025 public JSONObject getEndpoints () {
51- return endpoints ;
26+ return ( JSONObject ) endpoints . get ( "APIs" ) ;
5227 }
5328
5429 public JSONObject getUrls () {
@@ -71,15 +46,13 @@ public void setConf(JSONObject options) {
7146 this .conf .put ("clientId" , options .getString ("client_id" ));
7247 if (options .has ("client_secret" ))
7348 this .conf .put ("clientSecret" , options .getString ("client_secret" ));
74- if (options .has ("pix_cert " ))
75- this .conf .put ("certificadoPix " , options .getString ("pix_cert " ));
49+ if (options .has ("certificate " ))
50+ this .conf .put ("certificate " , options .getString ("certificate " ));
7651 if (options .has ("partner_token" ))
7752 this .conf .put ("partnerToken" , options .getString ("partner_token" ));
7853 if (options .has ("url" )) {
7954 this .conf .put ("baseUri" , options .getString ("url" ));
80- }
81-
82- else {
55+ } else {
8356 String baseUri = this .urls .getString ("production" );
8457 if (this .conf .getBoolean ("sandbox" ) == true )
8558 baseUri = this .urls .getString ("sandbox" );
@@ -90,6 +63,10 @@ public void setConf(JSONObject options) {
9063 if (options .has ("x-skip-mtls-checking" )) {
9164 this .conf .put ("headers" , options .getString ("x-skip-mtls-checking" ));
9265 }
66+
67+ if (options .has ("x-idempotency-key" )) {
68+ this .conf .put ("headers" , options .getString ("x-idempotency-key" ));
69+ }
9370 }
9471
9572 public JSONObject getOptions () {
@@ -100,8 +77,9 @@ public static String getVersion() {
10077 return Config .version ;
10178 }
10279
103- public boolean setPix (JSONObject options ) {
104- return options .has ("pix_cert" );
80+ public void setURLs (JSONObject parURLs ) {
81+ this .urls = parURLs ;
82+ this .setConf (this .options );
10583 }
10684
10785}
0 commit comments