tokenizeGooglePay method

Tokenize google pay payload

Can throw InvalidDataError if the data provided is not correct, or UnauthorizedError in case there is an issue with the api authentication or a general Exception. Returns the tokenization response including the card token used to process a payment from the server side.

Implementation

Future<WalletsTokenizationResponse> tokenizeGooglePay(
    GooglePayTokenizationRequest request) async {
  GooglePayTokenizationRequest data = request;
  //encode Map to JSON
  var body = json.encode(data);
  var url = Uri.parse(getEnvironment(publicKey) + '/tokens');

  var response = await http.post(url,
      headers: {
        "Content-Type": "application/json",
        "Authorization": publicKey
      },
      body: body);

  if (response.statusCode == 401) throw new UnauthorizedError();

  if (response.statusCode == 422)
    throw new InvalidDataError.fromJson(jsonDecode(response.body));

  if ((response.statusCode ~/ 100) == 2) {
    return WalletsTokenizationResponse.fromJson(jsonDecode(response.body));
  } else {
    throw Exception(response);
  }
}