IPC Configuration class

Namespace: Mypos\IPC
Located at Config.php 

Methods summary

public Mypos\IPC\Config
#setPrivateKeyPath( string $path )

Store private RSA key as a filepath

public string
#getAPIPublicKey( )

IPC API public RSA key

public Mypos\IPC\Config
#setAPIPublicKey( string $publicKey )

IPC API public RSA key

public Mypos\IPC\Config
#setAPIPublicKeyPath( string $path )

IPC API public RSA key as a filepath

public string
#getEncryptPublicKey( )

Public RSA key using for encryption sensitive data

public Mypos\IPC\Config
#setEncryptPublicKey( string $key )

Public RSA key using for encryption sensitive data

public Mypos\IPC\Config
#setEncryptPublicKeyPath( string $path )

Public RSA key using for encryption sensitive data

public string
#getLang( )

Language code (ISO 639-1)

public Mypos\IPC\Config
#setLang( string $lang )

Language code (ISO 639-1)

public string
#getDeveloperKey( )

Store private RSA key

public Mypos\IPC\Config
#setDeveloperKey( string $developerKey )

Set myPOS developer key.

public string
#getSource( )
 
public
#setSource( string $source )

Additional parameter to specify the source of request

public boolean
#validate( )

Validate all set config details

public string
#getKeyIndex( )

Keyindex used for signing request

public Mypos\IPC\Config
#setKeyIndex( integer $keyIndex )

Keyindex used for signing request

public string
#getIpcURL( )

IPC API URL

public Mypos\IPC\Config
#setIpcURL( string $ipc_url )

IPC API URL

public integer
#getSid( )

Store ID

public Mypos\IPC\Config
#setSid( integer $sid )

Store ID

public string
#getWallet( )

Wallet number

public Mypos\IPC\Config
#setWallet( string $wallet )

Wallet number

public string
#getVersion( )

API Version

public Mypos\IPC\Config
#setVersion( string $version )

API Version

public string
#getPrivateKey( )

Store private RSA key

public Mypos\IPC\Config
#setPrivateKey( string $privateKey )

Store private RSA key

 

 

Example

<?php
namespace Mypos\IPC;
/**
 * IPC Configuration class
 */
class Config
{
    private $privateKey = null;
    private $APIPublicKey = null;
    private $encryptPublicKey = null;
    private $keyIndex = null;
    private $sid;
    private $wallet;
    private $lang = 'en';
    private $version = '1.3';
    private $ipc_url = 'https://www.mypos.eu/vmp/checkout';
    private $developerKey;
    private $source = 'SDK_PHP_1.3';
    /**
     * Store private RSA key as a filepath
     *
     * @param string $path File path
     *
     * @return Config
     * @throws IPC_Exception
     */
    public function setPrivateKeyPath($path)
    {
        if (!is_file($path) || !is_readable($path)) {
            throw new IPC_Exception('Private key not found in:'.$path);
        }
        $this->privateKey = file_get_contents($path);
        return $this;
    }
    /**
     * IPC API public RSA key
     *
     * @return string
     */
    public function getAPIPublicKey()
    {
        return $this->APIPublicKey;
    }
    /**
     * IPC API public RSA key
     *
     * @param string $publicKey
     *
     * @return Config
     */
    public function setAPIPublicKey($publicKey)
    {
        $this->APIPublicKey = $publicKey;
        return $this;
    }
    /**
     * IPC API public RSA key as a filepath
     *
     * @param string $path
     *
     * @return Config
     * @throws IPC_Exception
     */
    public function setAPIPublicKeyPath($path)
    {
        if (!is_file($path) || !is_readable($path)) {
            throw new IPC_Exception('Public key not found in:'.$path);
        }
        $this->APIPublicKey = file_get_contents($path);
        return $this;
    }
    /**
     * Public RSA key using for encryption sensitive data
     *
     * @return string
     */
    public function getEncryptPublicKey()
    {
        return $this->encryptPublicKey;
    }
    /**
     * Public RSA key using for encryption sensitive data
     *
     * @param string $key
     *
     * @return Config
     */
    public function setEncryptPublicKey($key)
    {
        $this->encryptPublicKey = $key;
        return $this;
    }
    /**
     * Public RSA key using for encryption sensitive data
     *
     * @param string $path File path
     *
     * @return Config
     * @throws IPC_Exception
     */
    public function setEncryptPublicKeyPath($path)
    {
        if (!is_file($path) || !is_readable($path)) {
            throw new IPC_Exception('Key not found in:'.$path);
        }
        $this->encryptPublicKey = file_get_contents($path);
        return $this;
    }
    /**
     * Language code (ISO 639-1)
     *
     * @return string
     */
    public function getLang()
    {
        return $this->lang;
    }
    /**
     * Language code (ISO 639-1)
     *
     * @param string $lang
     *
     * @return Config
     */
    public function setLang($lang)
    {
        $this->lang = $lang;
        return $this;
    }
    /**
     * Store private RSA key
     *
     * @return string
     */
    public function getDeveloperKey()
    {
        return $this->developerKey;
    }
    /**
     * Set myPOS developer key.
     *
     * @param string $developerKey
     *
     * @return Config
     */
    public function setDeveloperKey($developerKey)
    {
        $this->developerKey = $developerKey;
        return $this;
    }
    /**
     * @return string
     */
    public function getSource()
    {
        return $this->source;
    }
    /**
     * Additional parameter to specify the source of request
     *
     * @param string $source
     */
    public function setSource($source)
    {
        $this->source = $source;
    }
    /**
     * Validate all set config details
     *
     * @return boolean
     * @throws IPC_Exception
     */
    public function validate()
    {
        if ($this->getKeyIndex() == null || !is_numeric($this->getKeyIndex())) {
            throw new IPC_Exception('Invalid Key Index');
        }
        if ($this->getIpcURL() == null || !Helper::isValidURL($this->getIpcURL())) {
            throw new IPC_Exception('Invalid IPC URL');
        }
        if ($this->getSid() == null || !is_numeric($this->getSid())) {
            throw new IPC_Exception('Invalid SID');
        }
        if ($this->getWallet() == null || !is_numeric($this->getWallet())) {
            throw new IPC_Exception('Invalid Wallet number');
        }
        if ($this->getVersion() == null) {
            throw new IPC_Exception('Invalid IPC Version');
        }
        if (!openssl_get_privatekey($this->getPrivateKey())) {
            throw new IPC_Exception('Invalid Private key');
        }
        return true;
    }
    /**
     *  Keyindex used for signing request
     *
     * @return string
     */
    public function getKeyIndex()
    {
        return $this->keyIndex;
    }
    /**
     * Keyindex used for signing request
     *
     * @param int $keyIndex
     *
     * @return Config
     */
    public function setKeyIndex($keyIndex)
    {
        $this->keyIndex = $keyIndex;
        return $this;
    }
    /**
     * IPC API URL
     *
     * @return string
     */
    public function getIpcURL()
    {
        return $this->ipc_url;
    }
    /**
     * IPC API URL
     *
     * @param string $ipc_url
     *
     * @return Config
     */
    public function setIpcURL($ipc_url)
    {
        $this->ipc_url = $ipc_url;
        return $this;
    }
    /**
     * Store ID
     *
     * @return int
     */
    public function getSid()
    {
        return $this->sid;
    }
    /**
     * Store ID
     *
     * @param int $sid
     *
     * @return Config
     */
    public function setSid($sid)
    {
        $this->sid = $sid;
        return $this;
    }
    /**
     * Wallet number
     *
     * @return string
     */
    public function getWallet()
    {
        return $this->wallet;
    }
    /**
     * Wallet number
     *
     * @param string $wallet
     *
     * @return Config
     */
    public function setWallet($wallet)
    {
        $this->wallet = $wallet;
        return $this;
    }
    /**
     * API Version
     *
     * @return string
     */
    public function getVersion()
    {
        return $this->version;
    }
    /**
     * API Version
     *
     * @param string $version
     *
     * @return Config
     */
    public function setVersion($version)
    {
        $this->version = $version;
        return $this;
    }
    /**
     * Store private RSA key
     *
     * @return string
     */
    public function getPrivateKey()
    {
        return $this->privateKey;
    }
    /**
     * Store private RSA key
     *
     * @param string $privateKey
     *
     * @return Config
     */
    public function setPrivateKey($privateKey)
    {
        $this->privateKey = $privateKey;
        return $this;
    }
}