@@ -27,7 +27,7 @@ class CakePayClient {
2727 HTTP ? httpClient,
2828 }) : _httpClient = httpClient ?? const HTTP ();
2929
30- Map < String , String > _headers () => {
30+ late final _authHeaders = {
3131 'Authorization' : 'Bearer $apiToken ' ,
3232 'Content-Type' : 'application/json' ,
3333 };
@@ -175,44 +175,8 @@ class CakePayClient {
175175 );
176176 }
177177
178- Future <ApiResponse <List <CakePayCountry >>> getCountries ({
179- int ? page,
180- int ? pageSize,
181- }) async {
182- final query = < String , String > {};
183- if (page != null ) query['page' ] = page.toString ();
184- if (pageSize != null ) query['page_size' ] = pageSize.toString ();
185-
186- return _requestRaw (
187- 'GET' ,
188- '/marketplace/countries/' ,
189- query: query,
190- parse: (body) {
191- final decoded = jsonDecode (body);
192- if (decoded is List ) {
193- return decoded
194- .whereType <Map <String , dynamic >>()
195- .map (CakePayCountry .fromJson)
196- .toList ();
197- }
198- if (decoded is Map <String , dynamic >) {
199- final results = decoded['results' ];
200- if (results is List ) {
201- return results
202- .whereType <Map <String , dynamic >>()
203- .map (CakePayCountry .fromJson)
204- .toList ();
205- }
206- }
207- return [];
208- },
209- );
210- }
211-
212178 /// Fetches all countries by following pagination til last page.
213- Future <ApiResponse <List <CakePayCountry >>> getAllCountries ({
214- int pageSize = 250 ,
215- }) async {
179+ Future <ApiResponse <List <CakePayCountry >>> getAllCountries () async {
216180 try {
217181 final allCountries = < CakePayCountry > [];
218182 int page = 1 ;
@@ -221,7 +185,8 @@ class CakePayClient {
221185 final response = await _send (
222186 'GET' ,
223187 '/marketplace/countries/' ,
224- query: {'page' : page.toString (), 'page_size' : pageSize.toString ()},
188+ query: {'page' : page.toString ()},
189+ overrideHeaders: {}, // Auth here leads to 403. Why? Who knows?
225190 );
226191
227192 if (response.code < 200 || response.code >= 300 ) {
@@ -236,15 +201,16 @@ class CakePayClient {
236201
237202 final decoded = jsonDecode (response.body);
238203
204+ // This never gets hit according to docs
239205 // Handle non-paginated response (plain list).
240- if (decoded is List ) {
241- return ApiResponse (
242- value: decoded
243- .whereType <Map <String , dynamic >>()
244- .map (CakePayCountry .fromJson)
245- .toList (),
246- );
247- }
206+ // if (decoded is List) {
207+ // return ApiResponse(
208+ // value: decoded
209+ // .whereType<Map<String, dynamic>>()
210+ // .map(CakePayCountry.fromJson)
211+ // .toList(),
212+ // );
213+ // }
248214
249215 if (decoded is Map <String , dynamic >) {
250216 final results = decoded['results' ];
@@ -466,15 +432,20 @@ class CakePayClient {
466432 String path, {
467433 Map <String , dynamic >? body,
468434 Map <String , String >? query,
435+ Map <String , String >? overrideHeaders,
469436 }) async {
470437 var uri = Uri .parse ('$baseUrl $path ' );
471438 if (query != null && query.isNotEmpty) {
472439 uri = uri.replace (queryParameters: query);
473440 }
474- final headers = _headers () ;
441+ final headers = overrideHeaders ?? _authHeaders ;
475442 final proxy = _proxyInfo;
476443
477- Logging .instance.t ("$_kTag $method $uri " );
444+ try {
445+ throw Exception (path);
446+ } catch (e, s) {
447+ Logging .instance.f ("$_kTag $method $uri " , error: e, stackTrace: s);
448+ }
478449
479450 switch (method) {
480451 case 'GET' :
0 commit comments