Skip to content

Commit

Permalink
address pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
agedd committed Feb 12, 2025
1 parent 02074b5 commit e8e4d11
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 4 deletions.
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Braintree iOS SDK Release Notes

## unreleased
* BraintreePayPal
* Add PayPal App Switch checkout Flow (BETA)
* Add `BTPayPalCheckoutRequest(userAuthenticationEmail:enablePayPalAppSwitch:amount:intent:userAction:offerPayLater:currencyCode:requestBillingAgreement:)`
* **Note:** This feature is currently in beta and may change or be removed in future releases.

## 6.28.0 (2025-02-05)
* BraintreeVenmo
* Allow universal links to be set without a return URL scheme (fixes #1505)
Expand Down Expand Up @@ -32,9 +38,6 @@
## 6.25.0 (2024-12-11)
* BraintreePayPal
* Add `BTPayPalRequest.userPhoneNumber` optional property
* Add PayPal App Switch checkout Flow (BETA)
* Add `BTPayPalCheckoutRequest(userAuthenticationEmail:enablePayPalAppSwitch:amount:intent:userAction: offerPayLater:currencyCode:requestBillingAgreement:)`
* **Note:** This feature is currently in beta and may change or be removed in future releases.
* 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)
Expand Down
69 changes: 68 additions & 1 deletion UnitTests/BraintreePayPalTests/BTPayPalClient_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ class BTPayPalClient_Tests: XCTestCase {
XCTAssertNil(BTPayPalClient.payPalClient)
}

// MARK: - App Switch - tokenize
// MARK: - App Switch - Tokenize

func testTokenizeVaultAccount_whenPayPalAppApprovalURLPresent_attemptsAppSwitchWithParameters() async {
let fakeApplication = FakeApplication()
Expand Down Expand Up @@ -858,6 +858,73 @@ class BTPayPalClient_Tests: XCTestCase {

waitForExpectations(timeout: 1)
}

func testTokenizeCheckoutAccount_whenPayPalAppApprovalURLPresent_attemptsAppSwitchWithParameters() async {
let fakeApplication = FakeApplication()
payPalClient.application = fakeApplication

mockAPIClient.cannedResponseBody = BTJSON(value: [
"paymentResource": [
"redirectUrl": "https://www.some-url.com/some-path?token=value1",
"launchPayPalApp": true
]
])

let checkoutRequest = BTPayPalCheckoutRequest(
userAuthenticationEmail: "[email protected]",
enablePayPalAppSwitch: true,
amount: "10.00"
)
payPalClient.tokenize(checkoutRequest) { _, _ in }

XCTAssertTrue(fakeApplication.openURLWasCalled)

let urlComponents = URLComponents(url: fakeApplication.lastOpenURL!, resolvingAgainstBaseURL: true)
XCTAssertEqual(urlComponents?.host, "www.some-url.com")
XCTAssertEqual(urlComponents?.path, "/some-path")

XCTAssertEqual(urlComponents?.queryItems?[0].name, "token")
XCTAssertEqual(urlComponents?.queryItems?[0].value, "value1")
XCTAssertEqual(urlComponents?.queryItems?[1].name, "source")
XCTAssertEqual(urlComponents?.queryItems?[1].value, "braintree_sdk")
XCTAssertEqual(urlComponents?.queryItems?[2].name, "switch_initiated_time")
if let urlTimestamp = urlComponents?.queryItems?[2].value {
XCTAssertNotNil(urlTimestamp)
} else {
XCTFail("Expected integer value for query param `switch_initiated_time`")
}
}

func testTokenizeCheckoutAccount_whenPayPalAppApprovalURLMissingECToken_returnsError() {
let fakeApplication = FakeApplication()
payPalClient.application = fakeApplication

mockAPIClient.cannedResponseBody = BTJSON(value: [
"paymentResource": [
"redirectUrl": "https://www.some-url.com/some-path",
"launchPayPalApp": true
]
])

let checkoutRequest = BTPayPalCheckoutRequest(
userAuthenticationEmail: "[email protected]",
enablePayPalAppSwitch: true,
amount: "10.00"
)

let expectation = expectation(description: "completion block called")
payPalClient.tokenize(checkoutRequest) { nonce, error in
XCTAssertNil(nonce)

guard let error = error as NSError? else { XCTFail(); return }
XCTAssertEqual(error.code, 14)
XCTAssertEqual(error.localizedDescription, "Missing EC Token for PayPal App Switch.")
XCTAssertEqual(error.domain, "com.braintreepayments.BTPayPalErrorDomain")
expectation.fulfill()
}

waitForExpectations(timeout: 1)
}

func testHandleReturn_whenURLIsUnknown_returnsError() {
let request = BTPayPalVaultRequest(
Expand Down

0 comments on commit e8e4d11

Please sign in to comment.