getTokenInfo method

Future<TokenInfo> getTokenInfo(
  1. String token,
  2. APIEnv env
)

Implementation

Future<TokenInfo> getTokenInfo(String token, APIEnv env) async {
  final webBaseURL = await getWebBaseURL(env);
  if (token.startsWith(webBaseURL + "/cashtrays/")) {
    return TokenInfo(type: TokenType.CASHTRAY, token: "");
  } else if (token.startsWith(webBaseURL + "/bills/")) {
    final String uuid = token.substring((webBaseURL + "/bills/").length);
    final bill = await api.getBill(id: uuid);
    return TokenInfo(type: TokenType.BILL, token: bill);
  } else if (token.startsWith(webBaseURL + "/checks/")) {
    final String uuid = token.substring((webBaseURL + "/checks/").length);
    final check = await api.getCheck(id: uuid);
    return TokenInfo(type: TokenType.CHECK, token: check);
  } else if (RegExp(r'^([0-9A-Z]{25})$').hasMatch(token)) {
    final cpmToken = await api.getCpmToken(cpmToken: token);
    return TokenInfo(type: TokenType.CPM, token: cpmToken);
  } else {
    String key = parseAsPokeregiToken(token);
    if (key.length > 0) {
      return TokenInfo(type: TokenType.PAYREGI, token: "");
    }else{
      return TokenInfo(type: TokenType.UNKNOWN, token: "");
    }
  }
}