VGSCollect and States

VGSCollect

An object you use for observing VGSTextField states and send data

Declaration

class VGSCollect

Creating a VGSCollect


/// Initialzation.
///
/// - Parameters:
///   - id: your organization vault id.
///   - environment: your organization vault environment with data region.(e.g. "live", "live-eu1", "sanbox").
///   - hostname: Custom Hostname, if not set, data will be sent to Vault Url
init(id: String, environment: String, hostname: String? = nil)

/// Initialzation.
///
/// - Parameters:
///   - id: your organization vault id.
///   - environment: your organization vault environment. By default `Environment.sandbox`.
///   - dataRegion: id of data storage region (e.g. "eu-123").
///   - hostname: Custom Hostname, if not set, data will be sent to Vault Url
init(id: String, environment: Environment = .sandbox, dataRegion: String? = nil, hostname: String? = nil)

• All VGSCollect instances in the app will be working independently and only with fields that have them in VGSConfiguration settings. • All VGSCollect instances can be configured differently.

VGSCollect instance grab the data from VGSTextFields during sendData(_:) request. By default, it has strong reference with all textfield and files related with to it. If you need to remove reference from textfield or file before VGSCollect instance is deallocated, you can do it manually whenever you need it.

Code example

Multiple Data Regions

Please use the following configuration to set up a specific data region if needed.

Add a Custom Hostname

When integrated with VGS, by default, the traffic is passed via VGS proxy, which has tntxxxxx.sandbox.verygoodproxy.com format, where tntxxxxx is your Vault identifier. Collect SDK allows you to use your custom hostname and make requests to a non-VGS domain name or localhost (on your local machine). Before adding a new Hostname you should create a CNAME record for your existing domain in your DNS provider’s account that should point to <VAULT_ID>.<ENVIRONMENT>.verygoodproxy.com.

** Learn more about Custom Hostnames**.

Then, in your Application create a VGSCollect instance with the Custom Hostname:

• When the hostname is not valid or not registered in VGS system, it will be ignored by SDK and all the traffic will be passed via VGS proxy directly. • Only https scheme is supported.\

Observing States

There are three types of VGSTextField states available that depends on choosen FieldType in VGSConfiguration: State, VGSCardState and VGSSSNState.

State

An object you use for observing VGSTextField parameters that depends on input and VGSConfiguration.

Declaration

You should not create State object by itself. Instead, get access to it from VGSTextField.state attribute. State object and it's attributes are read-only.

Some of State attributes

Attribute

Type/Default value

fieldName

VGSConfiguration.fieldName associated with VGSTextField

isValid

Contains VGSTextField current validation state

inputLength

Contains user input characters count in VGSTextField

To get a full list of State attributes check VGSCollectSDK Reference docsarrow-up-right

VGSCardState

An object you use for observing VGSTextField parameters when VGSConfiguration.type defined as FieldType.cardNumber.

Declaration

VGSCardState extends default State with more specific attributes related to credit card numbers

VGSCardState attributes

Attribute

Type/Default value

last4

Last 4 digits of the valid card number

bin

Bin digits of the valid card number

cardBrand

CardType object describing Credit Card Brand of the card number

  • bin and last4 attributes will be empty until the input card number is valid.

To get a full list of supported card brands check VGSCollectSDK Reference docs

VGSSSNState

An object you use for observing VGSTextField parameters when VGSConfiguration.type defined as FieldType.ssn.

Declaration

VGSSSNState extends default State with more specific attributes related to social security numbers

VGSSSNState attributes

Attribute

Type/Default value

last4

Last 4 digits of the valid card number

  • last4 attributes will be empty until the input social security number is valid.

Code example

State Publisher

If you preffere to use Combine framework, you can observe state changes with .statePublisher attribure. It will be triggered on each VGSTextField's interaction event, similar to VGSTextFieldDelegate events.

Declaration

Code example

Observe VGSTextField states

You can observe states every time VGSTextField input is changed. Observer callback will be called on each VGSTextField's interaction event. For more granular editing events handler, check VGSTextFieldDelegate methods.

Code example

For more details about available attributes and functionality check VGSCollectSDK Reference docsarrow-up-right

Last updated