Skip to content
Merged
Changes from 2 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
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,50 @@ let paypalButtonView = PayPalButton(
}
```

## Card Fields

The Braintree iOS SDK provides a `CardFields` view that renders a complete card entry form with fields for card number, expiration date, and CVV. It handles input validation, card brand detection, and focus advancement between fields automatically.

*Note:* Ensure you include the `BraintreeUIComponents` module in your project to use this feature.

To integrate `CardFields` into your checkout view:

```swift
import BraintreeCard
import BraintreeUIComponents

struct CheckoutView: View {
@State private var isFormValid = false
@State private var submit: (() -> Void)?

var body: some View {
VStack {
CardFields(
authorization: "<YOUR_TOKENIZATION_KEY_OR_CLIENT_TOKEN>",
card: BTCard()
) { nonce, error in
if let nonce {
// send nonce.nonce to your server to complete the transaction
} else if let error {
// handle card tokenization error
}
}
.onValidityChange { isValid, tokenize in
isFormValid = isValid
submit = tokenize
}

Button("Pay") {
submit?()
}
.disabled(!isFormValid)
}
}
}
```

The `onValidityChange` modifier delivers the form's validity state and a `submit` closure whenever validity changes. Use `isValid` to enable or disable your submit button, then call `submit` when the user taps it to tokenize the card and receive a nonce in the completion handler.
Comment thread
buzzamus marked this conversation as resolved.
Outdated

## Contributing

We welcome PRs to this repo. See our [development doc](https://github.com/braintree/braintree_ios/blob/main/DEVELOPMENT.md).
Expand Down
Loading