diff --git a/README.md b/README.md index 41c915f..a51a530 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,8 @@ Sign in to your [Dashboard](https://business.satispay.com) at [business.satispay Use the activation token with the `authenticateWithToken` function to generate and exchange a pair of RSA keys. Save the keys in your database or in a **safe place** not accesibile from your website. - ```php +// Initialize an empty Api $api = new \SatispayOnline\Api(); // Authenticate and generate the keys @@ -39,11 +39,8 @@ $serverPublicKey = $api->getServerPublicKey(); ``` To reuse the keys after authentication, pass them as an argument in the `\SatispayOnline\Api` constructor. - ```php -$api = new \SatispayOnline\Api(); - -// Keys +// Keys variables $publicKey = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhk..."; $privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBg..."; $keyId = "ldg9sbq283og7ua1abpj989kbbm2g60us6f18c1sciq..."; @@ -65,3 +62,18 @@ try { exit; } ``` + +## Enable Sandbox +To enable sandbox pass `isSandbox` with value `true` as an argument in the `\SatispayOnline\Api` constructor. +```php +// Pass isSandbox = true to Api constructor +$api = new \SatispayOnline\Api([ + "isSandbox" => true + // Other arguments +]); +``` + +You can also use the `setIsSandbox` function. +```php +$api->setIsSandbox(true); +``` diff --git a/lib/Api.php b/lib/Api.php index d410a30..a78465b 100644 --- a/lib/Api.php +++ b/lib/Api.php @@ -41,6 +41,10 @@ public function __construct($options = []) { $this->keyId = $options["keyId"]; } + if (!empty($options["isSandbox"]) && $options["isSandbox"] === true) { + $this->env = "staging"; + } + $this->amounts = new Amounts($this); $this->charges = new Charges($this); $this->checkouts = new Checkouts($this); @@ -140,4 +144,28 @@ public function getKeyId() { public function getVersion() { return $this->version; } + + /** + * Is sandbox enabled? + * @return boolean + */ + public function getIsSandbox() { + if ($this->env === "staging") { + return true; + } else { + return false; + } + } + + /** + * Enable or disable sandbox + * @param boolean $value + */ + public function setIsSandbox($value) { + if ($value === true) { + $this->env = "staging"; + } else { + $this->env = "production"; + } + } }