         }
         task.resume()
         semaphore.wait()
-        
+
         if let resultError = resultError {
             throw resultError
         }
         return result
     }
-    
+
     /**
      Build the basic authentication header from username/password
      - parameters:

        }
        return result
    }
    
    private static func parseCurrenciesJSON(data: Data?) -> BSCurrencies? {
        
        var resultData : BSCurrencies?
        if let data = data {
            do {
                // Parse the result JSOn object
                if let json = try JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [String : AnyObject] {
                    var currencies : [BSCurrency] = []
                    if let currencyName = json["baseCurrencyName"] as? String
                    , let currencyCode = json["baseCurrency"] as? String {
                        let bsCurrency = BSCurrency(name: currencyName, code: currencyCode, rate: 1.0)
                        currencies.append(bsCurrency)
                    }
                    if let exchangeRatesArr = json["exchangeRate"] as? [[String : Any]] {
                        for exchangeRateItem in exchangeRatesArr {
                            if let currencyName = exchangeRateItem["quoteCurrencyName"] as? String
                                , let currencyCode = exchangeRateItem["quoteCurrency"] as? String
                                , let currencyRate = exchangeRateItem["conversionRate"] as? Double {
                                let bsCurrency = BSCurrency(name: currencyName, code: currencyCode, rate: currencyRate)
                                currencies.append(bsCurrency)
                            }
                        }
                    }
                    currencies = currencies.sorted { $0.name < $1.name }
                    resultData = BSCurrencies(currencies: currencies)
                } else {
                    NSLog("Error parsing BS currency rates")

        let base64LoginStr = loginData.base64EncodedString()
        return "Basic \(base64LoginStr)"
    }

    private static func notifyTokenExpired() {
        DispatchQueue.main.async {
            NotificationCenter.default.post(name: Notification.Name.bsTokenExpirationNotification, object: nil)
        }
    }

    private static func parseApplePayResponse(httpStatusCode: Int, data: Data?) -> (BSResultCcDetails?, BSCcDetailErrors?) {
        var result: BSResultCcDetails?
        var resultError: BSCcDetailErrors?

        if (httpStatusCode >= 200 && httpStatusCode <= 299 && !self.simulateTokenExpired) {
//            if (result == nil) {
//                resultError = .unknown
//            }
        } else if (httpStatusCode == 400 || self.simulateTokenExpired) {
            resultError = .unknown
            if let data = data {
                let errStr = NSString(data: data, encoding: String.Encoding.utf8.rawValue)
                if (errStr == "\"EXPIRED_TOKEN\"" || self.simulateTokenExpired) {
                    resultError = .expiredToken
                    notifyTokenExpired()
                }
            }
        } else {
            NSLog("Http error submitting ApplePay details to BS; HTTP status = \(httpStatusCode)")
            resultError = .unknown
        }
        return (result, resultError)
    }



    /**
