From cd593a2245db495532b57d4d67ddb02d2277a936 Mon Sep 17 00:00:00 2001 From: Jax DesMarais-Leder Date: Mon, 2 Dec 2024 13:09:18 -0600 Subject: [PATCH 1/4] pass URL to paymentMethodsDisplayed --- Sources/BraintreePayPal/BTPayPalClient.swift | 46 ++++++++++---------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/Sources/BraintreePayPal/BTPayPalClient.swift b/Sources/BraintreePayPal/BTPayPalClient.swift index 0362ed1597..9d5ee0e8e5 100644 --- a/Sources/BraintreePayPal/BTPayPalClient.swift +++ b/Sources/BraintreePayPal/BTPayPalClient.swift @@ -284,6 +284,29 @@ import BraintreeDataCollector performSwitchRequest(appSwitchURL: url, paymentType: paymentType, completion: completion) } + func invokedOpenURLSuccessfully(_ success: Bool, url: URL, completion: @escaping (BTPayPalAccountNonce?, Error?) -> Void) { + if success { + apiClient.sendAnalyticsEvent( + BTPayPalAnalytics.appSwitchSucceeded, + isVaultRequest: isVaultRequest, + linkType: linkType, + payPalContextID: payPalContextID, + appSwitchURL: url + ) + BTPayPalClient.payPalClient = self + appSwitchCompletion = completion + } else { + apiClient.sendAnalyticsEvent( + BTPayPalAnalytics.appSwitchFailed, + isVaultRequest: isVaultRequest, + linkType: linkType, + payPalContextID: payPalContextID, + appSwitchURL: url + ) + notifyFailure(with: BTPayPalError.appSwitchFailed, completion: completion) + } + } + // MARK: - App Switch Methods func handleReturnURL(_ url: URL) { @@ -404,28 +427,7 @@ import BraintreeDataCollector } application.open(redirectURL) { success in - self.invokedOpenURLSuccessfully(success, completion: completion) - } - } - - private func invokedOpenURLSuccessfully(_ success: Bool, completion: @escaping (BTPayPalAccountNonce?, Error?) -> Void) { - if success { - apiClient.sendAnalyticsEvent( - BTPayPalAnalytics.appSwitchSucceeded, - isVaultRequest: isVaultRequest, - linkType: linkType, - payPalContextID: payPalContextID - ) - BTPayPalClient.payPalClient = self - appSwitchCompletion = completion - } else { - apiClient.sendAnalyticsEvent( - BTPayPalAnalytics.appSwitchFailed, - isVaultRequest: isVaultRequest, - linkType: linkType, - payPalContextID: payPalContextID - ) - notifyFailure(with: BTPayPalError.appSwitchFailed, completion: completion) + self.invokedOpenURLSuccessfully(success, url: redirectURL, completion: completion) } } From fbddf62919f49b39881cd9e082d784bf8f687dcb Mon Sep 17 00:00:00 2001 From: Jax DesMarais-Leder Date: Mon, 2 Dec 2024 13:09:28 -0600 Subject: [PATCH 2/4] add unit tests --- .../BTPayPalClient_Tests.swift | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/UnitTests/BraintreePayPalTests/BTPayPalClient_Tests.swift b/UnitTests/BraintreePayPalTests/BTPayPalClient_Tests.swift index 7fff4ad489..810a720764 100644 --- a/UnitTests/BraintreePayPalTests/BTPayPalClient_Tests.swift +++ b/UnitTests/BraintreePayPalTests/BTPayPalClient_Tests.swift @@ -982,6 +982,24 @@ class BTPayPalClient_Tests: XCTestCase { XCTAssertNil(lastPostParameters["merchant_app_return_url"] as? String) } + func testInvokedOpenURLSuccessfully_whenSuccess_sendsAppSwitchSucceededWithAppSwitchURL() { + let eventName = BTPayPalAnalytics.appSwitchSucceeded + let appSwitchURL = URL(string: "some-url")! + payPalClient.invokedOpenURLSuccessfully(true, url: appSwitchURL) { _, _ in } + + XCTAssertEqual(mockAPIClient.postedAnalyticsEvents.last!, eventName) + XCTAssertEqual(mockAPIClient.postedAppSwitchURL[eventName], appSwitchURL.absoluteString) + } + + func testInvokedOpenURLSuccessfully_whenFailure_sendsAppSwitchFailedWithAppSwitchURL() { + let eventName = BTPayPalAnalytics.appSwitchFailed + let appSwitchURL = URL(string: "some-url")! + payPalClient.invokedOpenURLSuccessfully(false, url: appSwitchURL) { _, _ in } + + XCTAssertEqual(mockAPIClient.postedAnalyticsEvents.first!, eventName) + XCTAssertEqual(mockAPIClient.postedAppSwitchURL[eventName], appSwitchURL.absoluteString) + } + // MARK: - Analytics func testAPIClientMetadata_hasIntegrationSetToCustom() { From c11319f5be0b2367c6ccc365688c6eb539cf514c Mon Sep 17 00:00:00 2001 From: Jax DesMarais-Leder Date: Mon, 2 Dec 2024 13:16:59 -0600 Subject: [PATCH 3/4] cleanup property names --- .../BraintreePayPalTests/BTPayPalClient_Tests.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/UnitTests/BraintreePayPalTests/BTPayPalClient_Tests.swift b/UnitTests/BraintreePayPalTests/BTPayPalClient_Tests.swift index 810a720764..787e9ef356 100644 --- a/UnitTests/BraintreePayPalTests/BTPayPalClient_Tests.swift +++ b/UnitTests/BraintreePayPalTests/BTPayPalClient_Tests.swift @@ -984,20 +984,20 @@ class BTPayPalClient_Tests: XCTestCase { func testInvokedOpenURLSuccessfully_whenSuccess_sendsAppSwitchSucceededWithAppSwitchURL() { let eventName = BTPayPalAnalytics.appSwitchSucceeded - let appSwitchURL = URL(string: "some-url")! - payPalClient.invokedOpenURLSuccessfully(true, url: appSwitchURL) { _, _ in } + let fakeURL = URL(string: "some-url")! + payPalClient.invokedOpenURLSuccessfully(true, url: fakeURL) { _, _ in } XCTAssertEqual(mockAPIClient.postedAnalyticsEvents.last!, eventName) - XCTAssertEqual(mockAPIClient.postedAppSwitchURL[eventName], appSwitchURL.absoluteString) + XCTAssertEqual(mockAPIClient.postedAppSwitchURL[eventName], fakeURL.absoluteString) } func testInvokedOpenURLSuccessfully_whenFailure_sendsAppSwitchFailedWithAppSwitchURL() { let eventName = BTPayPalAnalytics.appSwitchFailed - let appSwitchURL = URL(string: "some-url")! - payPalClient.invokedOpenURLSuccessfully(false, url: appSwitchURL) { _, _ in } + let fakeURL = URL(string: "some-url")! + payPalClient.invokedOpenURLSuccessfully(false, url: fakeURL) { _, _ in } XCTAssertEqual(mockAPIClient.postedAnalyticsEvents.first!, eventName) - XCTAssertEqual(mockAPIClient.postedAppSwitchURL[eventName], appSwitchURL.absoluteString) + XCTAssertEqual(mockAPIClient.postedAppSwitchURL[eventName], fakeURL.absoluteString) } // MARK: - Analytics From 4b56221cf63630e8f52702f4bf4bcecd3717d4e0 Mon Sep 17 00:00:00 2001 From: Jax DesMarais-Leder Date: Mon, 2 Dec 2024 13:25:57 -0600 Subject: [PATCH 4/4] add CHANGELOG entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 156f060520..56799e4e79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## unreleased * BraintreePayPal * Add `BTPayPalRequest.userPhoneNumber` optional property + * Send `url` in `event_params` for App Switch events to PayPal's analytics service (FPTI) * BraintreeVenmo * Send `url` in `event_params` for App Switch events to PayPal's analytics service (FPTI)