From 267fc968eced1cdde8fe63dd5870f690c560436a Mon Sep 17 00:00:00 2001 From: scannillo <35243507+scannillo@users.noreply.github.com> Date: Tue, 19 Mar 2024 10:25:24 -0500 Subject: [PATCH] [V6] Accept email in `BTPayPalVaultRequest` (#1223) --- CHANGELOG.md | 3 +++ Sources/BraintreePayPal/BTPayPalVaultRequest.swift | 12 ++++++++++-- .../BTPayPalVaultRequest_Tests.swift | 2 ++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 352a9bc111..9e17ad3f89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Braintree iOS SDK Release Notes +## unreleased +* Add `BTPayPalVaultRequest.userAuthenticationEmail` optional property + ## 6.15.0 (2024-03-18) * [Meets Apple's new Privacy Update requirements](https://developer.apple.com/news/?id=3d8a9yyh) diff --git a/Sources/BraintreePayPal/BTPayPalVaultRequest.swift b/Sources/BraintreePayPal/BTPayPalVaultRequest.swift index 02f4d62d3f..d6f4461742 100644 --- a/Sources/BraintreePayPal/BTPayPalVaultRequest.swift +++ b/Sources/BraintreePayPal/BTPayPalVaultRequest.swift @@ -11,13 +11,17 @@ import BraintreeCore /// Optional: Offers PayPal Credit if the customer qualifies. Defaults to `false`. public var offerCredit: Bool + + /// Optional: User email to initiate a quicker authentication flow in cases where the user has a PayPal Account with the same email. + public var userAuthenticationEmail: String? // MARK: - Initializer /// Initializes a PayPal Native Vault request /// - Parameter offerCredit: Optional: Offers PayPal Credit if the customer qualifies. Defaults to `false`. - public init(offerCredit: Bool = false) { + public init(offerCredit: Bool = false, userAuthenticationEmail: String? = nil) { self.offerCredit = offerCredit + self.userAuthenticationEmail = userAuthenticationEmail super.init(hermesPath: "v1/paypal_hermes/setup_billing_agreement", paymentType: .vault) } @@ -30,9 +34,13 @@ import BraintreeCore let baseParameters = super.parameters(with: configuration) var vaultParameters: [String: Any] = ["offer_paypal_credit": offerCredit] - if billingAgreementDescription != nil { + if let billingAgreementDescription { vaultParameters["description"] = billingAgreementDescription } + + if let userAuthenticationEmail { + vaultParameters["payer_email"] = userAuthenticationEmail + } if let shippingAddressOverride { let shippingAddressParameters: [String: String?] = [ diff --git a/UnitTests/BraintreePayPalTests/BTPayPalVaultRequest_Tests.swift b/UnitTests/BraintreePayPalTests/BTPayPalVaultRequest_Tests.swift index 7735c26a96..c2baf2407a 100644 --- a/UnitTests/BraintreePayPalTests/BTPayPalVaultRequest_Tests.swift +++ b/UnitTests/BraintreePayPalTests/BTPayPalVaultRequest_Tests.swift @@ -47,11 +47,13 @@ class BTPayPalVaultRequest_Tests: XCTestCase { request.shippingAddressOverride = shippingAddress request.isShippingAddressEditable = true request.offerCredit = true + request.userAuthenticationEmail = "fake@email.com" let parameters = request.parameters(with: configuration) XCTAssertEqual(parameters["description"] as? String, "desc") XCTAssertEqual(parameters["offer_paypal_credit"] as? Bool, true) + XCTAssertEqual(parameters["payer_email"] as? String, "fake@email.com") guard let shippingParams = parameters["shipping_address"] as? [String:String] else { XCTFail(); return }