Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class 'Paystack' not found in Laravel 5.4 #66

Open
jgodstime opened this issue Jan 10, 2019 · 6 comments
Open

Class 'Paystack' not found in Laravel 5.4 #66

jgodstime opened this issue Jan 10, 2019 · 6 comments

Comments

@jgodstime
Copy link

I followed all the steps yet am having this error Class 'Paystack' not found.
I tried all suggestions made in this issue "Class 'Paystack' not found #52 ", but to no avail. (may be due to the fact they are using Laravel 5.6).

I also tried using
use \Unicodeveloper\Paystack\Paystack;
instead of
use Paystack
But i got this error
Non-static method Unicodeveloper\Paystack\Paystack::getAuthorizationUrl() should not be called statically

Please help...

@aeadedoyin
Copy link

aeadedoyin commented Jan 10, 2019

You need to create an instance of the class Paystack

Like this:

    use Unicodeveloper\Paystack\Paystack;
   :
   :
    public function redirectToGateway(Request $request)
    {
        $paystack = new Paystack();
        $user = Auth::user();
        $request->email = $user->email;
        $request->orderID = '3';
        $request->amount = '200000';
        $request->quantity = '1';
        $request->reference = $paystack->genTranxRef();
        $request->key = config('paystack.secretKey');
        return $paystack->getAuthorizationUrl()->redirectNow();
    }

@jgodstime
Copy link
Author

Thanks @dbkonxepts that prompted another error

(1/1) RequestException
cURL error 3: malformed (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)

in CurlFactory.php (line 186)

I will also be grateful if you can help me with a fix on this issue. Thanks Bro

@aeadedoyin
Copy link

aeadedoyin commented Jan 11, 2019

If you can send an excerpt of your code i.e in redirectToGateway or your custom pay method so I know where the error is coming from.

  1. Check to make sure your .env is appropriate filled i.e.
    PAYSTACK_PUBLIC_KEY=yourPublicKey
    PAYSTACK_SECRET_KEY=yourSecretKey
    PAYSTACK_PAYMENT_URL=https://api.paystack.co
    MERCHANT_EMAIL=yourMail (Registered on Paystack Site)
  1. Ensure you have "paystack.php" config file in your "\config\" folder with this content:
    'publicKey' => getenv('PAYSTACK_PUBLIC_KEY'),
    'secretKey' => getenv('PAYSTACK_SECRET_KEY'),
    'paymentUrl' => getenv('PAYSTACK_PAYMENT_URL'),
    'merchantEmail' => getenv('MERCHANT_EMAIL'),

However, errors at curl level like this imply some fields/variables are possibly missing in the url or it isn't all together correct.

@jgodstime
Copy link
Author

Yes 1 and 2 are very ok.
Here are my code

---- My route
Route::get('/payment', 'HomeController@paymentDisplay');
Route::post('/pay', [
'uses' => 'PaymentController@redirectToGateway',
'as' => 'pay'
]);
Route::get('/payment/callback', 'PaymentController@handleGatewayCallback');

----- My Payment Controller
public function redirectToGateway()
{
$paystack = new Paystack();
return $paystack->getAuthorizationUrl()->redirectNow();
}

public function handleGatewayCallback()

{
$paystack = new Paystack();

$paymentDetails = $paystack->getPaymentData();

dd($paymentDetails);
// Now you have the payment details,
// you can store the authorization_code in your db to allow for recurrent subscriptions
// you can then redirect or do whatever you want

}

Thanks Bro.

@jgodstime
Copy link
Author

----My view
http://prntscr.com/m63tkr

@aeadedoyin
Copy link

aeadedoyin commented Jan 12, 2019

Alright, so I have seen your code. Cool.

"Laravel Paystack" Readme/Documenation still needs some adjustments and improvements [Which I'm working on including some new boiler boilerplates, gonna do a PR soon!]; As such don't follow all you see.

Here are the changes I would employ you make.

  1. You need to pass in Request $request in your pay method i.e
    public function redirectToGateway(Request $request)
    {
        //Thats how you get the data (from your blade).
    }
  1. There are required data that needs to be loaded before a redirection to paystack site can take place.
    -Customer email, -Amount, -Reference and -Key
    All of which should be done in the pay method [For security and to avoid stress & issues]. This can be done as shown below. [Do make sure you have confirmed all configs and env] Here
    public function redirectToGateway(Request $request)
    {
        $paystack = new Paystack();
         
        // For user email
        $user = Auth::user(); // This fetches the logged in user
         
        //Initialize the required data here locally not from blade view      
        $request->email = $user->email;
        $request->amount = '200000';
        $request->reference = $paystack->genTranxRef();
        $request->key = config('paystack.secretKey');

        return $paystack->getAuthorizationUrl()->redirectNow();
    }

And that's it if you follow the steps above without missing anything you should be fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants