PGWNavigationDelegate constructor

PGWNavigationDelegate({
  1. FutureOr<NavigationDecision> onNavigationRequest(
    1. NavigationRequest request
    )?,
  2. void onPageStarted(
    1. String url
    )?,
  3. void onPageFinished(
    1. String url
    )?,
  4. void onProgress(
    1. int progress
    )?,
  5. void onWebResourceError(
    1. WebResourceError error
    )?,
  6. void onUrlChange(
    1. UrlChange change
    )?,
  7. void onHttpAuthRequest(
    1. HttpAuthRequest request
    )?,
  8. void onInquiry(
    1. String paymentToken
    )?,
})

Implementation

PGWNavigationDelegate({
  super.onNavigationRequest,
  super.onPageStarted,
  super.onPageFinished,
  super.onProgress,
  super.onWebResourceError,
  void Function(UrlChange change)? onUrlChange,
  super.onHttpAuthRequest,
  void Function(String paymentToken)? onInquiry
}) {

  platform.setOnUrlChange((change) {

    if(onUrlChange != null) onUrlChange(change);

    String? url = change.url ?? '';

    final bool doWebUrlCapture = RegExp(_defaultResultWebUrlCaptureRegex, caseSensitive: false).hasMatch(url);
    final bool doAppSchemeCapture = RegExp(_defaultResultAppSchemeCaptureRegex, caseSensitive: false).hasMatch(url);

    if(doWebUrlCapture || doAppSchemeCapture) {

      if(onInquiry != null) {

        String paymentToken = '';

        if(doWebUrlCapture) {

          try {

            Iterable<RegExpMatch> webUrlFindMatcher = RegExp(_defaultResultWebUrlCaptureRegex, caseSensitive: false).allMatches(url);

            for (var match in webUrlFindMatcher) {

              paymentToken = match[3] != null ? match[3]! : '';
            }
          } catch(e) {

            paymentToken = '';
          }
        }

        onInquiry(paymentToken);
      }
    }
  });
}