Closed olayemii closed 5 years ago
Hi Olayemii, don't call the method (Paystack::genTranxRef()
) in your blade, do it in your controller.
i.e. Remove this line from your blade :- <input type="hidden" name="reference" value="{{ Unicodeveloper\Paystack\Paystack::genTranxRef() }}">
Then do this.
In your controller make sure you are importing.
use Paystack;
and not
use Unicodeveloper\Paystack\Paystack;
Then in your pay method i.e
public function redirectToGateway(Request $request)
{
:
:
$request->reference = Paystack::genTranxRef();
:
return Paystack::getAuthorizationUrl()->redirectNow();
}
Hi Olayemii,
- In your controller make sure you are importing.
use Paystack;
and notuse Unicodeveloper\Paystack\Paystack;
- Then in your pay method i.e
public function redirectToGateway(Request $request) { : : $request->reference = Paystack::genTranxRef(); : return Paystack::getAuthorizationUrl()->redirectNow(); }
using use Paystack
causes Class 'Paystack' not found
Alright, it means you didn't register the Facade and Provider
To do this, open the app.php
file in config\ folder, scroll down to aliases
section and append like so:
'providers' => [
...
Unicodeveloper\Paystack\PaystackServiceProvider::class,
...
],
'aliases' => [
...
'Paystack' => Unicodeveloper\Paystack\Facades\Paystack::class,
...
]
Alright, it means you didn't register the Facade. To do this, open the
app.php
file in config\ folder, scroll down toaliases
section and append like so:'aliases' => [ ... 'Paystack' => Unicodeveloper\Paystack\Facades\Paystack::class, ... ]
Adding that and changing all use Unicodeveloper\Paystack\Facades\Paystack
to use Paystack
gives class laravel-paystack not found
. the docs says that step should be skipped for laravel versions above 5.5 ..or not?
Ignore the doc. It shouldn't be skipped.
If you use Unicodeveloper\Paystack\Paystack;
then you would have to create an instance whenever you need to call the Paystack class i.e $paystack = new Paystack();
because the methods are not static.
However you can avoid the whole instance thing, (that's one of the reason for the "Facade" keys) by adding the alias as I have sent it. Then in anywhere you can call
Paystack::functionName()
instead of
$paystack = new Paystack();
$paystack->functionName();
Ignore the doc. It shouldn't be skipped.
If you
use Unicodeveloper\Paystack\Paystack;
then you would have to create an instance whenever you need to call the Paystack class i.e$paystack = new Paystack();
because the methods are not static.However you can avoid the whole instance thing, (that's one of the reason for the "Facade" keys) by adding the alias as I have sent it. Then in anywhere you can call
Paystack::functionName()
instead of
$paystack = new Paystack();
$paystack->functionName();
Fixed it using your method, i just needed to register the provider. Having a whole new different error though.
Feel free to drop it. Always happy to help.
I keep getting this error
Non-static method Unicodeveloper\Paystack\Paystack::genTranxRef() should not be called statically
when i try setting up the library according to its doc This is what gives the error<input type="hidden" name="reference" value="{{ Unicodeveloper\Paystack\Paystack::genTranxRef() }}">
Am trying this on Laravel 5.7