Skip to content

Commit

Permalink
Bug fix to allow specifiying api keys in .env
Browse files Browse the repository at this point in the history
  • Loading branch information
shalvah committed Apr 28, 2017
1 parent 6e50962 commit 7106786
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions src/Moneywave.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ class Moneywave
/**
* Moneywave constructor.
*/
public function __construct($apiKey, $secretKey)
public function __construct($apiKey = null, $secretKey = null)
{
if (func_num_args() == 0) {
if (!($this->apiKey = $apiKey)) {
$this->apiKey = getenv("MONEYWAVE_API_KEY");
}
if (!($this->secretkey = $secretKey)) {
$this->secretkey = getenv("MONEYWAVE_SECRET_KEY");
if (!($this->apiKey)) {
throw new MoneywaveException("No api key given.");
} else if (!($this->secretkey)) {
throw new MoneywaveException("No secret key given.");
}
} else {
$this->apiKey = $apiKey;
$this->secretkey = $secretKey;
}

if (!($this->apiKey)) {
throw new MoneywaveException("No api key given.");
} else if (!($this->secretkey)) {
throw new MoneywaveException("No secret key given.");
}

$this->baseUrl = "https://moneywave.herokuapp.com";
Expand All @@ -51,7 +51,8 @@ public function __construct($apiKey, $secretKey)
/*
* Get Moneywave access token
*/
private function getAccessToken()
private
function getAccessToken()
{
$response = $this->client->post('/v1/merchant/verify', [
'form_params' => [
Expand All @@ -63,24 +64,31 @@ private function getAccessToken()
if ($response["status"] == "success") {
return $response['token'];
} else {
throw new MoneywaveException("Authentication failed: ".print_r($response));
throw new MoneywaveException("Authentication failed: " . print_r($response));
}
}

public function request($method, $url, $options)
public
function request($method, $url, $options)
{
return $this->client->request($method, "https://moneywave.herokuapp.com".$url, $options);
return $this->client->request($method, "https://moneywave.herokuapp.com" . $url, $options);
}

public function getClient() {
public
function getClient()
{
return $this->client;
}

public function getToken() {
public
function getToken()
{
return $this->accessToken;
}

public function getApiKey() {
public
function getApiKey()
{
return $this->apiKey;
}

Expand Down

0 comments on commit 7106786

Please sign in to comment.