Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 3DS and GraphQL Endpoint Sent to FPTI #1375

Merged
merged 6 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion Sources/BraintreeCore/BTAPIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,21 @@ import Foundation
func fetchAPITiming(path: String, connectionStartTime: Int?, requestStartTime: Int?, startTime: Int, endTime: Int) {
let cleanedPath = path.replacingOccurrences(of: "/merchants/([A-Za-z0-9]+)/client_api", with: "", options: .regularExpression)

if cleanedPath != "/v1/tracking/batch/events" {
if cleanedPath.contains("three_d_secure") {
jaxdesmarais marked this conversation as resolved.
Show resolved Hide resolved
let threeDSecurePath = cleanedPath.replacingOccurrences(
of: "payment_methods/.*/three_d_secure",
with: "payment_methods/three_d_secure",
options: .regularExpression
)
jaxdesmarais marked this conversation as resolved.
Show resolved Hide resolved
analyticsService?.sendAnalyticsEvent(
BTCoreAnalytics.apiRequestLatency,
connectionStartTime: connectionStartTime,
endpoint: threeDSecurePath,
endTime: endTime,
requestStartTime: requestStartTime,
startTime: startTime
)
} else if cleanedPath != "/v1/tracking/batch/events" {
analyticsService?.sendAnalyticsEvent(
BTCoreAnalytics.apiRequestLatency,
connectionStartTime: connectionStartTime,
Expand Down
10 changes: 7 additions & 3 deletions Sources/BraintreeCore/BTHTTP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,12 @@ class BTHTTP: NSObject, URLSessionTaskDelegate {
let json = try? JSONSerialization.jsonObject(with: data)
let body = BTJSON(value: json)

guard let mutationName = body["operationName"].asString() else { return nil }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The card GraphQL request is the only flow that uses operationName so for other flows such as Venmo we were sending the endpoint as /graphql. This update allows us to now send the expected query/mutation name.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious - would this change affect us being able to fetch the mutation name for the card graphql flow 👀

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still pass in a mutation as expected for the card flow, we just extract it from here:

var mutation = "mutation TokenizeCreditCard($input: TokenizeCreditCardInput!"
vs concatenating the mutation string to the operationName. So card is passed as mutation TokenizeCreditCard same as prior to this change.


return "mutation \(mutationName)"
guard let query = body["query"].asString() else {
return nil
}

let queryDiscardHolder = query.replacingOccurrences(of: #"^[^\(]*"#, with: "", options: .regularExpression)
jaxdesmarais marked this conversation as resolved.
Show resolved Hide resolved
let finalQuery = query.replacingOccurrences(of: queryDiscardHolder, with: "")
return finalQuery
}
}
3 changes: 2 additions & 1 deletion UnitTests/BraintreeCoreTests/BTHTTP_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,8 @@ final class BTHTTP_Tests: XCTestCase {
var originalRequest = URLRequest(url: URL(string: "https://example.com/graphql")!)
originalRequest.httpBody = """
{
"operationName": "TestMutation"
"operationName": "TestMutation",
"query": "mutation TestMutation()"
}
""".data(using: .utf8)
let task = testURLSession.dataTask(with: originalRequest)
Expand Down
Loading