@cardknox/angular-ifields
v1.2.621
Published
An Angular component for Cardknox iFields
Downloads
56
Readme
angular-cardknox-ifields
An Angular component for Cardknox iFields
Cardknox
Cardknox is a developer-friendly payment gateway integration provider for in-store, online, or mobile transactions
Sandbox: https://www.cardknox.com/sandbox/
iFields: https://www.cardknox.com/ifields/
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 iFields supports:
- Credit Card
- CVV
- ACH
<cardknox-ifields [type]="CARD"></cardknox-ifields>
The possible values for this property are
- card
- cvv
- ach
These can be imported from the component
import { ACH_TYPE, CARD_TYPE, CVV_TYPE, AngularIfieldsComponent } from '@cardknox/angular-ifields';
/**...*/
CARD = CARD_TYPE;
2. Account
Pass your iFields key to the component in the account input like this:
<cardknox-ifields [account]="account"></cardknox-ifields>
/**...*/
account = {
xKey: '{Your iFields key}',
xSoftwareName: '{The name of your app}',
xSoftwareVersion: '{Your app's version}'
}
Events
There are 2 lifecycle events and 7 user events.
Lifecycle events
1. Load
Is emitted when the iframe has loaded
<cardknox-ifields (load)="onLoad"></cardknox-ifields>
2. Token
Is emitted when a token is received from the iField
<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
- click
- dblclick
- focus
- blur
- input
- change
- 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:
<cardknox-ifields (update)="onUpdate($event)"></cardknox-ifields>
/**...*/
onUpdate({ data }) {
switch (data.event) {
case 'input':
console.log("input event received");
break;
case 'click':
console.log("click event received");
break;
}
}
Submit
This event is triggered when the user submits the form from within the iFrame.
This event works differently than 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).
<form id="form">
<cardknox-ifields [options]="options" (submit)="onSubmit"></cardknox-ifields>
</form>
/**...*/
onSubmit() {
document.getElementById('form').dispatchEvent(
new Event("submit", {
bubbles: true,
cancelable: true
})
);
}
options = {
autoSubmit: true
}
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.
<form id="form">
<cardknox-ifields [options]="options"></cardknox-ifields>
</form>
/**...*/
options = {
autoSubmit: true,
autoSubmitFormId: 'form'
}
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.
<cardknox-ifields #card></cardknox-ifields>
@ViewChild('card') cardIfield?: AngularIfieldsComponent;
this.cardIfield.focusIfield();
this.cardIfield.clearIfield();
this.cardIfield.getToken();
Inputs
Account
Options
ThreeDS
Update Event Data
Error Data
iFields Version: 2.6.2006.0102