From d15bd7745640c38a05350b1f6039244e732c7f62 Mon Sep 17 00:00:00 2001 From: Jax DesMarais-Leder Date: Tue, 12 Nov 2024 10:34:56 -0600 Subject: [PATCH 1/2] remove BTPayPalVaultBaseRequest --- Braintree.xcodeproj/project.pbxproj | 28 ---------- .../BTPayPalVaultBaseRequest.swift | 56 ------------------- 2 files changed, 84 deletions(-) delete mode 100644 Sources/BraintreePayPal/BTPayPalVaultBaseRequest.swift diff --git a/Braintree.xcodeproj/project.pbxproj b/Braintree.xcodeproj/project.pbxproj index 46d51f5f8..bc7ee97d0 100644 --- a/Braintree.xcodeproj/project.pbxproj +++ b/Braintree.xcodeproj/project.pbxproj @@ -226,7 +226,6 @@ BE349113294B798300D2CF68 /* BTPayPalRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE349112294B798300D2CF68 /* BTPayPalRequest.swift */; }; BE48CE4829D5DDA600F0825C /* BTThreeDSecureV2TextBoxCustomization.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE82E74029C4A1330059FE97 /* BTThreeDSecureV2TextBoxCustomization.swift */; }; BE549F112BF5445F00B6F441 /* BTPayPalReturnURL.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE6BC22D2BA9CFFC00C3E321 /* BTPayPalReturnURL.swift */; }; - BE549F122BF5449E00B6F441 /* BTPayPalVaultBaseRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE6BC22B2BA9C67600C3E321 /* BTPayPalVaultBaseRequest.swift */; }; BE549F142BF6576300B6F441 /* BTAnalyticsEventsStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE549F132BF6576300B6F441 /* BTAnalyticsEventsStorage.swift */; }; BE54C0332912B68E009C6CEE /* BTHTTP_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE54C0322912B68E009C6CEE /* BTHTTP_Tests.swift */; }; BE54C0352912B6BC009C6CEE /* BTHTTPTestProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE54C0342912B6BC009C6CEE /* BTHTTPTestProtocol.swift */; }; @@ -937,7 +936,6 @@ BE698EA328AD2C10001D9B10 /* BTCoreConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTCoreConstants.swift; sourceTree = ""; }; BE698EA528B3CDAD001D9B10 /* ConfigurationCache_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigurationCache_Tests.swift; sourceTree = ""; }; BE698EAA28B50F41001D9B10 /* BTClientToken_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTClientToken_Tests.swift; sourceTree = ""; }; - BE6BC22B2BA9C67600C3E321 /* BTPayPalVaultBaseRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTPayPalVaultBaseRequest.swift; sourceTree = ""; }; BE6BC22D2BA9CFFC00C3E321 /* BTPayPalReturnURL.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTPayPalReturnURL.swift; sourceTree = ""; }; BE70A962284FA3F000F6D3F7 /* BTDataCollectorError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTDataCollectorError.swift; sourceTree = ""; }; BE70A964284FA9DE00F6D3F7 /* MockBTDataCollector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockBTDataCollector.swift; sourceTree = ""; }; @@ -1086,13 +1084,6 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - 9CE51798282D54030013C740 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; A76D7BFC1BB1CAB00000FA6A /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -1309,7 +1300,6 @@ 57D9436D2968A8080079EAB1 /* BTPayPalLocaleCode.swift */, BE349112294B798300D2CF68 /* BTPayPalRequest.swift */, BE6BC22D2BA9CFFC00C3E321 /* BTPayPalReturnURL.swift */, - BE6BC22B2BA9C67600C3E321 /* BTPayPalVaultBaseRequest.swift */, BE349110294B77E100D2CF68 /* BTPayPalVaultRequest.swift */, 62A659A32B98CB23008DFD67 /* PrivacyInfo.xcprivacy */, 807D22F32C29ADA8009FFEA4 /* RecurringBillingMetadata */, @@ -2659,9 +2649,6 @@ 8046983D2B27C5530090878E = { CreatedOnToolsVersion = 15.0.1; }; - 9CE5179A282D54030013C740 = { - CreatedOnToolsVersion = 13.2.1; - }; A76D7BFF1BB1CAB00000FA6A = { CreatedOnToolsVersion = 7.0; LastSwiftMigration = 1340; @@ -2821,13 +2808,6 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - 9CE51799282D54030013C740 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; A76D7BFE1BB1CAB00000FA6A /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -3120,7 +3100,6 @@ BE349113294B798300D2CF68 /* BTPayPalRequest.swift in Sources */, BE549F112BF5445F00B6F441 /* BTPayPalReturnURL.swift in Sources */, 57544F5C295254A500DEB7B0 /* BTJSON+PayPal.swift in Sources */, - BE549F122BF5449E00B6F441 /* BTPayPalVaultBaseRequest.swift in Sources */, 3B7A261129C0CAA40087059D /* BTPayPalAnalytics.swift in Sources */, BE8E5CEF294B6937001BF017 /* BTPayPalCheckoutRequest.swift in Sources */, 807D22F02C29A93A009FFEA4 /* BTPayPalBillingCycle.swift in Sources */, @@ -3221,13 +3200,6 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - 9CE51797282D54030013C740 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; A76D7BFB1BB1CAB00000FA6A /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; diff --git a/Sources/BraintreePayPal/BTPayPalVaultBaseRequest.swift b/Sources/BraintreePayPal/BTPayPalVaultBaseRequest.swift deleted file mode 100644 index 99c31e82c..000000000 --- a/Sources/BraintreePayPal/BTPayPalVaultBaseRequest.swift +++ /dev/null @@ -1,56 +0,0 @@ -import Foundation - -#if canImport(BraintreeCore) -import BraintreeCore -#endif - -/// Options for the PayPal Vault flow. -@objcMembers open class BTPayPalVaultBaseRequest: BTPayPalRequest { - - // MARK: - Public Properties - - /// Optional: Offers PayPal Credit if the customer qualifies. Defaults to `false`. - public var offerCredit: Bool - - // MARK: - Initializer - - /// Initializes a PayPal Native Vault request - /// - Parameters: - /// - offerCredit: Optional: Offers PayPal Credit if the customer qualifies. Defaults to `false`. - public init(offerCredit: Bool = false) { - self.offerCredit = offerCredit - - super.init(hermesPath: "v1/paypal_hermes/setup_billing_agreement", paymentType: .vault) - } - - // MARK: Internal Methods - - override func parameters( - with configuration: BTConfiguration, - universalLink: URL? = nil, - isPayPalAppInstalled: Bool = false - ) -> [String: Any] { - let baseParameters = super.parameters(with: configuration) - var vaultParameters: [String: Any] = ["offer_paypal_credit": offerCredit] - - if let billingAgreementDescription { - vaultParameters["description"] = billingAgreementDescription - } - - if let shippingAddressOverride { - let shippingAddressParameters: [String: String?] = [ - "line1": shippingAddressOverride.streetAddress, - "line2": shippingAddressOverride.extendedAddress, - "city": shippingAddressOverride.locality, - "state": shippingAddressOverride.region, - "postal_code": shippingAddressOverride.postalCode, - "country_code": shippingAddressOverride.countryCodeAlpha2, - "recipient_name": shippingAddressOverride.recipientName - ] - - vaultParameters["shipping_address"] = shippingAddressParameters - } - - return baseParameters.merging(vaultParameters) { $1 } - } -} From f979808923b0db17769821a45f4bb1bda8fd6a65 Mon Sep 17 00:00:00 2001 From: Jax DesMarais-Leder Date: Tue, 12 Nov 2024 10:35:23 -0600 Subject: [PATCH 2/2] cleanup BTPayPalVaultRequest to subclass BTPayPalRequest --- .../BTPayPalVaultRequest.swift | 38 +++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/Sources/BraintreePayPal/BTPayPalVaultRequest.swift b/Sources/BraintreePayPal/BTPayPalVaultRequest.swift index a39cee1cd..ca33fe35a 100644 --- a/Sources/BraintreePayPal/BTPayPalVaultRequest.swift +++ b/Sources/BraintreePayPal/BTPayPalVaultRequest.swift @@ -5,13 +5,16 @@ import BraintreeCore #endif /// Options for the PayPal Vault flow. -@objcMembers public class BTPayPalVaultRequest: BTPayPalVaultBaseRequest { +@objcMembers public class BTPayPalVaultRequest: BTPayPalRequest { // MARK: - Public Properties /// 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? + /// Optional: Offers PayPal Credit if the customer qualifies. Defaults to `false`. + public var offerCredit: Bool + // MARK: - Internal Properties /// Optional: Used to determine if the customer will use the PayPal app switch flow. @@ -55,10 +58,11 @@ import BraintreeCore recurringBillingPlanType: BTPayPalRecurringBillingPlanType? = nil, userAuthenticationEmail: String? = nil ) { + self.offerCredit = offerCredit self.recurringBillingDetails = recurringBillingDetails self.recurringBillingPlanType = recurringBillingPlanType self.userAuthenticationEmail = userAuthenticationEmail - super.init(offerCredit: offerCredit) + super.init(hermesPath: "v1/paypal_hermes/setup_billing_agreement", paymentType: .vault) } public override func parameters( @@ -68,7 +72,7 @@ import BraintreeCore ) -> [String: Any] { var baseParameters = super.parameters(with: configuration) - if let userAuthenticationEmail { + if let userAuthenticationEmail, !userAuthenticationEmail.isEmpty { baseParameters["payer_email"] = userAuthenticationEmail } @@ -79,18 +83,38 @@ import BraintreeCore "os_type": UIDevice.current.systemName, "merchant_app_return_url": universalLink.absoluteString ] - + return baseParameters.merging(appSwitchParameters) { $1 } } - + if let recurringBillingPlanType { baseParameters["plan_type"] = recurringBillingPlanType.rawValue } - + if let recurringBillingDetails { baseParameters["plan_metadata"] = recurringBillingDetails.parameters() } - return baseParameters + var vaultParameters: [String: Any] = ["offer_paypal_credit": offerCredit] + + if let billingAgreementDescription { + vaultParameters["description"] = billingAgreementDescription + } + + if let shippingAddressOverride { + let shippingAddressParameters: [String: String?] = [ + "line1": shippingAddressOverride.streetAddress, + "line2": shippingAddressOverride.extendedAddress, + "city": shippingAddressOverride.locality, + "state": shippingAddressOverride.region, + "postal_code": shippingAddressOverride.postalCode, + "country_code": shippingAddressOverride.countryCodeAlpha2, + "recipient_name": shippingAddressOverride.recipientName + ] + + vaultParameters["shipping_address"] = shippingAddressParameters + } + + return baseParameters.merging(vaultParameters) { $1 } } }