Search code examples
applepayapplepayjsapplepay-web

Apple Pay Web - determine supported client version


What is a good way to determine what Apple Pay web SDK version does the web client support?

In checking the documentation only found supportsVersion(number): boolean


Solution

  • Found no other way than to iterate against all the versions until you find one that works.

    static getLatestSupportedVersion(): number {
      if (!this.doesBrowserSupport()) {
        return 0
      }
      // https://developer.apple.com/documentation/apple_pay_on_the_web/apple_pay_on_the_web_version_history
      const LATEST_VERSION = 16
      let applePayVersion = LATEST_VERSION
      while (!this.supportsVersion(applePayVersion) && applePayVersion > 1) {
        --applePayVersion
      }
      return applePayVersion
    }
    
    static supportsVersion(number): boolean {
      return window.ApplePaySession.supportsVersion(number)
    }
    
    static doesBrowserSupport(): boolean {
      if (window["ApplePaySession"]) {
        return true
      }
      return false
    }