Skip to content

Commit

Permalink
[BANKCON-15001] Add telemetry fields to /share and /payment_methods A…
Browse files Browse the repository at this point in the history
…PI calls
  • Loading branch information
mats-stripe committed Sep 30, 2024
1 parent 5f07c01 commit 935e2a5
Showing 1 changed file with 39 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ final class FinancialConnectionsAPIClient {
ephemeralKeySecret: possibleConsumerPublishableKey
)
}

private func updateAndApplyFraudDetection(to parameters: [String: Any]) -> Future<[String: Any]> {
let promise = Promise<[String: Any]>()
STPTelemetryClient.shared.updateFraudDetectionIfNecessary { _ in
// Fire and forget operation. Ignore any possible errors here.
var paramsWithTelemetry = parameters
paramsWithTelemetry = STPTelemetryClient.shared.paramsByAddingTelemetryFields(toParams: paramsWithTelemetry)
promise.fulfill { paramsWithTelemetry }
}
return promise
}
}

protocol FinancialConnectionsAPI {
Expand Down Expand Up @@ -964,11 +975,20 @@ extension FinancialConnectionsAPIClient: FinancialConnectionsAPI {
"expected_payment_method_type": expectedPaymentMethodType,
"expand": ["payment_method"],
]
return post(
resource: APIEndpointSharePaymentDetails,
parameters: parameters,
useConsumerPublishableKeyIfNeeded: false
)

return updateAndApplyFraudDetection(to: parameters)
.chained { [weak self] parametersWithTelemetry -> Future<FinancialConnectionsSharePaymentDetails> in
guard let self else {
return Promise(
error: FinancialConnectionsSheetError.unknown(debugDescription: "FinancialConnectionsAPIClient was deallocated.")
)
}
return self.post(
resource: APIEndpointSharePaymentDetails,
parameters: parametersWithTelemetry,
useConsumerPublishableKeyIfNeeded: false
)
}
}

func paymentMethods(
Expand All @@ -984,11 +1004,20 @@ extension FinancialConnectionsAPIClient: FinancialConnectionsAPI {
],
"type": "link",
]
return post(
resource: APIEndpointPaymentMethods,
parameters: parameters,
useConsumerPublishableKeyIfNeeded: false
)

return updateAndApplyFraudDetection(to: parameters)
.chained { [weak self] parametersWithTelemetry -> Future<FinancialConnectionsPaymentMethod> in
guard let self else {
return Promise(
error: FinancialConnectionsSheetError.unknown(debugDescription: "FinancialConnectionsAPIClient was deallocated.")
)
}
return self.post(
resource: APIEndpointPaymentMethods,
parameters: parametersWithTelemetry,
useConsumerPublishableKeyIfNeeded: false
)
}
}
}

Expand Down

0 comments on commit 935e2a5

Please sign in to comment.