successFromUrl function

Success? successFromUrl(
  1. String urlString
)

Parses the URL for a successful payment and extracts the relevant information. Returns a Success object if the URL contains success data; otherwise, returns null.

Implementation

Success? successFromUrl(String urlString) {
  if (urlString.startsWith(Constants.success)) {
    final Uri url = Uri.parse(urlString);
    final Map<String, String> queryParams = url.queryParameters;
    final String paymentKey = queryParams['paymentKey'] ?? '';
    final String orderId = queryParams['orderId'] ?? '';
    final num amount = num.tryParse(queryParams['amount'] ?? '') ?? 0;
    final Map<String, String> additionalParams = Map.fromEntries(queryParams.entries.where((element) {
      return (element.key != 'paymentKey') && (element.key != 'orderId') && (element.key != 'amount');
    }));

    return Success(paymentKey, orderId, amount, additionalParams);
  }
  return null;
}