berbix

package module
v0.0.0-...-d70e4f5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2021 License: MIT Imports: 13 Imported by: 0

README

Berbix Go SDK

This Berbix Go library provides simple interfaces to interact with the Berbix API.

Installation

go get github.com/berbix/berbix-go

Usage

Constructing a client
import "github.com/berbix/berbix-go"

client := NewClient(secret, &ClientOptions{})
Create a transaction
tokens, err := client.CreateTransaction(&CreateTransactionOptions{
    CustomerUID: "internal_customer_uid", # ID for the user in client database
    TemplateKey: "your_template_key", # Template key for this transaction,
})

Or, if you need the hosted URL

options := &CreateHostedTransactionOptions{
	CreateTransactionOptions: CreateTransactionOptions{
		CustomerUID: "internal_customer_uid",
		TemplateKey: "your_template_key",
	},
	HostedOptions: HostedOptions{
		// Optional
		CompletionEmail: "example@example.com",
	},
}
resp, err := client.CreateHostedTransaction(options)
if err != nil {
	// Handle error
}

hostedURL := resp.HostedURL
Create tokens from refresh token
refreshToken := "" # fetched from database
transactionTokens := TokensFromRefresh(refreshToken)
Fetch transaction data
transactionData, err := client.FetchTransaction(transactionTokens)

Reference

Client
NewClient(secret string, options *ClientOptions) Client

Supported options:

  • HTTPClient - An optional override for the default HTTP client.
Methods
CreateTransaction(options *CreateTransactionOptions) (*Tokens, error)

Creates a transaction within Berbix to initialize the client SDK. Typically after creating a transaction, you will want to store the refresh token in your database associated with the currently active user session.

Supported options:

  • Email - Previously verified email address for a user.

  • Phone - Previously verified phone number for a user.

  • CustomerUID - An ID or identifier for the user in your system.

  • TemplateKey - The template key for this transaction.

CreateHostedTransaction(options *CreateHostedTransactionOptions) (*CreateHostedTransactionResponse, error)

Behaves the same as CreateTransaction() with two key differences: it returns a URL for a hosted transaction in addition to tokens and supports two optional parameters in addition to those supported for CreateTransaction():

  • CompletionEmail - Where to send an email when the verification completes.

  • RedirectURL - URL to redirect the user to after they complete the transaction. If not specified, the URL specified in the Berbix dashboard will be used instead.

FetchTransaction(tokens *Tokens) (*TransactionMetadata, error)

Fetches all of the information associated with the transaction. If the user has already completed the steps of the transaction, then this will include all of the elements of the transaction payload as described on the Berbix developer docs.

RefreshTokens(tokens *Tokens) (*Tokens, error)

This is typically not needed to be called explicitly as it will be called by the higher-level SDK methods, but can be used to get fresh client or access tokens.

ValidateSignature(secret string, body string, header string) (bool, error)

This method validates that the content of the webhook has not been forged. This should be called for every endpoint that is configured to receive a webhook from Berbix.

Parameters:

  • secret - This is the secret associated with that webhook. NOTE: This is distinct from the API secret and can be found on the webhook configuration page of the dashboard.
  • body - The full request body from the webhook. This should take the raw request body prior to parsing.
  • header - The value in the 'X-Berbix-Signature' header.
DeleteTransaction(tokens *Tokens) error

Permanently deletes all submitted data associated with the transaction corresponding to the tokens provided.

UpdateTransaction(tokens *Tokens, options *UpdateTransactionOptions) (*TransactionMetadata, error)

Changes a transaction's "action", for example upon review in your systems. Returns the updated transaction upon success.

Options:

  • Action: string - Action taken on the transaction. Typically this will either be "accept" or "reject".
  • Note: string - An optional note explaining the action taken.
OverrideTransaction(tokens *Tokens, options *OverrideTransactionOptions) error

Completes a previously created transaction, and overrides its return payload and flags to match the provided parameters.

Parameters:

  • ResponsePayload: string - A string describing the payload type to return when fetching transaction metadata, e.g. "us-dl". See our testing guide for possible options.
  • Flags: []string - An optional list of flags to associate with the transaction (independent of the payload's contents), e.g. ["id_under_18", "id_under_21"]. See our flags documentation for a list of flags.
  • OverrideFields: map[string]string - An optional mapping from a transaction field to the desired override value, e.g. OverrideFields = map[string]string{"date_of_birth" : "2000-12-09",}
Tokens
Properties
AccessToken: string

This is the short-lived bearer token that the backend SDK uses to identify requests associated with a given transaction. This is not typically needed when using the higher-level SDK methods.

ClientToken: string

This is the short-lived token that the frontend SDK uses to identify requests associated with a given transaction. After transaction creation, this will typically be sent to a frontend SDK.

RefreshToken: string

This is the long-lived token that allows you to create new tokens after the short-lived tokens have expired. This is typically stored in the database associated with the given user session.

TransactionID: int64

The internal Berbix ID number associated with the transaction.

expiry: time.Time

The time at which the access and client tokens will expire.

Static methods
TokensFromRefresh(refreshToken string) *Tokens

Creates a tokens object from a refresh token, which can be passed to higher-level SDK methods. The SDK will handle refreshing the tokens for accessing relevant data.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	CreateTransaction(options *CreateTransactionOptions) (*Tokens, error)
	CreateHostedTransaction(options *CreateHostedTransactionOptions) (*CreateHostedTransactionResponse, error)
	RefreshTokens(tokens *Tokens) (*Tokens, error)
	FetchTransaction(tokens *Tokens) (*TransactionMetadata, error)
	DeleteTransaction(tokens *Tokens) error
	UpdateTransaction(tokens *Tokens, options *UpdateTransactionOptions) (*TransactionMetadata, error)
	OverrideTransaction(tokens *Tokens, options *OverrideTransactionOptions) error
	ValidateSignature(secret, body, header string) error
}

func NewClient

func NewClient(secret string, options *ClientOptions) Client

type ClientOptions

type ClientOptions struct {
	Host       string
	HTTPClient HTTPClient
}

type CreateHostedTransactionOptions

type CreateHostedTransactionOptions struct {
	CreateTransactionOptions
	HostedOptions HostedOptions `json:"hosted_options"`
}

type CreateHostedTransactionResponse

type CreateHostedTransactionResponse struct {
	Tokens    Tokens
	HostedURL string
}

type CreateTransactionOptions

type CreateTransactionOptions struct {
	CustomerUID string `json:"customer_uid"`
	TemplateKey string `json:"template_key"`
	Email       string `json:"email"`
	Phone       string `json:"phone"`
}

type DefaultHTTPClient

type DefaultHTTPClient struct {
	// contains filtered or unexported fields
}

func (*DefaultHTTPClient) Request

func (d *DefaultHTTPClient) Request(method string, url string, headers map[string]string, options *RequestOptions, dst interface{}) (err error)

type DuplicateInfo

type DuplicateInfo struct {
	CustomerUID string `json:"customer_uid"`

	TransactionID int64 `json:"transaction_id"`
}

type HTTPClient

type HTTPClient interface {
	Request(method string, url string, headers map[string]string, options *RequestOptions, dst interface{}) error
}

type HostedOptions

type HostedOptions struct {
	CompletionEmail string `json:"completion_email"`
	RedirectURL     string `json:"redirect_url"`
}

type OverrideTransactionOptions

type OverrideTransactionOptions struct {
	ResponsePayload string            `json:"response_payload"`
	Flags           []string          `json:"flags"`
	OverrideFields  map[string]string `json:"override_fields"`
}

type RequestOptions

type RequestOptions struct {
	Body io.Reader
}

type Tokens

type Tokens struct {
	TransactionID int64
	AccessToken   string
	RefreshToken  string
	ClientToken   string
	Expiry        time.Time
}

func TokensFromRefresh

func TokensFromRefresh(refreshToken string) *Tokens

func (*Tokens) NeedsRefresh

func (t *Tokens) NeedsRefresh() bool

type TransactionField

type TransactionField struct {
	// The highest confidence value for this field
	Value string `json:"value"`

	// The confidence level for this field
	Confidence string `json:"confidence"`

	// The underlying sources of the data for this field
	Sources []TransactionSource `json:"sources"`
}

type TransactionFieldSet

type TransactionFieldSet struct {
	// The given name of the person completing the flow.
	GivenName *TransactionField `json:"given_name,omitempty"`

	// The middle name of the person completing the flow.
	MiddleName *TransactionField `json:"middle_name,omitempty"`

	// The family name of the person completing the flow.
	FamilyName *TransactionField `json:"family_name,omitempty"`

	// The date of birth of the person completing the flow.
	DateOfBirth *TransactionField `json:"date_of_birth,omitempty"`

	// The sex of the person completing the flow. Available upon request if required for your use case.
	Sex *TransactionField `json:"sex,omitempty"`

	// The age of the person completing the flow
	Age *TransactionField `json:"age,omitempty"`

	// The nationality of the person completing the flow
	Nationality *TransactionField `json:"nationality,omitempty"`

	// The expiry date of the ID collected in the flow
	IDExpiryDate *TransactionField `json:"id_expiry_date,omitempty"`

	// The issue date of the ID collected in the flow
	IDIssueDate *TransactionField `json:"id_issue_date,omitempty"`

	// The ID number of the ID collected in the flow
	IDNumber *TransactionField `json:"id_number,omitempty"`

	// The type of the ID collected in the flow
	IDType *TransactionField `json:"id_type,omitempty"`

	// The issuer of the ID collected in the flow
	IDIssuer *TransactionField `json:"id_issuer,omitempty"`

	// The email address as verified in the flow
	EmailAddress *TransactionField `json:"email_address,omitempty"`

	// The phone number as verified in the flow
	PhoneNumber *TransactionField `json:"phone_number,omitempty"`

	// The street address collected in the flow
	AddressStreet *TransactionField `json:"address_street,omitempty"`

	// The city of the address collected in the flow
	AddressCity *TransactionField `json:"address_city,omitempty"`

	// The subdivision of the address collected in the flow
	AddressSubdivision *TransactionField `json:"address_subdivision,omitempty"`

	// The postal code of the address collected in the flow
	AddressPostalCode *TransactionField `json:"address_postal_code,omitempty"`

	// The country of the address collected in the flow
	AddressCountry *TransactionField `json:"address_country,omitempty"`

	// The unit of the address collected in the flow
	AddressUnit *TransactionField `json:"address_unit,omitempty"`
}

type TransactionImageSet

type TransactionImageSet struct {
	Front    *TransactionImages `json:"front,omitempty"`
	Back     *TransactionImages `json:"back,omitempty"`
	Selfie   *TransactionImages `json:"selfie,omitempty"`
	Liveness *TransactionImages `json:"liveness,omitempty"`
}

type TransactionImages

type TransactionImages struct {
	// Full image captured from the user. This will be present for front, selfie and liveness.
	FullImage string `json:"full_image,omitempty"`

	// Cropped ID image captured from the user. This will be present for front and back.
	CroppedImage string `json:"cropped_image,omitempty"`

	// Cropped face image captured from the user. This will be present for front, selfie and liveness.
	FaceImage string `json:"face_image,omitempty"`
}

type TransactionMetadata

type TransactionMetadata struct {
	// String representing the entity's type.
	Entity string `json:"entity"`

	// Berbix Transaction ID represented by the associated metadata.
	ID int64 `json:"id"`

	// Any flags associated with the verifications for this transaction.
	Flags []string `json:"flags"`

	// The action as configured in the customer dashboard for the given verification state.
	Action string `json:"action,omitempty"`

	// Data field values extracted from the verification sets.
	Fields *TransactionFieldSet `json:"fields,omitempty"`

	// Short-lived URLs of images collected from the end user.
	Images *TransactionImageSet `json:"images,omitempty"`

	// When the transaction was originally created.
	CreatedAt time.Time `json:"created_at"`

	// The user's unique identifier in your systems as provided in transaction creation.
	CustomerUID string `json:"customer_uid"`

	// A list of CustomerUIDs and Berbix Transaction IDs associated with those duplicates if duplicates of the photo ID are identified for the given transaction.
	Duplicates []DuplicateInfo `json:"duplicates"`

	// The link to Berbix dashboard page for this transaction.
	DashboardURL string `json:"dashboard_url,omitempty"`

	// Optional information about the response. Used in test mode only.
	ImplementationInfo string `json:"implementation_info,omitempty"`
}

type TransactionSource

type TransactionSource struct {
	// The value of the field as determined by this source
	Value string `json:"value"`

	// The type of source
	Type string `json:"type"`

	// The confidence level for this source
	Confidence string `json:"confidence"`
}

type UpdateTransactionOptions

type UpdateTransactionOptions struct {
	Action string `json:"action"`
	Note   string `json:"note"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL