-
Notifications
You must be signed in to change notification settings - Fork 995
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
[BANKCON-15711] Pass billing address and email address to payment details API #4148
Merged
mats-stripe
merged 4 commits into
master
from
mats/pass_billing_address_to_payment_details
Oct 29, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4c452d4
Hide Panther Bank tab for ineligible merchant configuration
mats-stripe dbdfeab
Move eligibility logic to extension property
mats-stripe 0fad879
Pass billing address and email address to payment details API
mats-stripe 7dbe362
Add another encoding unit test, only pass billing address when config…
mats-stripe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
StripeCore/StripeCore/Source/Connections Bindings/BillingAddress.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// | ||
// BillingAddress.swift | ||
// StripeCore | ||
// | ||
// Created by Mat Schmid on 2024-10-16. | ||
// | ||
|
||
import Foundation | ||
|
||
@_spi(STP) public struct BillingAddress: Encodable { | ||
let name: String? | ||
let line1: String? | ||
let line2: String? | ||
let city: String? | ||
let state: String? | ||
let postalCode: String? | ||
let countryCode: String? | ||
|
||
@_spi(STP) public init( | ||
name: String? = nil, | ||
line1: String? = nil, | ||
line2: String? = nil, | ||
city: String? = nil, | ||
state: String? = nil, | ||
postalCode: String? = nil, | ||
countryCode: String? = nil | ||
) { | ||
self.name = name | ||
self.line1 = line1 | ||
self.line2 = line2 | ||
self.city = city | ||
self.state = state | ||
self.postalCode = postalCode | ||
self.countryCode = countryCode | ||
} | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case name | ||
case line1 = "line_1" | ||
case line2 = "line_2" | ||
case city = "locality" | ||
case state = "administrative_area" | ||
case postalCode = "postal_code" | ||
case countryCode = "country_code" | ||
} | ||
|
||
// Custom encoder to only encode non-nil & non-empty properties. | ||
@_spi(STP) public func encode(to encoder: Encoder) throws { | ||
var container = encoder.container(keyedBy: CodingKeys.self) | ||
if let name, !name.isEmpty { try container.encode(name, forKey: .name) } | ||
if let line1, !line1.isEmpty { try container.encode(line1, forKey: .line1) } | ||
if let line2, !line2.isEmpty { try container.encode(line2, forKey: .line2) } | ||
if let city, !city.isEmpty { try container.encode(city, forKey: .city) } | ||
if let state, !state.isEmpty { try container.encode(state, forKey: .state) } | ||
if let postalCode, !postalCode.isEmpty { try container.encode(postalCode, forKey: .postalCode) } | ||
if let countryCode, !countryCode.isEmpty { try container.encode(countryCode, forKey: .countryCode) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,10 @@ import Foundation | |
@_spi(STP) import StripeCore | ||
|
||
final class FinancialConnectionsAPIClient { | ||
private enum EncodingError: Error { | ||
case cannotCastToDictionary | ||
} | ||
|
||
let backingAPIClient: STPAPIClient | ||
|
||
var isLinkWithStripe: Bool = false | ||
|
@@ -74,6 +78,17 @@ final class FinancialConnectionsAPIClient { | |
} | ||
return promise | ||
} | ||
|
||
static func encodeAsParameters(_ value: any Encodable) throws -> [String: Any] { | ||
let jsonData = try JSONEncoder().encode(value) | ||
let jsonObject = try JSONSerialization.jsonObject(with: jsonData) | ||
|
||
if let dictionary = jsonObject as? [String: Any] { | ||
return dictionary | ||
} else { | ||
throw EncodingError.cannotCastToDictionary | ||
} | ||
} | ||
} | ||
|
||
protocol FinancialConnectionsAPI { | ||
|
@@ -230,7 +245,9 @@ protocol FinancialConnectionsAPI { | |
|
||
func paymentDetails( | ||
consumerSessionClientSecret: String, | ||
bankAccountId: String | ||
bankAccountId: String, | ||
billingAddress: BillingAddress?, | ||
billingEmail: String? | ||
) -> Future<FinancialConnectionsPaymentDetails> | ||
|
||
func sharePaymentDetails( | ||
|
@@ -967,9 +984,11 @@ extension FinancialConnectionsAPIClient: FinancialConnectionsAPI { | |
|
||
func paymentDetails( | ||
consumerSessionClientSecret: String, | ||
bankAccountId: String | ||
bankAccountId: String, | ||
billingAddress: BillingAddress?, | ||
billingEmail: String? | ||
) -> Future<FinancialConnectionsPaymentDetails> { | ||
let parameters: [String: Any] = [ | ||
var parameters: [String: Any] = [ | ||
"request_surface": requestSurface, | ||
"credentials": [ | ||
"consumer_session_client_secret": consumerSessionClientSecret | ||
|
@@ -979,6 +998,22 @@ extension FinancialConnectionsAPIClient: FinancialConnectionsAPI { | |
], | ||
"type": "bank_account", | ||
] | ||
|
||
if let billingAddress { | ||
do { | ||
let encodedBillingAddress = try Self.encodeAsParameters(billingAddress) | ||
parameters["billing_address"] = encodedBillingAddress | ||
} catch let error { | ||
let promise = Promise<FinancialConnectionsPaymentDetails>() | ||
promise.reject(with: error) | ||
return promise | ||
} | ||
} | ||
|
||
if let billingEmail, !billingEmail.isEmpty { | ||
parameters["billing_email_address"] = billingEmail | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
return post( | ||
resource: APIEndpointPaymentDetails, | ||
parameters: parameters, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1765,8 +1765,7 @@ class PaymentSheetFormFactoryTest: XCTestCase { | |
XCTAssertEqual(instantDebitsSection.defaultEmail, "[email protected]") | ||
XCTAssertEqual(instantDebitsSection.phone, "+12345678900") | ||
XCTAssertEqual(instantDebitsSection.defaultPhone, "+12345678900") | ||
// Unlike the other fields, the `address` will not fallback to the default. | ||
XCTAssertEqual(instantDebitsSection.address, PaymentSheet.Address()) | ||
XCTAssertEqual(instantDebitsSection.address, defaultAddress) | ||
XCTAssertEqual(instantDebitsSection.defaultAddress, defaultAddress) | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Source: https://stripe.sourcegraphcloud.com/stripe-internal/pay-server/-/blob/lib/consumer/api/params/address.rb?L6:18-6:25