Data Revealing

VGS Show

An object you use for revealing and displaying data in VGS Show UI Elements.

Declaration

class VGSShow

Creating a VGS Show instance

Use the following initializers to create VGSShow instance:

/// Initialzation
///
/// - Parameters:
///   - id: `String` object, your organization vault id.
///   - environment: `String` object, your organization vault environment with data region.(e.g. "live", "live-eu1", "sanbox").
init(id: String, environment: String)

/// Initialzation
///
/// - Parameters:
///   - id: `String` object, your organization vault id.
///   - environment: `VGSEnvironment` object, your organization vault environment. By default `.sandbox`.
///   - dataRegion: `String` object, id of data storage region (e.g. "eu-123").
init(id: String, environment: VGSEnvironment = .sandbox, dataRegion: String? = nil)

• All VGSShow instances in the Application will be working independently and only with UI Elements that are subscribed by VGSShow instance. • All VGSShow instances can be configured differently.\

Multiple Data Regions

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

/// Check your data region, it should look like: "live-eu-1"
/// In your code follow the VGSShow initialization pattern
var vgsShow = VGSShow(id: "<VAULT_ID>", environment: .live, dataRegion: "eu-1")

///If you set enivronment as String, you can point region directly in environment string
var vgsShow = VGSShow(id: "<VAULT_ID>", environment: "live-eu-1")

Show revealed data

To show revealed data you should subscribe VGS Show SDK UI Elements to VGSShow instance and send a reveal request.

Subscribe UI Components

In order to show revealed data, you should subscribe VGS UI Elements with correct contentPath value:

Code example

override func viewDidLoad() {
	super.viewDidLoad()

  // Sudscribe VGSLabels.
	vgsShow.subscribe(cardNumberLabel)
	vgsShow.subscribe(expDateLabel)
}

Revealed data will be shown only if VGSShow response contains expected key, that is same as contentPath described in subscribed VGS UI Element.

Send reveal request

In order to change aliases to the real data, you need to send reveal request. The aliases data will be revealed when the response goes through VGS proxy. If the request is success, revealed data will be automatically displayed in subscribed VGS Show UI Elements. You also can send any additional data in the request payload.

Code example

func revealData() {
  /// send any additional data to your backend
  let customPayload = ["CustomKey" : "CustomValue"]()

  /// make a reveal request
	vgsShow.request(path: "post",
									method: .post,
                  payload: customPayload) { (requestResult) in

		switch requestResult {
		case .success(let code):
			self.copyCardNumberButton.isEnabled = true
			print("vgsshow success, code: \(code)")
		case .failure(let code, let error):
			print("vgsshow failed, code: \(code), error: \(error)")
		}
	}
}

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. Show SDK allows you to set your own 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 VGSShow instance with the Custom Hostname:


var vgsShow = VGSShow(id: "<VAULT_ID>", environment: <ENVIRONMENT>, hostname: "https://customdomain.com")

• 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.\

Setting Custom API Headers

There is an option to setup custom headers in VGSShow requests.

var customHeaders: [String: String]?

Code example

/// set custom headers
vgsShow.customHeaders = [
    "custom-header": "custom data"
]

Getting content from Nested JSON Structure

When you need to show revealed data from a specific json structure you can do it by adding . notation into VGSLabel.contentPath string. Each . in a contentPath represents a new level of nesting.

Code example

/// Define content paths in response object
userIdLabel.contentPath = "userId"
cardNumberLabel.contentPath = "card_data.card_number"
cardExpDateLabel.contentPath = "card_data.exp_date"

/// Example of JSON structure in response from reveal data request
{
  "userId": "id12345",
  “card_data: {
           “card_number”: "411111111111111”,
           “exp_date”: "01/2024"
         }”
}

Last updated