Skip to content

Commit

Permalink
capture
Browse files Browse the repository at this point in the history
  • Loading branch information
davidme-stripe committed Dec 17, 2024
1 parent c21e7e3 commit 48de1bc
Showing 1 changed file with 45 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,29 @@ extension STPAPIClient {
useModernMobileEndpoints: Bool,
completion: @escaping (Result<ConsumerSession.LookupResponse, Error>) -> Void
) {
let legacyEndpoint = "consumers/sessions/lookup"
let modernEndpoint = "consumers/mobile/sessions/lookup"

var parameters: [String: Any] = [
"request_surface": "ios_payment_element",
]
if let email, let emailSource {
parameters["email_address"] = email.lowercased()
parameters["email_source"] = emailSource.rawValue
}
parameters["session_id"] = sessionID

guard parameters.keys.contains("email_address") else {
// no request to make if we don't have an email
DispatchQueue.main.async {
completion(.success(
ConsumerSession.LookupResponse(.noAvailableLookupParams)
))
Task {
let legacyEndpoint = "consumers/sessions/lookup"
let modernEndpoint = "consumers/mobile/sessions/lookup"

var parameters: [String: Any] = [
"request_surface": "ios_payment_element",
]
if let email, let emailSource {
parameters["email_address"] = email.lowercased()
parameters["email_source"] = emailSource.rawValue
}
parameters["session_id"] = sessionID

guard parameters.keys.contains("email_address") else {
// no request to make if we don't have an email
DispatchQueue.main.async {
completion(.success(
ConsumerSession.LookupResponse(.noAvailableLookupParams)
))
}
return
}
return
}

Task {
// Explicitly capture the parameters within the task:
var parameters = parameters
if useModernMobileEndpoints {
do {
let attest = StripeAttest(apiClient: self)
Expand All @@ -67,7 +65,6 @@ extension STPAPIClient {
completion(result)
}
}

}

func createConsumer(
Expand All @@ -80,32 +77,30 @@ extension STPAPIClient {
useModernMobileEndpoints: Bool,
completion: @escaping (Result<ConsumerSession.SessionWithPublishableKey, Error>) -> Void
) {
let legacyEndpoint = "consumers/accounts/sign_up"
let modernEndpoint = "consumers/mobile/sign_up"

var parameters: [String: Any] = [
"request_surface": "ios_payment_element",
"email_address": email.lowercased(),
"phone_number": phoneNumber,
"locale": locale.toLanguageTag(),
"country_inferring_method": "PHONE_NUMBER",
]

if let legalName = legalName {
parameters["legal_name"] = legalName
}

if let countryCode = countryCode {
parameters["country"] = countryCode
}

if let consentAction = consentAction {
parameters["consent_action"] = consentAction
}

Task {
// Explicitly capture the parameters within the task:
var parameters = parameters
let legacyEndpoint = "consumers/accounts/sign_up"
let modernEndpoint = "consumers/mobile/sign_up"

var parameters: [String: Any] = [
"request_surface": "ios_payment_element",
"email_address": email.lowercased(),
"phone_number": phoneNumber,
"locale": locale.toLanguageTag(),
"country_inferring_method": "PHONE_NUMBER",
]

if let legalName = legalName {
parameters["legal_name"] = legalName
}

if let countryCode = countryCode {
parameters["country"] = countryCode
}

if let consentAction = consentAction {
parameters["consent_action"] = consentAction
}

if useModernMobileEndpoints {
do {
let attest = StripeAttest(apiClient: self)
Expand All @@ -124,7 +119,7 @@ extension STPAPIClient {
if useModernMobileEndpoints, case .failure(let error) = result {
StripeAttest(apiClient: self).receivedAssertionError(error)
}

completion(result)
}
}
Expand Down

0 comments on commit 48de1bc

Please sign in to comment.