diff --git a/resources/config/paystack.php b/resources/config/paystack.php index 58d6563..e6d0d29 100644 --- a/resources/config/paystack.php +++ b/resources/config/paystack.php @@ -35,4 +35,4 @@ */ 'merchantEmail' => getenv('MERCHANT_EMAIL'), -]; \ No newline at end of file +]; diff --git a/src/Exceptions/PaymentVerificationFailedException.php b/src/Exceptions/PaymentVerificationFailedException.php index 39110c8..7886880 100644 --- a/src/Exceptions/PaymentVerificationFailedException.php +++ b/src/Exceptions/PaymentVerificationFailedException.php @@ -13,6 +13,7 @@ use Exception; -class PaymentVerificationFailedException extends Exception { +class PaymentVerificationFailedException extends Exception +{ -} \ No newline at end of file +} diff --git a/src/Exceptions/isNullException.php b/src/Exceptions/isNullException.php index fa14ac4..d90777e 100644 --- a/src/Exceptions/isNullException.php +++ b/src/Exceptions/isNullException.php @@ -13,6 +13,7 @@ use Exception; -class IsNullException extends Exception { +class IsNullException extends Exception +{ -} \ No newline at end of file +} diff --git a/src/Facades/Paystack.php b/src/Facades/Paystack.php index f0ef46a..8805f92 100644 --- a/src/Facades/Paystack.php +++ b/src/Facades/Paystack.php @@ -13,14 +13,14 @@ use Illuminate\Support\Facades\Facade; -class Paystack extends Facade { +class Paystack extends Facade +{ /** - * Get the registered name of the component. - * - * @return string - */ + * Get the registered name of the component + * @return string + */ protected static function getFacadeAccessor() { return 'laravel-paystack'; } -} \ No newline at end of file +} diff --git a/src/Paystack.php b/src/Paystack.php index a3646a1..ec4e0ea 100644 --- a/src/Paystack.php +++ b/src/Paystack.php @@ -14,8 +14,8 @@ use GuzzleHttp\Client; use Illuminate\Support\Facades\Config; -class Paystack { - +class Paystack +{ /** * Transaction Verification Successful */ @@ -28,13 +28,13 @@ class Paystack { /** * Issue Secret Key from your Paystack Dashboard - * @var mixed + * @var string */ protected $secretKey; /** * Instance of Client - * @var object + * @var Client */ protected $client; @@ -73,7 +73,6 @@ public function setBaseUrl() /** * Get secret key from Paystack config file - * @return void */ public function setKey() { @@ -82,22 +81,26 @@ public function setKey() /** * Set options for making the Client request - * @return void */ private function setRequestOptions() { $authBearer = 'Bearer '. $this->secretKey; - $this->client = new Client(['base_uri' => $this->baseUrl, - 'headers' => [ - 'Authorization' => $authBearer, - 'Content-Type' => 'application/json', - 'Accept' => 'application/json' - ]]); + $this->client = new Client( + [ + 'base_uri' => $this->baseUrl, + 'headers' => [ + 'Authorization' => $authBearer, + 'Content-Type' => 'application/json', + 'Accept' => 'application/json' + ] + ] + ); } /** * Initiate a payment request to Paystack + * @return Paystack */ public function makePaymentRequest() { @@ -110,7 +113,7 @@ public function makePaymentRequest() "last_name" => request()->last_name, "callback_url" => request()->callback_url ]; - + // Remove the fields which were not sent (value would be null) array_filter($data); @@ -120,18 +123,30 @@ public function makePaymentRequest() } + /** + * @param string $relativeUrl + * @param string $method + * @param array $body + * @return Paystack + * @throws IsNullException + */ private function setHttpResponse($relativeUrl, $method, $body = []) { - if(is_null($method)){ + if (is_null($method)) { throw new IsNullException("Empty method not allowed"); } - $this->response = $this->client->{strtolower($method)}($this->baseUrl . $relativeUrl, ["body" => json_encode($body)]); + $this->response = $this->client->{strtolower($method)}( + $this->baseUrl . $relativeUrl, + ["body" => json_encode($body)] + ); + return $this; } /** * Get the authorization url from the callback response + * @return Paystack */ public function getAuthorizationUrl() { @@ -144,7 +159,6 @@ public function getAuthorizationUrl() /** * Hit Paystack Gateway to Verify that the transaction is valid - * @return void */ private function verifyTransactionAtGateway() { @@ -165,8 +179,7 @@ public function isTransactionVerificationValid() $result = $this->getResponse()['message']; - switch ($result) - { + switch ($result) { case self::VS: $validate = true; break; @@ -275,8 +288,8 @@ private function getData() /** * Create a plan */ - public function createPlan(){ - + public function createPlan() + { $data = [ "name" => request()->name, "description" => request()->desc, @@ -298,7 +311,8 @@ public function createPlan(){ * @param $plan_code * @return array */ - public function fetchPlan($plan_code){ + public function fetchPlan($plan_code) + { $this->setRequestOptions(); return $this->setHttpResponse('/plan/' . $plan_code, 'GET', [])->getResponse(); } @@ -308,7 +322,8 @@ public function fetchPlan($plan_code){ * @param $plan_code * @return array */ - public function updatePlan($plan_code){ + public function updatePlan($plan_code) + { $data = [ "name" => request()->name, "description" => request()->desc, @@ -325,9 +340,9 @@ public function updatePlan($plan_code){ /** * Create a customer - * @return array */ - public function createCustomer(){ + public function createCustomer() + { $data = [ "email" => request()->email, "first_name" => request()->fname, @@ -357,7 +372,8 @@ public function fetchCustomer($customer_id) * @param $customer_id * @return array */ - public function updateCustomer($customer_id){ + public function updateCustomer($customer_id) + { $data = [ "email" => request()->email, "first_name" => request()->fname, @@ -372,10 +388,11 @@ public function updateCustomer($customer_id){ } /** - * Export tranactions in .CSV + * Export transactions in .CSV * @return array */ - public function exportTransactions(){ + public function exportTransactions() + { $data = [ "from" => request()->from, "to" => request()->to, @@ -388,9 +405,9 @@ public function exportTransactions(){ /** * Create a subscription to a plan from a customer. - * @return array */ - public function createSubscription(){ + public function createSubscription() + { $data = [ "customer" => request()->customer, //Customer email or code "plan" => request()->plan, @@ -405,7 +422,8 @@ public function createSubscription(){ * Enable a subscription using the subscription code and token * @return array */ - public function enableSubscription(){ + public function enableSubscription() + { $data = [ "code" => request()->code, "token" => request()->token, @@ -419,7 +437,8 @@ public function enableSubscription(){ * Disable a subscription using the subscription code and token * @return array */ - public function disableSubscription(){ + public function disableSubscription() + { $data = [ "code" => request()->code, "token" => request()->token, @@ -431,7 +450,7 @@ public function disableSubscription(){ /** * Fetch details about a certain subscription - * @param $subscription_id + * @param mixed $subscription_id * @return array */ public function fetchSubscription($subscription_id) @@ -442,9 +461,9 @@ public function fetchSubscription($subscription_id) /** * Create pages you can share with users using the returned slug - * @return array */ - public function createPage(){ + public function createPage() + { $data = [ "name" => request()->name, "description" => request()->description, @@ -467,7 +486,7 @@ public function getAllPages() /** * Fetch details about a certain page using its id or slug - * @param $page_id + * @param mixed $page_id * @return array */ public function fetchPage($page_id) @@ -481,7 +500,8 @@ public function fetchPage($page_id) * @param $page_id * @return array */ - public function updatePage($page_id){ + public function updatePage($page_id) + { $data = [ "name" => request()->name, "description" => request()->description, @@ -491,8 +511,4 @@ public function updatePage($page_id){ $this->setRequestOptions(); return $this->setHttpResponse('/page/'.$page_id, 'PUT', $data)->getResponse(); } - } - - - diff --git a/src/PaystackServiceProvider.php b/src/PaystackServiceProvider.php index 2af3d27..ec2cc54 100644 --- a/src/PaystackServiceProvider.php +++ b/src/PaystackServiceProvider.php @@ -13,48 +13,46 @@ use Illuminate\Support\ServiceProvider; -class PaystackServiceProvider extends ServiceProvider { - - /* - * Indicates if loading of the provider is deferred. - * - * @var bool - */ - protected $defer = false; - - /** - * Publishes all the config file this package needs to function - * @return void - */ - public function boot() - { +class PaystackServiceProvider extends ServiceProvider +{ + + /* + * Indicates if loading of the provider is deferred. + * + * @var bool + */ + protected $defer = false; + + /** + * Publishes all the config file this package needs to function + */ + public function boot() + { $config = realpath(__DIR__.'/../resources/config/paystack.php'); $this->publishes([ $config => config_path('paystack.php') ]); - } + } - /** - * Register the application services. - * - * @return void - */ - public function register() - { - $this->app->bind('laravel-paystack', function() { + /** + * Register the application services. + */ + public function register() + { + $this->app->bind('laravel-paystack', function () { - return new Paystack; + return new Paystack; }); - } - - /** - * Get the services provided by the provider - * @return array - */ - public function provides() - { - return ['laravel-paystack']; - } -} \ No newline at end of file + } + + /** + * Get the services provided by the provider + * @return array + */ + public function provides() + { + return ['laravel-paystack']; + } +} diff --git a/src/TransRef.php b/src/TransRef.php index 7899c89..7a166c3 100644 --- a/src/TransRef.php +++ b/src/TransRef.php @@ -13,16 +13,16 @@ namespace Unicodeveloper\Paystack; -class TransRef { - +class TransRef +{ /** * Get the pool to use based on the type of prefix hash * @param string $type * @return string */ - private static function getPool( $type = 'alnum') + private static function getPool($type = 'alnum') { - switch ( $type ) { + switch ($type) { case 'alnum': $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; break; @@ -55,7 +55,8 @@ private static function getPool( $type = 'alnum') * @param integer $max * @return integer */ - private static function secure_crypt($min, $max) { + private static function secureCrypt($min, $max) + { $range = $max - $min; if ($range < 0) { @@ -84,10 +85,9 @@ public static function getHashedToken($length = 25) $token = ""; $max = strlen(static::getPool()); for ($i = 0; $i < $length; $i++) { - $token .= static::getPool()[static::secure_crypt(0, $max)]; + $token .= static::getPool()[static::secureCrypt(0, $max)]; } return $token; } - } diff --git a/tests/PaystackTest.php b/tests/PaystackTest.php index 9a007d3..04f7f5e 100644 --- a/tests/PaystackTest.php +++ b/tests/PaystackTest.php @@ -53,8 +53,4 @@ public function testAllPlansAreReturned() $this->assertEquals('array', gettype(array($array))); } - - - - -} \ No newline at end of file +}