Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

ENG-1858 - feat: refer to new Elements consolidated interfaces #135

Merged
merged 2 commits into from
Dec 28, 2021
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
2 changes: 1 addition & 1 deletion source/includes/elements/_element_mask.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Element Mask

```jsx
var phoneNumberElement = BasisTheory.elements.create('text', {
var phoneNumberElement = BasisTheory.createElement('text', {
targetId: 'myPhoneNumberElement',
mask: ['(', /\d/, /\d/, /\d/, ')', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/]
})
Expand Down
2 changes: 1 addition & 1 deletion source/includes/elements/_element_style.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Element Style

```jsx
var cardElement = BasisTheory.elements.create('card', {
var cardElement = BasisTheory.createElement('card', {
style: {
fonts: [
"https://fonts.googleapis.com/css2?family=Source+Sans+Pro:ital,wght@0,200;0,300;0,400;0,600;0,700;0,900;1,200;1,300;1,400;1,600;1,700;1,900&display=swap"
Expand Down
2 changes: 1 addition & 1 deletion source/includes/elements/_element_transform.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Element Transform

```jsx
var phoneNumberElement = BasisTheory.elements.create('text', {
var phoneNumberElement = BasisTheory.createElement('text', {
targetId: 'myPhoneNumberElement',
mask: ['(', /\d/, /\d/, /\d/, ')', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/],
transform: /[()-]/,
Expand Down
8 changes: 2 additions & 6 deletions source/includes/elements/_elements_instance.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
# Elements Instance

```jsx
BasisTheory.elements
```

After [initialization](#initialize), **Elements** are available through `BasisTheory` instance.

## Create Element

```jsx
var cardElement = BasisTheory.elements.create('card', options);
var cardElement = BasisTheory.createElement('card', options);

var textElement = BasisTheory.elements.create('text', { targetId: 'myInputId' });
var textElement = BasisTheory.createElement('text', { targetId: 'myInputId' });
```

This method returns a new instance of an element type.
Expand Down
18 changes: 7 additions & 11 deletions source/includes/elements/_elements_services.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Elements Services

The following **BasisTheory.js** services are capable of recognizing Elements instances in the payload and securely tokenizing their data directly to Basis Theory vault.

## Atomic Cards

```javascript
BasisTheory.elements.atomicCards.create({
BasisTheory.atomicCards.create({
card: cardElement
}).then((token) => {
console.log(token.id); // token to store
Expand All @@ -15,7 +17,6 @@ Allows secure submission and tokenization of a card element. Returns a `Promise`
See [CardModel](#element-types-card-element) for the resolved value type. The `Promise` will reject with an [error](#elements-services-errors)
if the response status is not in the 2xx range.

Internally, `BasisTheory.elements.atomicCards.create` calls [Create Atomic Card API](/api-reference/#atomic-cards-create-atomic-card).

You can fetch this same data later with [Get an Atomic Card API](/api-reference/#atomic-cards-get-an-atomic-card).

Expand All @@ -26,7 +27,7 @@ You can fetch this same data later with [Get an Atomic Card API](/api-reference/
## Atomic Banks

```javascript
BasisTheory.elements.atomicBanks.create({
BasisTheory.atomicBanks.create({
bank: {
routingNumber: routingNumberElement | 'plainText', // values can be either a TextElement or plain text (see warning).
accountNumber: accountNumberElement | 'plainText',
Expand All @@ -41,7 +42,6 @@ Allows secure submission and tokenization of a bank element. Returns a `Promise`
data. The `Promise` will reject with an [error](#elements-services-errors) if the response status is not in the 2xx
range.

Internally, `BasisTheory.elements.atomicBanks.create` calls [Create Atomic Bank API](/api-reference#atomic-banks-create-atomic-bank).

You can fetch this same data later with [Get an Atomic Bank API](/api-reference#atomic-banks-get-an-atomic-bank).

Expand All @@ -56,7 +56,7 @@ You can fetch this same data later with [Get an Atomic Bank API](/api-reference#
## Tokens

```javascript
BasisTheory.elements.tokens.create({
BasisTheory.tokens.create({
type: 'token',
data: {
sensitiveData: sensitiveDataElement,
Expand All @@ -78,8 +78,6 @@ BasisTheory.elements.tokens.create({
Allows secure submission and tokenization of string data. Returns a `Promise` that resolves to the created token. The
`Promise` will reject with an [error](#elements-services-errors) if the response status is not in the 2xx range.

Internally, `BasisTheory.elements.tokens.create` calls [Create Token API](/api-reference#tokens-create-token).

You can fetch this same data later with [Get a Token API](/api-reference#tokens-get-a-token) or [Get a Decrypted Token API](/api-reference#tokens-get-a-decrypted-token)

<aside class="notice">
Expand All @@ -101,7 +99,7 @@ You can fetch this same data later with [Get a Token API](/api-reference#tokens-
## Tokenize

```javascript
BasisTheory.elements.tokenize.tokenize({
BasisTheory.tokenize.tokenize({
sensitiveData: sensitiveDataElement,
nonSensitiveData: 'plainText', // see warning on plain text data
otherData: {
Expand All @@ -117,8 +115,6 @@ BasisTheory.elements.tokenize.tokenize({
Allows secure submission and tokenization of string data. Returns a `Promise` that resolves to the created tokens. The
`Promise` will reject with an [error](#elements-services-errors) if the response status is not in the 2xx range.

Internally, `BasisTheory.elements.tokenize.tokenize` calls [Tokenize API](/api-reference#tokenize).

You can fetch this same data later with [Get a Token API](/api-reference#tokens-get-a-token) or [Get a Decrypted Token API](/api-reference#tokens-get-a-decrypted-token).

<aside class="notice">
Expand All @@ -137,7 +133,7 @@ You can fetch this same data later with [Get a Token API](/api-reference#tokens-
## Errors

```javascript
BasisTheory.elements.tokens.create(...).catch(error => {
BasisTheory.tokens.create(...).catch(error => {
// handle error
});
```
Expand Down
14 changes: 2 additions & 12 deletions source/includes/elements/_getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,6 @@ The setup above is recommended to avoid errors similar to these:

## Usage with TypeScript

In order to facilitate usage with TypeScript, an optional typings NPM module is available for installation.
Starting at `1.14.0`, [BasisTheory.js](https://www.npmjs.com/package/@basis-theory/basis-theory-js) bundles all TypeScript definitions for Elements features. You don't have to take any extra steps in order to use it.

> NPM

```shell
npm install --save-dev @basis-theory/basis-theory-elements
```

> Yarn

```shell
yarn add @basis-theory/basis-theory-elements --dev
```
If you can't upgrade past `1.13.1`, [Basis Theory Elements](https://www.npmjs.com/package/@basis-theory/basis-theory-elements) offers unmaintained definitions for deprecated Elements features.
6 changes: 3 additions & 3 deletions source/includes/elements/_initialize.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
try {
// global/window variable BasisTheory is an instance, but requires initialization
await BasisTheory.init('test_1234567890', { elements: true });
// use BasisTheory.elements
// use Elements
} catch (e) {
// handle errors that could happen while loading elements script
}
Expand All @@ -27,7 +27,7 @@ import { BasisTheory } from '@basis-theory/basis-theory-js';

// In this context BasisTheory is a class
const bt = await new BasisTheory().init('test_1234567890', { elements: true });
// use bt.elements
// use Elements
```


Expand All @@ -38,7 +38,7 @@ After [installing](#getting-started-install-sdk) **BasisTheory.js**, simply init
</aside>

<aside class="warning">
<span>If you try to call <code>BasisTheory.elements</code> before calling <code>BasisTheory.init</code>, or before its Promise has been fulfilled, you will get an error.</span>
<span>If you try to to use any Elements feature before calling <code>BasisTheory.init</code>, or before its Promise has been fulfilled, you will get an error.</span>
</aside>

<aside class="notice">
Expand Down