Open jgodstime opened 5 years ago
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();
}
Thanks @dbkonxepts that prompted another error
(1/1) RequestException
cURL error 3:
in CurlFactory.php (line 186)
I will also be grateful if you can help me with a fix on this issue. Thanks Bro
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.
PAYSTACK_PUBLIC_KEY=yourPublicKey
PAYSTACK_SECRET_KEY=yourSecretKey
PAYSTACK_PAYMENT_URL=https://api.paystack.co
MERCHANT_EMAIL=yourMail (Registered on Paystack Site)
'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.
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.
----My view http://prntscr.com/m63tkr
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.
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).
}
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.
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...