From 2a8842afc01a7f1d096bc7d942a4f155565da0f7 Mon Sep 17 00:00:00 2001 From: michelleb-stripe <77996191+michelleb-stripe@users.noreply.github.com> Date: Mon, 28 Feb 2022 11:43:08 -0800 Subject: [PATCH] Check and fix broken documentation links. (#4626) --- .../main/java/com/stripe/android/Stripe.kt | 2 +- .../com/stripe/android/model/PaymentMethod.kt | 2 +- scripts/check_links_valid.py | 67 +++++++++++++++++++ 3 files changed, 69 insertions(+), 2 deletions(-) create mode 100755 scripts/check_links_valid.py diff --git a/payments-core/src/main/java/com/stripe/android/Stripe.kt b/payments-core/src/main/java/com/stripe/android/Stripe.kt index e90d58d2980..b8f2069d0e9 100644 --- a/payments-core/src/main/java/com/stripe/android/Stripe.kt +++ b/payments-core/src/main/java/com/stripe/android/Stripe.kt @@ -325,7 +325,7 @@ class Stripe internal constructor( * Handle the [next_action](https://stripe.com/docs/api/payment_intents/object#payment_intent_object-next_action) * for a previously confirmed [PaymentIntent]. * - * Used for [manual confirmation](https://stripe.com/docs/payments/payment-intents/android-manual) flow. + * Used for [manual confirmation](https://stripe.com/docs/payments/accept-a-payment-synchronously) flow. * * @param fragment the `Fragment` that is launching the payment authentication flow * @param clientSecret the [client_secret](https://stripe.com/docs/api/payment_intents/object#payment_intent_object-client_secret) diff --git a/payments-core/src/main/java/com/stripe/android/model/PaymentMethod.kt b/payments-core/src/main/java/com/stripe/android/model/PaymentMethod.kt index 4e20d5431a0..bc4e4e897d2 100644 --- a/payments-core/src/main/java/com/stripe/android/model/PaymentMethod.kt +++ b/payments-core/src/main/java/com/stripe/android/model/PaymentMethod.kt @@ -833,7 +833,7 @@ constructor( /** * The customer’s bank. * - * [netbanking.bank](https://stripe.com/docs/payments/netbanking/banks) + * [netbanking.bank](https://stripe.com/docs/js#stripe_create_payment_method-paymentMethodData-netbanking[bank]) */ @JvmField val bank: String? ) : TypeData() { diff --git a/scripts/check_links_valid.py b/scripts/check_links_valid.py new file mode 100755 index 00000000000..083351fc27f --- /dev/null +++ b/scripts/check_links_valid.py @@ -0,0 +1,67 @@ +#!/bin/python +import re +import glob +import os +import sys +import urllib.request +from urllib.error import HTTPError +from urllib.error import URLError + +root_dir="docs" +readme="README.md" + +def request(url): + try: + print("requesting... ---" + url + "--- ") + response = urllib.request.urlopen(url) + if(response): + return response.getcode() == 200 + else: + print("No response\n") + return False + except HTTPError as e: + print("HTTPError \n") + return False + except URLError as e: + print("URLError\n") + return False + print("\n") + return False + +def findStripeLinksInFile(filename): + regexStripe = r'(https://stripe.com[^\\)|"|\\ |<]*)' + regexGithub = r'(https://github.com[^\\)|"|\\ |<]*)' + allUrls = [] + isFile = os.path.isfile(filename) + if(isFile): + with open(filename) as file: + for line in file: + allUrls.extend(re.findall(regexStripe, line)) + allUrls.extend(re.findall(regexGithub, line)) + return allUrls + + +def findStripeLinks(root_dir): + urlSet=set() + for filename in glob.iglob(root_dir + '**/**', recursive=True): + urls = findStripeLinksInFile(filename) + if(urls): + for url in urls: + urlSet.add(url) + + return urlSet + +##------ +# Find the stripe links in the documentation directory +urlSet = findStripeLinks(root_dir) +# Find the stripe links in the Readme +for urlLinkFromReadme in findStripeLinksInFile("README.md"): + urlSet.add(urlLinkFromReadme) + +# For each link verify it does not 404 when requested. +urlDNE = [] +for url in urlSet: + if(not request(url)): + urlDNE.append(url) +print(urlDNE) +sys.exit(1)