Type: "Wallet"

Introduction

The core purpose of the N-Squared OCS is to act on wallets. An wallet in the Lua scripting engine is a Lua table and represents (by default) an immutable wallet.

API Methods

.id

Returns the unique wallet ID. This is the wallet’s primary key. The exact type of key (i.e. whether it’s a MSISDN, a GUID or something else) will depend on how the deployment of the OCS is designed.

This method has no parameters.

    ...
    local ocs = require "n2.n2ocs"
    local wallet = ocs.context().active_wallet()
    log.debug ("Processing wallet" .. wallet.id())
    ...

The wallet’s ID will always be defined. It cannot be nil.

.profile

Returns a Lua table, translated from a JSON object, that represents the wallet’s profile. The wallet’s profile is an opaque storage location for wallet data that is available for storing additional deployment-specific information on a wallet.

Note that the wallet’s associated CRM account (if there is one) will also have a profile. The subscriber’s profile (on the account) is completely separate and distinct to the subscriber’s wallet profile.

This method has no parameters.

    ...
    local ocs = require "n2.n2ocs"
    local wallet = ocs.context().active_wallet()
    local profile = wallet.profile()
    
    ...

The wallet’s profile will never be nil but the table returned may be empty if the wallet has no profile.

Note the Lua table is a copy of the wallet’s actual profile. Changes to this object do not automatically reflect in the wallet profile and are not automatically stored back to the OCS datastore.

.lifecycle_instance

Returns an object representing the current state of the wallet’s lifecycle (a lifecycle instance). This is effectively the wallet’s current state.

A lifecycle instance refers to a lifecycle which describes the state machine this instance is progressing through.

This method has no parameters.

    ...
    local ocs = require "n2.n2ocs"
    local wallet = ocs.context().active_wallet()
    local lifecycle = wallet.lifecycle()
    if (lifecycle ~= nil) then
        -- perform some state-based logic.
    end

    ...

The wallet’s lifecycle details, if it has one. It may be nil although that would be unusual.

.lifecycle_state

Returns the current lifecycle state name as a string for the wallet. This is equivalent to using the .lifecycle_instance() method to retrieve the current wallet lifecycle, and then using the name() method of that result (if it is not nil).

This method has no parameters. If the wallet does not have a lifecycle then this method will return nil.

.bucket

Returns a bucket from the wallet with the ID given, or nil if a wallet with this ID does not exist.

Field Type Description
.id String The ID of the bucket (as would be returned by mybucket.id()

This method may be used on a wallet:

    ...
    local ocs = require "n2.n2ocs"
    local wallet = ocs.context().active_wallet()
    local bucket = wallet.bucket("abcdef")
    if (bucket ~= nil) then
        -- bucket exists
    end
    ...

This method returns the bucket object, or nil if this bucket does not exist.

.buckets

Returns all buckets from the wallet as an array of buckets.

This method may be used on a wallet:

    ...
    local ocs = require "n2.n2ocs"
    local wallet = ocs.context().active_wallet()
    local buckets = wallet.buckets("abcdef")
    for _, bucket in ipairs(buckets) do
        -- Process the bucket
    end
    ...

This will return an empty array if there are no buckets.

.subscriptions

Returns all subscriptions from the wallet as an array of subscription objects.

This will return an empty array if there are no subscriptions.

.sessions

Returns all sessions from the wallet as an array of session objects.

This will return an empty array if there are no sessions.