Angular iFields

Overview

Our component for the Angular framework simplifies the iFields integration process. This integration allows you to build forms with secure payment fields, giving you the ability to design and customize the look and feel of your payment and checkout flows without having to worry about PCI compliance.
iFields: Fields​
A sandbox or live account is required to use this component.

Inputs

There are 2 basic inputs required to get this up and running:

1. Type

There are three types of payment data that iFields supports:
  • Credit Card
  • CVV
  • ACH
1
<cardknox-ifields [type]="CARD"></cardknox-ifields>
Copied!
The possible values for this property are:
  • card
  • CVV
  • ACH
These can be imported from the component.
1
import { ACH_TYPE, CARD_TYPE, CVV_TYPE, AngularIfieldsComponent } from '@cardknox/angular-ifields';
2
/**...*/
3
CARD = CARD_TYPE;
Copied!

2. Account

Pass your iFields key to the component in the account input like this:
1
<cardknox-ifields [account]="account"></cardknox-ifields>
2
3
/**...*/
4
​
5
account = {
6
xKey: '{Your iFields key}',
7
xSoftwareName: '{The name of your app}',
8
xSoftwareVersion: '{Your app's version}'
9
}
Copied!
Events:
There are 2 lifecycle events and 7 user events.

Lifecycle events

1. Load

Is emitted when the iFrame has loaded.
1 <cardknox-ifields (load)="onLoad"></cardknox-ifields>

2. Token

Is emitted when a token is received from the iField.
1 <cardknox-ifields (token)="onToken"></cardknox-ifields>

User events

User events are events passed along from iFields when the user interacts with it.
The available events are:
  1. 1.
    click
  2. 2.
    dblclick
  3. 3.
    focus
  4. 4.
    blur
  5. 5.
    input
  6. 6.
    change
  7. 7.
    submit*
* the submit event works slightly differently, see below.

Update

Aside from submit, the above events can be collected on a single event update. This is not recommended as it will cause an unnecessary amount of function calls. Instead, subscribe only to the events you want to act on.
The event payload is in e.data. The data also contains the event so you can subscribe to multiple events with a single function and a switch statement, like this:
1
<cardknox-ifields (update)="onUpdate($event)"></cardknox-ifields>
2
​
3
/**...*/
4
​
5
onUpdate({ data }) {
6
switch (data.event) {
7
case 'input':
8
console.log("input event received");
9
break;
10
case 'click':
11
console.log("click event received");
12
break;
13
}
14
}
Copied!

Submit

This event is triggered when the user submits the form from within the iFrame.
This event works differently from other user events.
  • This event is only emitted if prop options.autoSubmit is true. (this is the default).
  • Subscribing to update will not, work as mentioned above.
  • The data passed along with this event is slightly different (see below).
1
<form id="form">
2
<cardknox-ifields [options]="options"></cardknox-ifields>
3
</form>
4
​
5
/**...*/
6
7
options = {
8
autoSubmit: true,
9
autoSubmitFormId: 'form'
10
}
Copied!
It is also possible to have the component automatically submit the form for you when submit is triggered from the iFrame. If autoSubmitFormId is set on the options prop, the component will call submit on the element with that ID. This is useful for smaller applications relying on the form element to handle submission.
1
<form id="form">
2
<cardknox-ifields [options]="options"></cardknox-ifields>
3
</form>
4
​
5
/**...*/
6
7
options = {
8
autoSubmit: true,
9
autoSubmitFormId: 'form'
10
}
Copied!

Error

There is also an error event that can be subscribed to.

Actions

There are 3 actions available on this component as well:

Focus

focusIfield
This action will set the focus to the iField when called.

Clear

clearIfield
This action will clear the data from the iField when called.

Get Token

getToken
This action will load the token for the iField when called.
1
<cardknox-ifields #card></cardknox-ifields>
2
​
3
@ViewChild('card') cardIfield?: AngularIfieldsComponent;
4
​
5
this.cardIfield.focusIfield();
6
this.cardIfield.clearIfield();
7
this.cardIfield.getToken();
Copied!

Inputs

Name
Type
Description
Valid values
type
String
iFields type
  • card
  • cvv
  • ach
account
​Account​
​
​
options
​Options​
​
​
threeDS
​ThreeDS​
​
​
issuer
String
Card issuer
For cvv iField only

Account

Name
Type
Description
xKey
String
iFields key
xSoftwareName
String
Software name
xSoftwareVersion
String
Software version

Options

Name
Type
Description
enableLogging
Boolean
Turn iField logs to the console on and off
autoFormat
Boolean
Turn iField auto-formatting on and off. This is only used for iFields of card type. See autoFormatSeparator
autoFormatSeparator
String
A string to be used to auto-format card numbers when autoFormat is turned on. The default value is " " (space).
autoSubmit
Boolean
Turn on capturing a submit event triggered from within the iFrame. Default is true.
autoSubmitFormId
String
If autoSubmit is true, the ID of a form element can be set and the component will trigger submit on the form when submit is triggered in the iFrame.
placeholder
String
Text to be used as placeholder text for the input field.
iFieldstyle
Object
A style object to be used to style the iFields input element. This object is assigned to HTMLElement.style.

ThreeDS

Name
Type
Description
enable3DS
Boolean
Turn 3DSecure on and off
waitForResponse
Boolean
Determine whether iFields should wait for a response from 3DSecure before getting the token
waitForResponseTimeout
Number
The 3DSecure response timeout in milli-seconds. The default value is 2000 (2 seconds).
amount
Number
The transaction amount
month
Number
The 2-digit card expiration month
year
Number
The 2-digit card expiration year

Update Event Data

Name
Type
Description
enable3DS
Boolean
Turn 3DSecure on and off
waitForResponse
Boolean
Determine whether iFields should wait for a response from 3DSecure before getting the token
waitForResponseTimeout
Number
The 3DSecure response timeout in milli-seconds. The default value is 2000 (2 seconds).
amount
Number
The transaction amount
month
Number
The 2-digit card expiration month
year
Number
The 2-digit card expiration year

Error Data

Name
Type
Description
result
String
This will always have the value of error
errorMessage
String
Contains the error message
xTokenType
String
Either card, cvv, or ach
iFields Version: 2.6.2006.0102​