listMerchants method
Returns Merchant information for a given access token.
If you don't know a Merchant ID, you can use this endpoint to retrieve the merchant ID for an access token. You can specify your personal access token to get your own merchant information or specify an OAuth token to get the information for the merchant that granted you access.
If you know the merchant ID, you can also use the RetrieveMerchant endpoint to get the merchant information.
Implementation
Future<MerchantResponse> listMerchants({
String? cursor,
String? authToken,
}) async {
authToken ??= authenticationService.getCachedToken()?.accessToken;
Map<String, String> headers = {
"Authorization": "Bearer ${authToken ?? ""}",
'Content-Type': 'application/json; charset=UTF-8',
'Accept': 'application/json',
};
Map<String, String>? params = null;
if (cursor != null) {
params = {
"cursor": cursor
};
}
Uri endpoint = Uri.https(
baseUrl, "/v2/merchants", params);
//print (endpoint.toString());
var response = await
http.get(endpoint, headers: headers);
if (response.statusCode == 200) {
print (jsonDecode(response.body));
return MerchantResponse.fromJson(jsonDecode(response.body));
}
else {
print (response.body);
throw MerchantException(statusCode: response.statusCode, message: MerchantResponse.fromJson(jsonDecode(response.body)).errors?[0].detail?.toString());
}
}