Skip to content

EN🍉3 Configuration

jeffrey n. carre edited this page Nov 21, 2022 · 2 revisions

Configuration

Global environmental values

This library expects the configuration (secret, mode, client_id....) to be set in the environment value of the host. Assign the proper value from the MonCash Business dashboard as indicated in the prerequisite section.

Check the .env.example file for a non-exhaustive list of variables.

On the test server, set the mode (MONCASH_MODE) to sandbox. It will only work with the sandbox credentials.

If you have permission, you can set the host environment depending on the server distribution and service running ( Windows, Ubuntu, Apache, Nginx,...).

Environment file .env

This package is bundled with vlucas/phpdotenv and can read the .env file in the root of the application host. Add these variables to the .env file in the root of your project.

# /root/.env

# Replace <your-client-id> accordingly
MONCASH_CLIENT_ID="<your-client-id>"
# Replace <your-client-secret> accordingly
MONCASH_CLIENT_SECRET="<your-client-secret>"
# Replace <yourbuisiness-key> accordingly
MONCASH_BUSINESS_KEY="<yourbuisiness-key>"
#[ExpectedValues(['sandbox', 'production'])] Default: 'sandbox'
MONCASH_MODE="sandbox"
# Enum: en, fr, ht. Default 'en' 
MONCASH_LANG="en"

Override the global environment

At any time you can override the default configuration that is set in .env file.

use Fruitsbytes\PHP\MonCash\Configuration\Configuration;


/**
* @var string $client_id
 */
$client_id ='<your-client-id>';
/**
* @var string $client_secret
 */
$client_secret='<your-client-secret>';

// Switch credentials with the configuration DTO
$configuration = new Configuration(["lang"=>"ht", "clientId" => $client_id, "clientSecret" => $client_secret]);
$monCash = new Client($configuration);

// With configuration array
$monCash = new Client(["lang"=>"fr"]);

Use third-party Secret manager (Advanced)

🧙 This configuration is optional and requires a level of mastery of some external library/SDK, but can greatly improve the Application security if implemented correctly.

It is not recommended to keep application API keys, passwords, certificates, and other sensitive data in the repository. For this reason, Many cloud providers offer secret managers to help mitigate secret exposition.

The general idea is to set the host environment variables via secure and authorized access to a vault. Based on the various implementations from the providers, we can use a uniform approach. Some strategy classes are available:

Name Provider Implementation Status
Default uses .env file
GCP Google Cloud Platform Secret Manager
AWS AWS Secret Manager
Azure Azure Key Vault
KeyCloak Keycloak - Kubernetes/OpenShift secrets
Vault HashiCorp Vault

To add new strategies implement the SecretManager interface as explained in the section Manage secret.

In the `environment variables you can specify a Strategy to retrieve the secret :

# /root/.env

# Name of implementation `Fruitsbytes\PHP\MonCash\Strategy\TokenMachine\TokenMachineInterface`. Default: `FileTokenMachine`
MONCASH_TOKEN_MACHINE="Fruitsbytes\\PHP\\MonCash\\Strategy\\TokenMachine\\MySQLTokenMachine"
# Name of `Fruitsbytes\PHP\MonCash\Strategy\SecretManager\SecretManagerInterface` implementation. Default Default: `DefaultSecretManager`
MONCASH_SECRET_MANAGER="Fruitsbytes\\PHP\\MonCash\\Strategy\\SecretManager\\GCPSecretManager"
Previous Next
◄ Installation Create a payment ►

FruitsBytes MonCash PHP

Clone this wiki locally