Skip to content
This repository has been archived by the owner on Oct 4, 2019. It is now read-only.

Commit

Permalink
sandbox mode
Browse files Browse the repository at this point in the history
  • Loading branch information
alessiodionisi committed Jun 28, 2018
1 parent b536067 commit 97be67b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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...";
Expand All @@ -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);
```
28 changes: 28 additions & 0 deletions lib/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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";
}
}
}

0 comments on commit 97be67b

Please sign in to comment.