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

[WIP] feat: Address Element 🏘 #1169

Merged
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
279 changes: 279 additions & 0 deletions AddressSheetUtilsTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,279 @@
//
// AddressSheetUtilsTests.swift
// stripe-react-native-Unit-Tests
//
// Created by Charles Cruzan on 10/13/22.
//

import XCTest
@testable import stripe_react_native
import Stripe

class AddressSheetUtilsTests: XCTestCase {
let testCity = "testCity"
let testCountry = "testCountry"
let testLine1 = "testLine1"
let testLine2 = "testLine2"
let testPostalCode = "testPostalCode"
let testState = "testState"
let testName = "testName"
let testPhone = "testPhone"

func test_buildDefaultValues_whenPassedNil() throws {
let result = AddressSheetUtils.buildDefaultValues(params: nil)
XCTAssertEqual(
result.address, PaymentSheet.Address()
)
XCTAssertEqual(
result.name, nil
)
XCTAssertEqual(
result.phone, nil
)
XCTAssertEqual(
result.isCheckboxSelected, nil
)
}

func test_buildDefaultValues_whenPassedValues() throws {
let result = AddressSheetUtils.buildDefaultValues(
params: ["name": testName,
"phone": testPhone,
"address": ["city": testCity],
"isCheckboxSelected": true]
)
XCTAssertEqual(
result.address.city, testCity
)
XCTAssertEqual(
result.name, testName
)
XCTAssertEqual(
result.phone, testPhone
)
XCTAssertEqual(
result.isCheckboxSelected, true
)
}

func test_buildAddressDetails_whenPassedNil() throws {
let result = AddressSheetUtils.buildAddressDetails(params: nil)
XCTAssertEqual(
result.address.country, ""
)
XCTAssertEqual(
result.address.line1, ""
)
XCTAssertEqual(
result.name, nil
)
XCTAssertEqual(
result.phone, nil
)
XCTAssertEqual(
result.isCheckboxSelected, nil
)
}

func test_buildAddressDetails_whenPassedValues() throws {
let result = AddressSheetUtils.buildAddressDetails(
params: ["name": testName,
"phone": testPhone,
"address": ["city": testCity],
"isCheckboxSelected": true]
)

XCTAssertEqual(
result.address.city, testCity
)
XCTAssertEqual(
result.address.line1, ""
)
XCTAssertEqual(
result.name, testName
)
XCTAssertEqual(
result.phone, testPhone
)
XCTAssertEqual(
result.isCheckboxSelected, true
)
}

func test_buildAddress_forPaymentSheet_whenPassedNil() throws {
let result: PaymentSheet.Address = AddressSheetUtils.buildAddress(params: nil)

XCTAssertEqual(
result.city, nil
)
XCTAssertEqual(
result.line1, nil
)
XCTAssertEqual(
result.line2, nil
)
XCTAssertEqual(
result.country, nil
)
XCTAssertEqual(
result.postalCode, nil
)
XCTAssertEqual(
result.state, nil
)
}

func test_buildAddress_forPaymentSheet_whenPassedValues() throws {
let result: PaymentSheet.Address = AddressSheetUtils.buildAddress(
params: ["city": testCity, "country": testCountry, "line1": testLine1, "line2": testLine2, "postalCode": testPostalCode, "state": testState]
)

XCTAssertEqual(
result.city, testCity
)
XCTAssertEqual(
result.line1, testLine1
)
XCTAssertEqual(
result.line2, testLine2
)
XCTAssertEqual(
result.country, testCountry
)
XCTAssertEqual(
result.postalCode, testPostalCode
)
XCTAssertEqual(
result.state, testState
)
}

func test_buildAddress_forAddressViewController_whenPassedNil() throws {
let result: AddressViewController.AddressDetails.Address = AddressSheetUtils.buildAddress(params: nil)

XCTAssertEqual(
result.city, nil
)
XCTAssertEqual(
result.line1, ""
)
XCTAssertEqual(
result.line2, nil
)
XCTAssertEqual(
result.country, ""
)
XCTAssertEqual(
result.postalCode, nil
)
XCTAssertEqual(
result.state, nil
)
}

func test_buildAddress_forAddressViewController_whenPassedValues() throws {
let result: AddressViewController.AddressDetails.Address = AddressSheetUtils.buildAddress(
params: ["city": testCity, "country": testCountry, "line1": testLine1, "line2": testLine2, "postalCode": testPostalCode, "state": testState]
)

XCTAssertEqual(
result.city, testCity
)
XCTAssertEqual(
result.line1, testLine1
)
XCTAssertEqual(
result.line2, testLine2
)
XCTAssertEqual(
result.country, testCountry
)
XCTAssertEqual(
result.postalCode, testPostalCode
)
XCTAssertEqual(
result.state, testState
)
}

func test_buildAdditionalFieldsConfiguration_whenPassedNil() throws {
let result = AddressSheetUtils.buildAdditionalFieldsConfiguration(params: nil)

XCTAssertEqual(
result.phone, .hidden
)
XCTAssertEqual(
result.name, .required
)
XCTAssertEqual(
result.checkboxLabel, nil
)
}

func test_buildAdditionalFieldsConfiguration_whenPassedValues() throws {
let testCheckboxLabel = "testCheckboxLabel"
let result = AddressSheetUtils.buildAdditionalFieldsConfiguration(
params: ["name": "hidden", "phoneNumber": "optional", "checkboxLabel": testCheckboxLabel]
)

XCTAssertEqual(
result.phone, .optional
)
XCTAssertEqual(
result.name, .hidden
)
XCTAssertEqual(
result.checkboxLabel, testCheckboxLabel
)
}

func test_getFieldConfiguration() throws {
XCTAssertEqual(
AddressSheetUtils.getFieldConfiguration(input: nil, default: .hidden), .hidden
)

XCTAssertEqual(
AddressSheetUtils.getFieldConfiguration(input: "optional", default: .hidden), .optional
)

XCTAssertEqual(
AddressSheetUtils.getFieldConfiguration(input: "required", default: .hidden), .required
)

XCTAssertEqual(
AddressSheetUtils.getFieldConfiguration(input: "hidden", default: .hidden), .hidden
)

XCTAssertEqual(
AddressSheetUtils.getFieldConfiguration(input: "hidden", default: .optional), .hidden
)
}

func test_buildResult() throws {
let input = AddressViewController.AddressDetails(
address: AddressViewController.AddressDetails.Address(
city: testCity, country: testCountry, line1: testLine1, line2: testLine2, postalCode: testPostalCode, state: testState
),
name: testName,
phone: testPhone,
isCheckboxSelected: true
)

XCTAssertEqual(
AddressSheetUtils.buildResult(address: input) as NSDictionary,
[
"name": testName,
"phone": testPhone,
"isCheckboxSelected": true,
"address": [
"city": testCity,
"country": testCountry,
"line1": testLine1,
"line2": testLine2,
"postalCode": testPostalCode,
"state": testState
]
] as NSDictionary
)
}
}
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

### New features

- Added the `<AddressSheet />` component, which enables you to collect local and international shipping or billing addresses from your customers _with_ address autocomplete. [#1169](https://github.com/stripe/stripe-react-native/pull/1169)
- Added the `defaultShippingDetails` field to the `params` argument in `initPaymentSheet(params)`. This will allow you to collect shipping details (either in your own UI or using the new `<AddressSheet />` component) for payments in the Payment Sheet. [#1169](https://github.com/stripe/stripe-react-native/pull/1169)

## Fixes

- Fixed an issue on iOS where `confirmSetupIntent` would throw an error if the `Card` payment method was provided with the `paymentMethodId` parameter. [#1151](https://github.com/stripe/stripe-react-native/pull/1151)
Expand Down
8 changes: 6 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,12 @@ dependencies {
implementation 'com.github.bumptech.glide:glide:4.12.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.1"
implementation "com.stripe:stripe-android:$stripe_version"
implementation "com.stripe:financial-connections:$stripe_version"
implementation ('com.github.stripe:stripe-android:address-element-private-beta-SNAPSHOT') {
exclude group: 'com.github.stripe.stripe-android', module: 'stripecardscan-tflite'
exclude group: 'com.github.stripe.stripe-android', module: 'stripecardscan'
}

// implementation "com.stripe:financial-connections:$stripe_version"
Comment on lines +138 to +143
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: revert

implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
Expand Down
Loading