Skip to content

Commit

Permalink
feat: add get token service to ios sdk (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
lcschy authored Feb 17, 2023
1 parent ddb38d8 commit 6150d11
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 10 deletions.
6 changes: 1 addition & 5 deletions docs/concepts/elements.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ data directly within your application code.
Using one of our [SDKs](#elements-sdks), sensitive data can be securely retrieved and applied to one or more Elements within your UI.
The SDK will manage encapsulating the sensitive data so that your application can reference these value without having direct access to it.

To get started revealing sensitive data to your users, check out our guides:

- [Reveal Data on Web](/docs/sdks/web/javascript/methods#detokenization)
- [Reveal Data on Android](/docs/sdks/mobile/android/services#gettoken)
- [Reveal Data on iOS](/docs/sdks/mobile/ios/services#proxy)
To get started revealing sensitive data to your users, check out our [Reveal Tokenized Data](/docs/guides/share/reveal-tokenized-data) guide.

## Elements SDKs

Expand Down
32 changes: 32 additions & 0 deletions docs/sdks/mobile/ios/services.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,38 @@ BasisTheoryElements.createSession(

The callback provided calls your function with a `data` of type [CreateSessionResponse](https://github.com/Basis-Theory/basistheory-swift/blob/master/docs/CreateSessionResponse.md), and an `error` of type [Error](#errors).

### getTokenById

This function wraps the [get a token API endpoint](/docs/api/tokens/#get-a-token) to retrieve a single strongly typed token.
The token's data is transformed to value references which you can use to [set the value](/docs/sdks/mobile/ios/types#methods) of your elements without touching
the plaintext value and pulling your application into compliance scope.

```swift showLineNumbers
BasisTheoryElements.getTokenById(
id: "<YOUR TOKEN ID>",
apiKey: "<YOUR API KEY>",
) { data, error in ... }
```

The callback provided calls your function with a:
* `error` of type [Error](#errors)
* `data` of type `JSON` - `JSON` is a data structure that has dynamic member lookup capabilities. This allows you to traverse a `token` without giving you access to read any sensitive values in `token.data` which means you stay compliant.

To show a value from the token `data`, traverse the JSON using dot or bracket notation and retrieve the value using the `elementValueReference` property.
Below is an example of how you do that and set the value reference into a Text Element.

```swift showLineNumbers
@IBOutlet private weak var myTextElement: TextElementUITextField!
...

BasisTheoryElements.getTokenById(
id: "<YOUR TOKEN ID>",
apiKey: "<YOUR API KEY>",
) { data, error in
myTextElement.setValue(elementValueReference: data!.data!.nested!.property!.elementValueReference)
}
```

### proxy

Proxy provides a simple way to retrieve data back into an element utilizing our [proxy](/docs/api/proxies) service. To accomplish this, simply construct your `proxy` request like this:
Expand Down
44 changes: 39 additions & 5 deletions docs/sdks/mobile/ios/types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Combine
class TokenizeName: UIViewController {
@IBOutlet weak var nameTextField: TextElementUITextField!
@IBOutlet weak var output: UITextView!

@IBAction func tokenize(_ sender: Any) {
let body: [String: Any] = [
"data": [
Expand All @@ -45,11 +45,27 @@ class TokenizeName: UIViewController {
}
```

| Configuration | Defaults |
| --- | --- |
### Configuration

The `TextElementUITextField` extends the native `UITextField` from UIKit, so all standard properties and attributes supported by `UITextField` are supported by `TextElementUITextField`.

#### Properties

The following additional properties are supported when programmatically interacting with a `TextElementUITextField`:

| Name | Type |
| ---------- | --- |
| validation | No default validation. Always valid in [ElementEvent](/docs/sdks/mobile/ios/events#elementevent). |
| mask | No default [mask](/docs/sdks/mobile/ios/options#mask). [Mask](/docs/sdks/mobile/ios/options#mask) can be overridden. |
| transform | No default [transform](/docs/sdks/mobile/ios/options#transform). [Transform](/docs/sdks/mobile/ios/options#transform) can be overriden. |
| mask | No default [mask](/docs/sdks/mobile/ios/options#mask). [Mask](/docs/sdks/mobile/ios/options#mask) can be overridden. |
| transform | No default [transform](/docs/sdks/mobile/ios/options#transform). [Transform](/docs/sdks/mobile/ios/options#transform) can be overriden. |

#### Methods

| Signature | Description |
|----------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `setValue(elementValueReference: ElementValueReference)` | Sets the element's text to the value referenced by the provided ElementValueReference. |
| `setValueRef(element: TextElementUITextField)` | Binds the provided `element: TextElementUITextField` instance as a value source for this element, keeping the value of this element in sync with any changes made to the other element. |


## CardNumberUITextField

Expand Down Expand Up @@ -89,6 +105,12 @@ class TokenizeCardNumber: UIViewController {
}
```

### Configuration

The `CardNumberUITextField` element type extends the `TextElementUITextField` class, so all properties and attributes supported by `TextElementUITextField` are also supported here.

By default, this element is configured with:

| Configuration | Defaults |
| --- | --- |
| validation | Input must be Luhn valid and be an acceptable length for the card brand. |
Expand Down Expand Up @@ -143,6 +165,12 @@ class TokenizeCardExpirationDate: UIViewController {
}
```

### Configuration

The `CardExpirationDateUITextField` element type extends the `TextElementUITextField` class, so all properties and attributes supported by `TextElementUITextField` are also supported here.

By default, this element is configured with:

| Configuration | Defaults |
| --- | --- |
| validation | Input must be the current month and year or later. |
Expand Down Expand Up @@ -203,6 +231,12 @@ class TokenizeCVC: UIViewController {
}
```

### Configuration

The `CardVerificationCodeUITextField` element type extends the `TextElementUITextField` class, so all properties and attributes supported by `TextElementUITextField` are also supported here.

By default, this element is configured with:

| Configuration | Defaults |
| --- | --- |
| validation | No default validation. Always valid in [ElementEvent](/docs/sdks/mobile/ios/events#elementevent). |
Expand Down

1 comment on commit 6150d11

@vercel
Copy link

@vercel vercel bot commented on 6150d11 Feb 17, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.