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

[DO NOT REVIEW] Merge Contact Information Feature Branch #1495

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions Braintree.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
42FC237125CE0E110047C49A /* BTPayPalCheckoutRequest_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42FC237025CE0E110047C49A /* BTPayPalCheckoutRequest_Tests.swift */; };
45227FC52C330FDE00A15018 /* MockURLSessionTask.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45227FC32C330FDE00A15018 /* MockURLSessionTask.swift */; };
45227FC72C33104100A15018 /* MockBTHTTPNetworkTiming.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45227FC62C33104100A15018 /* MockBTHTTPNetworkTiming.swift */; };
454722AC2CEFB291000DCF4E /* BTContactInformation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 454722AB2CEFB291000DCF4E /* BTContactInformation.swift */; };
457D7FC82C29CEC300EF6523 /* RepeatingTimer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 457D7FC72C29CEC300EF6523 /* RepeatingTimer.swift */; };
457D7FCA2C2A250E00EF6523 /* RepeatingTimer_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 457D7FC92C2A250E00EF6523 /* RepeatingTimer_Tests.swift */; };
458570782C34A699009CEF7A /* ConfigurationLoader_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 458570772C34A699009CEF7A /* ConfigurationLoader_Tests.swift */; };
Expand Down Expand Up @@ -790,6 +791,7 @@
42FC237025CE0E110047C49A /* BTPayPalCheckoutRequest_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTPayPalCheckoutRequest_Tests.swift; sourceTree = "<group>"; };
45227FC32C330FDE00A15018 /* MockURLSessionTask.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockURLSessionTask.swift; sourceTree = "<group>"; };
45227FC62C33104100A15018 /* MockBTHTTPNetworkTiming.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockBTHTTPNetworkTiming.swift; sourceTree = "<group>"; };
454722AB2CEFB291000DCF4E /* BTContactInformation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTContactInformation.swift; sourceTree = "<group>"; };
457D7FC72C29CEC300EF6523 /* RepeatingTimer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RepeatingTimer.swift; sourceTree = "<group>"; };
457D7FC92C2A250E00EF6523 /* RepeatingTimer_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RepeatingTimer_Tests.swift; sourceTree = "<group>"; };
458570772C34A699009CEF7A /* ConfigurationLoader_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigurationLoader_Tests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1406,6 +1408,7 @@
62A659A32B98CB23008DFD67 /* PrivacyInfo.xcprivacy */,
807D22F32C29ADA8009FFEA4 /* RecurringBillingMetadata */,
62B811872CC002470024A688 /* BTPayPalPhoneNumber.swift */,
454722AB2CEFB291000DCF4E /* BTContactInformation.swift */,
);
path = BraintreePayPal;
sourceTree = "<group>";
Expand Down Expand Up @@ -3291,6 +3294,7 @@
57544F582952298900DEB7B0 /* BTPayPalAccountNonce.swift in Sources */,
8014221C2BAE935B009F9999 /* BTPayPalApprovalURLParser.swift in Sources */,
BE349111294B77E100D2CF68 /* BTPayPalVaultRequest.swift in Sources */,
454722AC2CEFB291000DCF4E /* BTContactInformation.swift in Sources */,
62B811882CC002470024A688 /* BTPayPalPhoneNumber.swift in Sources */,
807D22F52C29ADE2009FFEA4 /* BTPayPalRecurringBillingPlanType.swift in Sources */,
57544820294A2EBE00DEB7B0 /* BTPayPalCreditFinancing.swift in Sources */,
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Braintree iOS SDK Release Notes

## unreleased
* BraintreePayPal
* Add `BTContactInformation` request object
* Add `BTPayPalCheckoutRequest.contactInformation` optional property

## 6.25.0 (2024-12-11)
* BraintreePayPal
* Add `BTPayPalRequest.userPhoneNumber` optional property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,11 @@ class PayPalWebCheckoutViewController: PaymentButtonBaseViewController {
let newPayPalCheckoutToggle = Toggle(title: "New PayPal Checkout Experience")

let rbaDataToggle = Toggle(title: "Recurring Billing (RBA) Data")

let contactInformationToggle = Toggle(title: "Add Contact Information")

override func viewDidLoad() {
super.heightConstraint = 400
super.heightConstraint = 500
super.viewDidLoad()
}

Expand All @@ -93,6 +95,7 @@ class PayPalWebCheckoutViewController: PaymentButtonBaseViewController {
let oneTimeCheckoutStackView = buttonsStackView(label: "1-Time Checkout", views: [
payLaterToggle,
newPayPalCheckoutToggle,
contactInformationToggle,
payPalCheckoutButton
])
oneTimeCheckoutStackView.spacing = 12
Expand Down Expand Up @@ -151,6 +154,13 @@ class PayPalWebCheckoutViewController: PaymentButtonBaseViewController {
request.offerPayLater = payLaterToggle.isOn
request.intent = newPayPalCheckoutToggle.isOn ? .sale : .authorize

if contactInformationToggle.isOn {
request.contactInformation = BTContactInformation(
recipientEmail: "[email protected]",
recipientPhoneNumber: .init(countryCode: "52", nationalNumber: "123456789")
)
}

payPalClient.tokenize(request) { nonce, error in
sender.isEnabled = true

Expand Down
19 changes: 19 additions & 0 deletions Sources/BraintreePayPal/BTContactInformation.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/// Contact information of the recipient for the order
public struct BTContactInformation {

// MARK: - Internal Properties

let recipientEmail: String?
let recipientPhoneNumber: BTPayPalPhoneNumber?

// MARK: - Initializer

/// Intialize a BTContactInformation
/// - Parameters:
/// - recipientEmail: Optional: Email address of the recipient.
/// - recipientPhoneNumber: Optional: Phone number of the recipient.
public init(recipientEmail: String? = nil, recipientPhoneNumber: BTPayPalPhoneNumber? = nil) {
self.recipientEmail = recipientEmail
self.recipientPhoneNumber = recipientPhoneNumber
}
}
13 changes: 12 additions & 1 deletion Sources/BraintreePayPal/BTPayPalCheckoutRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ import BraintreeCore

/// 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: Contact information of the recipient for the order
public var contactInformation: BTContactInformation?

// MARK: - Initializer

Expand Down Expand Up @@ -164,7 +167,15 @@ import BraintreeCore
checkoutParameters["country_code"] = shippingAddressOverride?.countryCodeAlpha2
checkoutParameters["recipient_name"] = shippingAddressOverride?.recipientName
}


if let recipientEmail = contactInformation?.recipientEmail {
checkoutParameters["recipient_email"] = recipientEmail
}

if let recipientPhoneNumber = try? contactInformation?.recipientPhoneNumber?.toDictionary() {
checkoutParameters["international_phone"] = recipientPhoneNumber
}

return baseParameters.merging(checkoutParameters) { $1 }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,27 @@ class BTPayPalCheckoutRequest_Tests: XCTestCase {

XCTAssertNil(parameters["payer_email"])
}

func testParametersWithConfiguration__withContactInformation_setsRecipientEmailAndPhoneNumber() {
let request = BTPayPalCheckoutRequest(amount: "1")
request.contactInformation = BTContactInformation(
recipientEmail: "[email protected]",
recipientPhoneNumber: BTPayPalPhoneNumber(countryCode: "US", nationalNumber: "123456789")
)

let parameters = request.parameters(with: configuration)

XCTAssertEqual(parameters["recipient_email"] as? String, "[email protected]")
let internationalPhone = parameters["international_phone"] as? [String: String]
XCTAssertEqual(internationalPhone, ["country_code": "US", "national_number": "123456789"])
}

func testParametersWithConfiguration_whenContactInformationNotSet_doesNotSetPayerEmailAndPhoneNumberInRequest() {
let request = BTPayPalCheckoutRequest(amount: "1")

let parameters = request.parameters(with: configuration)

XCTAssertNil(parameters["recipient_email"])
XCTAssertNil(parameters["international_phone"])
}
}