PCSDKModule Documentation

Class PCUsers​Manager

public final class PCUsersManager  

Creates and manages PCUser objects

Properties

users

public static var users: [PCUser]  

Returs all users stored on the device

fingerprint

public static var fingerprint: String  

Unique fingerprint for the device

Methods

import​User(from:​)

public static func importUser(
        from string: String
    ) throws -> PCUser  

Creates the new user by importing the data from a string

Parameters

string String

Should contain the user's data. Supports JSON, XML and Plain Text formats

Returns

The new PCUser object or nil if source is incorrect

activate(user:​using:​)

public static func activate(
        user: PCUser,
        using code: String
    ) throws  

Activates a non-activated user using an activation code

If user is already activated nothing will happen.

Parameters

user PCUser

User to be activated

code String

Activation code

Throws

PCError.invalidActivationCode if the activation code is wrong

submit(password:​for:​)

public static func submit(
        password: String,
        for user: PCUser
    ) throws  

Prepares the user for signing operations and changes the isReadyToSign property to true.

The user must be activated before submiting the password. You can check the activation by reading the isActivated property which must be true.

Parameters

password String

The user's password

user PCUser

The user to be ready to sign

Throws

PCError.invalidPassword if the password is wrong

register(user:​device​Token:​push​Notifications​Service:​keys​Processor:​target​Queue:​completion:​)

public static func register(
        user: PCUser,
        deviceToken: String?,
        pushNotificationsService: PushNotificationsService = .apns,
        keysProcessor: KeysProcessor? = nil,
        targetQueue: DispatchQueue = .main,
        completion: @escaping (_ result: Result<RegistrationResult, Error>) -> Void
    )  

Registers the user on the PayContol server and returns registration result

Registers public key, deviceToken for Push Notifications and the device's fingerprint

Parameters

user PCUser

The user to be registered

device​Token String?

The device's token for PUSH-notifications

push​Notifications​Service Push​Notifications​Service

The service for push notifications. Default is APNS.

keys​Processor Keys​Processor?

The keys processor where keypair will be generated

target​Queue Dispatch​Queue

The queue where a closure will be invoked on

completion @escaping (_ result:​ Result<Registration​Result, Error>) -> Void

A closure to be invoked after finishing registration

result

Returns RegistrationResult when success. Otherwise, returns error

register​Ext​Auth​Template(_:​user:​target​Queue:​completion:​)

public static func registerExtAuthTemplate(
        _ template: PCExtendedAuthTemplate,
        user: PCUser,
        targetQueue: DispatchQueue = .main,
        completion: @escaping (_ result: Result<Void, Error>) -> Void)  

Registers an extended authentication template for a user

Parameters

template PCExtended​Auth​Template

A template object

user PCUser

The user to be registered a template for

target​Queue Dispatch​Queue

The queue where a closure will be invoked on

completion @escaping (_ result:​ Result<Void, Error>) -> Void

A closure to be invoked after finishing registration

result

Returns nothing when success. Otherwise, returns error

store(user:​name:​password:​)

public static func store(
        user: PCUser,
        name: String? = nil,
        password: String? = nil) throws  

Stores the user in the storage

This method provides several possibilities:

  • Adding the new user. You must provide the imported user object, name and the password. If the name property is nil — the new name will be generated automatically by using the systemName property or by adding a suffix with a number.

  • Updating the existing user's data. Provide either the new name or the new password, or both. Updating the password requires invoking submitPassword method before.

Parameters

user PCUser

PCUser object to be stored

name String?

User's name

password String?

User's password

Throws

Can throw PCError.internalError if there are problems with CoreData or Keychain

delete(user:​)

public static func delete(
        user: PCUser) throws  

Deletes the user in the storage

Parameters

user PCUser

PCUser object to be deleted

Throws

Can throw PCError.internalError if there are problems with CoreData or Keychain

renew(user:​keys​Processor:​target​Queue:​completion:​)

public static func renew(
        user: PCUser,
        keysProcessor: KeysProcessor? = nil,
        targetQueue: DispatchQueue = .main,
        completion: @escaping (_ result: Result<PCUser, Error>) -> Void)  

Renews user

Renewing the user requires invoking submitPassword method before.

Parameters

user PCUser

PCUser to be renewed

keys​Processor Keys​Processor?

The processor to sign renew operation

target​Queue Dispatch​Queue

The queue where a closure will be invoked on

completion @escaping (_ result:​ Result<PCUser, Error>) -> Void

A closure to be invoked after renewing

result

Returns instance of renewed PCUser when success. Otherwise, returns error

get​Certificate​Info(user:​target​Queue:​completion:​)

public static func getCertificateInfo(
        user: PCUser,
        targetQueue: DispatchQueue = .main,
        completion: @escaping (_ result: Result<PCCertificateInfo, Error>) -> Void)  

Gets certificate info for the provided user

Parameters

user PCUser

PCUser the certificate info should be get for.

target​Queue Dispatch​Queue

The queue where a closure will be invoked on

completion @escaping (_ result:​ Result<PCCertificate​Info, Error>) -> Void

A closure to be invoked after renewing

result

Returns PCCertificateInfo object or error