checkoutUrlFor static method

Uri? checkoutUrlFor(
  1. Uri imageUrl
)

The checkout JSON for an image URL of the form …/pay/{id}/qr.svg (or qr.png), else null.

Implementation

static Uri? checkoutUrlFor(Uri imageUrl) {
  final parts = imageUrl.pathSegments;
  if (parts.length < 3) return null;
  final last = parts.last;
  if (last != 'qr.svg' && last != 'qr.png') return null;
  if (parts[parts.length - 3] != 'pay' || parts[parts.length - 2].isEmpty) return null;
  // Rebuilt without query or fragment.
  return Uri(
    scheme: imageUrl.scheme,
    userInfo: imageUrl.userInfo,
    host: imageUrl.host,
    port: imageUrl.hasPort ? imageUrl.port : null,
    pathSegments: parts.sublist(0, parts.length - 1),
  );
}