Skip to content

Commit

Permalink
adding phoneNumberForDisplay
Browse files Browse the repository at this point in the history
  • Loading branch information
wooj-stripe committed Jan 12, 2024
1 parent 13de200 commit 04630b0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ struct BillingDetailsView: View {
if let email = billingDetails.email {
Text(email)
}
if let phone = billingDetails.phone {
if let phone = billingDetails.phoneNumberForDisplay {
Text(phone)
}
if let line1 = billingDetails.address.line1 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import Foundation
import PassKit
@_spi(STP) import StripeCore
@_spi(STP) import StripeUICore
@_spi(STP) import StripePaymentsUI
import UIKit

Expand Down Expand Up @@ -342,9 +343,18 @@ extension PaymentSheet {
/// - Note: When used with defaultBillingDetails, the value set is displayed in the payment sheet as-is. Depending on the payment method, the customer may be required to edit this value.
public var name: String?

/// The customer's phone number without formatting (e.g. +15551234567)
/// The customer's phone number in e164 formatting (e.g. +15551234567)
/// - Note: Not passing in a '+' will assume a US based phone number
public var phone: String?

/// The customer's phone number used for displaying in your UI (e.g. +1 (555) 555-5555)
public var phoneNumberForDisplay: String? {
guard let phone = self.phone else {
return nil
}
return PhoneNumber.fromE164(phone)?.string(as: .international)
}

/// Initializes billing details
public init(address: PaymentSheet.Address = Address(), email: String? = nil, name: String? = nil, phone: String? = nil) {
self.address = address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class PaymentSheetConfigurationTests: XCTestCase {
XCTAssertEqual(psBillingDetails.name, "Jane Doe")
XCTAssertEqual(psBillingDetails.email, "janedoe@test.com")
XCTAssertEqual(psBillingDetails.phone, "+18885551234")
XCTAssertEqual(psBillingDetails.phoneNumberForDisplay, "+1 (888) 555-1234")
XCTAssertEqual(psBillingDetails.address.line1, "123 Main Street")
XCTAssertEqual(psBillingDetails.address.line2, "")
XCTAssertEqual(psBillingDetails.address.city, "San Francisco")
Expand Down

0 comments on commit 04630b0

Please sign in to comment.