failFromUrl function

Fail? failFromUrl(
  1. String urlString
)

Parses the URL for a failed payment and extracts the relevant information. Returns a Fail object if the URL contains error data; otherwise, returns null.

Implementation

Fail? failFromUrl(String urlString) {
  if (urlString.startsWith(Constants.fail)) {
    final Uri url = Uri.parse(urlString);
    final Map<String, String> queryParams = url.queryParameters;
    final String errorCode = queryParams['code'] ?? '';
    final String errorMessage = queryParams['message'] ?? '';
    final String orderId = queryParams['orderId'] ?? '';

    return Fail(errorCode, errorMessage, orderId);
  }
  return null;
}