Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
alphaolomi authored and github-actions[bot] committed Sep 26, 2022
1 parent 777aea6 commit 0166125
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 29 deletions.
1 change: 0 additions & 1 deletion config/azampay.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

/**
* Config for Azampay
*
*/
return [

Expand Down
32 changes: 17 additions & 15 deletions src/AzampayService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,36 @@ class AzampayService
use CanSendGetRequest;
use CanSendPostRequest;

const SANDBOX_AUTH_BASE_URL = 'https://authenticator-sandbox.azampay.co.tz';

const SANDBOX_BASE_URL = 'https://sandbox.azampay.co.tz';

const SANDBOX_AUTH_BASE_URL = "https://authenticator-sandbox.azampay.co.tz";
const SANDBOX_BASE_URL = "https://sandbox.azampay.co.tz";
const AUTH_BASE_URL = '';

const BASE_URL = '';
const SUPPORTED_MNO = ["Airtel", "Tigo", "Halopesa", "Azampesa"];
const SUPPORTED_BANK = ["CRDB", "NMB"];
const SUPPORTED_CURRENCY = ["TZS"];

const SUPPORTED_MNO = ['Airtel', 'Tigo', 'Halopesa', 'Azampesa'];

const SUPPORTED_BANK = ['CRDB', 'NMB'];

const SUPPORTED_CURRENCY = ['TZS'];

// appName
// clientId
// clientSecret
// environment

private $baseUrl;

private $authBaseUrl;

private $apiKey;

public function __construct(
private array $options = []
) {
foreach (['appName', 'clientId', 'clientSecret'] as $key) {
if (!isset($this->options[$key]) || empty($this->options[$key])) {
foreach (['appName', 'clientId', 'clientSecret'] as $key) {
if (! isset($this->options[$key]) || empty($this->options[$key])) {
throw new \InvalidArgumentException("Missing required option: $key");
}
}
Expand All @@ -49,8 +56,6 @@ public function __construct(
$this->authBaseUrl = $this->options['environment'] === 'sandbox' ? self::SANDBOX_AUTH_BASE_URL : self::AUTH_BASE_URL;
}



/**
* Generate Token
*
Expand All @@ -62,7 +67,7 @@ public function generateToken(): array
{
return $this->get(
request: Http::baseUrl(url: $this->authBaseUrl), // FIXME: bad code
url: "/AppRegistration/GenerateToken",
url: '/AppRegistration/GenerateToken',
)->onError(function (Response $response) {
if ($response->status() === 423) {
throw new \Exception('Provided detail is not valid for this app or secret key has been expired');
Expand All @@ -72,7 +77,6 @@ public function generateToken(): array
// expire
}


// "accountNumber": "string",
// "additionalProperties": {
// "property1": null,
Expand All @@ -87,7 +91,7 @@ public function mobileCheckout(array $data)
// azampay/mno/checkout
return $this->post(
request: $this->service->buildRequestWithToken(),
url: "/azampay/mno/checkout",
url: '/azampay/mno/checkout',
payload: $data
)->onError(function (Response $response) {
// if ($response->status() === 400) {
Expand All @@ -96,8 +100,6 @@ public function mobileCheckout(array $data)
})->json();
}



// "additionalProperties": {
// "property1": null,
// "property2": null
Expand All @@ -115,7 +117,7 @@ public function bankCheckout(array $data)
// azampay/bank/checkout
return $this->post(
request: $this->service->buildRequestWithToken(),
url: "/azampay/mno/checkout",
url: '/azampay/mno/checkout',
payload: $data
)->onError(function (Response $response) {
// if ($response->status() === 400) {
Expand Down
2 changes: 1 addition & 1 deletion src/Facades/Azampay.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @method static \Alphaolomi\Azampay\AzampayService bankCheckout(array $payload)
*
* @author Alpha Olomi
*
*
* @see \Alphaolomi\Azampay\Azampay
*/
class Azampay extends Facade
Expand Down
17 changes: 8 additions & 9 deletions src/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,38 @@
*/
class Helpers
{

/**
* Cleans the mobile number to remove any whitespace or dashes
*
* @param string $mobileNumber
* @param string $mobileNumber
* @return string
*/

public static function cleanMobileNumber($mobileNumber)
{

$mobileNumber = preg_replace('/[^0-9]/', '', $mobileNumber);

if (strlen($mobileNumber) < 9 || strlen($mobileNumber) > 12) {
throw new \Exception("Invalid mobile number");
throw new \Exception('Invalid mobile number');
}
if (strlen($mobileNumber) == 9 && $mobileNumber[0] != '0') {
$mobileNumber = "255{$mobileNumber}";
} elseif (strlen($mobileNumber) == 10 && $mobileNumber[0] == '0') {
$mobileNumber = str_replace("0", "255", $mobileNumber, 1);
$mobileNumber = str_replace('0', '255', $mobileNumber, 1);
}
}

/**
* Clean the amount to remove any whitespace or commas
* @param string $amount
*
* @param string $amount
* @return string
*/
public static function cleanAmount($amount)
{
$amount = trim($amount);
$amount = str_replace(" ", "", $amount);
$amount = str_replace(",", "", $amount);
$amount = str_replace(' ', '', $amount);
$amount = str_replace(',', '', $amount);

return $amount;
}
}
4 changes: 1 addition & 3 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

namespace Alphaolomi\Azampay\Tests;

use Illuminate\Database\Eloquent\Factories\Factory;
use Orchestra\Testbench\TestCase as Orchestra;
use Alphaolomi\Azampay\AzampayServiceProvider;
use Orchestra\Testbench\TestCase as Orchestra;

class TestCase extends Orchestra
{

protected function getPackageProviders($app)
{
return [AzampayServiceProvider::class];
Expand Down

0 comments on commit 0166125

Please sign in to comment.