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

[V7] Update BTCard #1443

Merged
merged 31 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
096741e
Include all properties in public init
richherrera Oct 22, 2024
d4db0c9
Make all properties internal
richherrera Oct 22, 2024
56f49c8
Update BTCard tests
richherrera Oct 22, 2024
862763a
Update BTVardClient tests
richherrera Oct 22, 2024
2aa76c8
Update Integration tests
richherrera Oct 22, 2024
bab98ba
Update CardHelper newCard method
richherrera Oct 22, 2024
54a08af
Update demo app Amex View Controller
richherrera Oct 22, 2024
5cd4420
Update CHANGELOG
richherrera Oct 22, 2024
36dd53f
Update V7 readme
richherrera Oct 22, 2024
0e4df32
Move property docstrings to the init method
richherrera Oct 22, 2024
8724b64
Add optional on postalCode docstring
richherrera Oct 23, 2024
f0351a3
Merge branch 'v7' into update-btcard-parameters
richherrera Oct 23, 2024
6b1c65d
Fix code snippet
richherrera Oct 23, 2024
7f6c766
Merge branch 'v7' into update-btcard-parameters
richherrera Oct 23, 2024
bc42546
Add the missing commas in the documentation example
richherrera Oct 23, 2024
618dc37
Remove optional for required properties, change boolean to let
richherrera Oct 29, 2024
d62f43d
Make return optional for static method card helper
richherrera Oct 29, 2024
727ce54
Add message when user uses optional card helper method
richherrera Oct 29, 2024
c96278d
Fix BTCardTests
richherrera Oct 29, 2024
f4628db
Fix BTCardClient tests
richherrera Oct 29, 2024
a578f4a
Fix BTCardClient integration tests
richherrera Oct 29, 2024
c127063
Remove unnecessary code sample
richherrera Oct 29, 2024
dfb1c5e
Address PR feedback
richherrera Oct 30, 2024
8d74df5
Merge branch 'v7' into update-btcard-parameters
richherrera Nov 6, 2024
759bfc6
Remove cvv note
richherrera Nov 6, 2024
ecd23fc
Merge branch 'v7' into update-btcard-parameters
richherrera Nov 8, 2024
bb9cccb
Merge branch 'v7' into update-btcard-parameters
richherrera Nov 14, 2024
b9744d3
Add init with cvv
richherrera Nov 14, 2024
8e192df
Update amex integration test
richherrera Nov 14, 2024
6ae1adb
Update docstring and empty validation
richherrera Nov 19, 2024
65cadd5
Update UTs
richherrera Nov 19, 2024
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* Bump minimum supported deployment target to iOS 16+
* BraintreeVenmo
* Update `BTVenmoRequest` to make all properties accessible on the initializer only vs via the dot syntax.
* BraintreeCard
* Update `BTCard` to make all properties accessible on the initializer only vs via the dot syntax.
* BraintreeSEPADirectDebit
* Update `BTSEPADirectDebitRequest` to make all properties accessible on the initializer only vs via the dot syntax.

Expand Down
11 changes: 6 additions & 5 deletions Demo/Application/Features/AmexViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ class AmexViewController: PaymentButtonBaseViewController {
}

private func getRewards(for cardNumber: String) {
let card = BTCard()
card.number = cardNumber
card.expirationMonth = "12"
card.expirationYear = CardHelpers.generateFuture(.year)
card.cvv = "1234"
let card = BTCard(
number: cardNumber,
expirationMonth: "12",
expirationYear: CardHelpers.generateFuture(.year),
cvv: "1234"
)

progressBlock("Tokenizing Card")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ class CardTokenizationViewController: PaymentButtonBaseViewController {
@objc func tappedSubmit() {
progressBlock("Tokenizing card details!")

guard let card = CardHelpers.newCard(from: cardFormView) else {
progressBlock("Fill in all the card fields.")
return
}
let cardClient = BTCardClient(apiClient: apiClient)
let card = CardHelpers.newCard(from: cardFormView)

setFieldsEnabled(false)
cardClient.tokenize(card) { nonce, error in
Expand Down
34 changes: 14 additions & 20 deletions Demo/Application/Features/Helpers/CardHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,20 @@ enum Format {

enum CardHelpers {

static func newCard(from cardFormView: BTCardFormView) -> BTCard {
let card = BTCard()

if let cardNumber = cardFormView.cardNumber {
card.number = cardNumber
}

if let expirationYear = cardFormView.expirationYear {
card.expirationYear = expirationYear
}

if let expirationMonth = cardFormView.expirationMonth {
card.expirationMonth = expirationMonth
}

if let cvv = cardFormView.cvv {
card.cvv = cvv
}

return card
static func newCard(from cardFormView: BTCardFormView) -> BTCard? {
guard
let cardNumber = cardFormView.cardNumber,
let expirationMonth = cardFormView.expirationMonth,
let expirationYear = cardFormView.expirationYear,
let cvv = cardFormView.cvv
else { return nil}
richherrera marked this conversation as resolved.
Show resolved Hide resolved

return .init(
richherrera marked this conversation as resolved.
Show resolved Hide resolved
number: cardNumber,
expirationMonth: expirationMonth,
expirationYear: expirationYear,
cvv: cvv
)
}

static func generateFuture(_ format: Format) -> String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ class ThreeDSecureViewController: PaymentButtonBaseViewController {
callbackCount = 0
updateCallbackCount()

let card = CardHelpers.newCard(from: cardFormView)
guard let card = CardHelpers.newCard(from: cardFormView) else {
progressBlock("Fill in all the card fields.")
return
}
let cardClient = BTCardClient(apiClient: apiClient)

cardClient.tokenize(card) { tokenizedCard, error in
Expand Down
102 changes: 46 additions & 56 deletions IntegrationTests/BTCardClient_IntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ class BTCardClient_IntegrationTests: XCTestCase {
let apiClient = BTAPIClient(authorization: BTIntegrationTestsConstants.sandboxTokenizationKey)!
let cardClient = BTCardClient(apiClient: apiClient)
let expectation = expectation(description: "Tokenize card")

cardClient.tokenize(invalidCard()) { tokenizedCard, error in
let card = BTCard(
number: "123123",
expirationMonth: "XX",
expirationYear: "XXXX",
cvv: "1234"
)

cardClient.tokenize(card) { tokenizedCard, error in
guard let tokenizedCard else {
XCTFail("Expect a nonce to be returned")
return
Expand All @@ -27,11 +33,13 @@ class BTCardClient_IntegrationTests: XCTestCase {
func testTokenizeCard_whenCardIsInvalidAndValidationIsEnabled_failsWithExpectedValidationError() {
let apiClient = BTAPIClient(authorization: BTIntegrationTestsConstants.sandboxClientToken)!
let cardClient = BTCardClient(apiClient: apiClient)
let card = BTCard()
card.number = "123"
card.expirationMonth = "12"
card.expirationYear = Helpers.shared.futureYear()
card.shouldValidate = true
let card = BTCard(
number: "123",
expirationMonth: "12",
expirationYear: Helpers.shared.futureYear(),
cvv: "1234",
shouldValidate: true
)

let expectation = expectation(description: "Tokenize card")

Expand All @@ -56,8 +64,15 @@ class BTCardClient_IntegrationTests: XCTestCase {
let apiClient = BTAPIClient(authorization: BTIntegrationTestsConstants.sandboxTokenizationKey)!
let cardClient = BTCardClient(apiClient: apiClient)
let expectation = expectation(description: "Tokenize card")

cardClient.tokenize(validCard()) { tokenizedCard, error in
let card = BTCard(
number: "123",
expirationMonth: "12",
expirationYear: Helpers.shared.futureYear(),
cvv: "1234",
cardholderName: "Cookie Monster"
)

cardClient.tokenize(card) { tokenizedCard, error in
guard let tokenizedCard else {
XCTFail("Expect a nonce to be returned")
return
Expand Down Expand Up @@ -89,8 +104,13 @@ class BTCardClient_IntegrationTests: XCTestCase {
func testTokenizeCard_whenUsingTokenizationKeyAndCardHasValidationEnabled_failsWithAuthorizationError() {
let apiClient = BTAPIClient(authorization: BTIntegrationTestsConstants.sandboxTokenizationKey)!
let cardClient = BTCardClient(apiClient: apiClient)
let card = invalidCard()
card.shouldValidate = true
let card = BTCard(
number: "123123",
expirationMonth: "XX",
expirationYear: "XXXX",
cvv: "1234",
shouldValidate: true
)

let expectation = expectation(description: "Tokenize card")
cardClient.tokenize(card) { tokenizedCard, error in
Expand All @@ -114,8 +134,14 @@ class BTCardClient_IntegrationTests: XCTestCase {
func testTokenizeCard_whenUsingClientTokenAndCardHasValidationEnabledAndCardIsValid_tokenizesSuccessfully() {
let apiClient = BTAPIClient(authorization: BTIntegrationTestsConstants.sandboxClientToken)!
let cardClient = BTCardClient(apiClient: apiClient)
let card = validCard()
card.shouldValidate = true
let card = BTCard(
number: "4111111111111111",
expirationMonth: "12",
expirationYear: Helpers.shared.futureYear(),
cvv: "123",
cardholderName: "Cookie Monster",
shouldValidate: true
)

let expectation = expectation(description: "Tokenize card")

Expand All @@ -137,8 +163,13 @@ class BTCardClient_IntegrationTests: XCTestCase {
func testTokenizeCard_whenUsingVersionThreeClientTokenAndCardHasValidationEnabledAndCardIsValid_tokenizesSuccessfully() {
let apiClient = BTAPIClient(authorization: BTIntegrationTestsConstants.sandboxClientTokenVersion3)!
let cardClient = BTCardClient(apiClient: apiClient)
let card = validCard()
card.shouldValidate = true
let card = BTCard(
number: "4111111111111111",
expirationMonth: "12",
expirationYear: Helpers.shared.futureYear(),
cvv: "123",
shouldValidate: true
)

let expectation = expectation(description: "Tokenize card")

Expand All @@ -156,45 +187,4 @@ class BTCardClient_IntegrationTests: XCTestCase {

waitForExpectations(timeout: 5)
}

func testTokenizeCard_withCVVOnly_tokenizesSuccessfully() {
let apiClient = BTAPIClient(authorization: BTIntegrationTestsConstants.sandboxClientTokenVersion3)!
let cardClient = BTCardClient(apiClient: apiClient)
let card = BTCard()
card.cvv = "123"

let expectation = expectation(description: "Tokenize card")

cardClient.tokenize(card) { tokenizedCard, error in
guard let tokenizedCard else {
XCTFail("Expect a nonce to be returned")
return
}

XCTAssertTrue(tokenizedCard.nonce.isValidNonce)
XCTAssertNil(error)
expectation.fulfill()
}

waitForExpectations(timeout: 5)
}

// MARK: - Private Helper Methods

func invalidCard() -> BTCard {
let card = BTCard()
card.number = "123123"
card.expirationMonth = "XX"
card.expirationYear = "XXXX"
return card
}

func validCard() -> BTCard {
let card = BTCard()
card.number = "4111111111111111"
card.expirationMonth = "12"
card.expirationYear = Helpers.shared.futureYear()
card.cardholderName = "Cookie Monster"
return card
}
}
Loading