unicodeveloper / laravel-paystack

:credit_card: :package: :moneybag: Laravel 6, 7, 8, 9, 10 and 11 Package for Paystack
https://paystack.co
MIT License
605 stars 312 forks source link

Any body experience this exception "URI must be a string or UriInterface" #57

Closed strategicdots closed 4 years ago

strategicdots commented 6 years ago

The app has been throwing this error for a while. If I comment out this line in the form <input type="hidden" name="reference" value="{{ Paystack::genTranxRef() }}"> it works fine but throws that same error on the PaymentController@redirectToGateway controller.

I search and realized it has to do with Guzzle, anyway to bypass this exception?

Emmanuel96 commented 5 years ago

Hi @strategicdots did you ever figure out the solution to this error? I'm currently experiencing it and I don't know how to deal with it.

nensok commented 5 years ago

Hi i'm also experiencing the same problem, any solution?

strategicdots commented 5 years ago

@Emmanuel96 and @nensok , I updated my packages using composer update (this is after I added "unicodeveloper/laravel-paystack": "1.0.*" to my composer.json file of course) and it worked.

Try that and let's see

AaronVikta commented 5 years ago

I assume you have already done the installation of the package and added paystack.php manually and populated config:app, with the provider and alliases to get this error, if not do so. now this is what worked for me:

  1. run composer update
  2. after the update run config:cache and you are good to go
aeadedoyin commented 5 years ago

I would advise you do "sensitive" Paystack data initialization in the controller.

    public function redirectToGateway(Request $request)
    {
        // computed amount -> $amount;

        $paystack = new Paystack();
        $user = Auth::user();
        $request->email = $user->email;
        $request->amount = $amount;
        $request->reference = $paystack->genTranxRef();
        $request->key = config('paystack.secretKey');

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

And then in your web.php do the needful routing.

shoutershub commented 5 years ago
  1. try t o Install Guzzle HTTP client , the latest version, if you don't have this, Laravel would fall back to crul as its default HTTP client, which might result to a totally different problem of certification or MalFormed URL especially if you are using an older version of XAMPP or WAMPP

So install Guzzle Then run run composer update after the update run config:cache and you are good to go

Pauloo101 commented 5 years ago

Hi guys ... so i used dis package worked perfectly on my local server buh when i deployed it i get the "URI must be a string or UriInterface"... i currently dont know how to fix it ...

ghost commented 5 years ago

I would advise you do "sensitive" Paystack data initialization in the controller.

    public function redirectToGateway(Request $request)
    {
        // computed amount -> $amount;

        $paystack = new Paystack();
        $user = Auth::user();
        $request->email = $user->email;
        $request->amount = $amount;
        $request->reference = $paystack->genTranxRef();
        $request->key = config('paystack.secretKey');

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

And then in your web.php do the needful routing.

@aeadedoyin any sample on how you can pass ur form datails to Paystack. With your approach which is passing the datails from your controller to Paystack, After which in view page, we just create an empty form with submit button to pass the details to Paystack. Is this a good implementation and would it work fine?
<form method="POST" action="{{ route('agentPay') }}" accept-charset="UTF-8" class="form-horizontal" role="form"> {{ csrf_field() }} <button class="btn btn-success btn-lg btn-block" type="submit" value="Pay Now!"> <i class="fa fa-plus-circle fa-lg"></i> Pay Now! </button> </form>

aeadedoyin commented 5 years ago

@Akhibemudu Alright, you see the redirectToGateway(Request $request) method is where all the magic takes place. the amount, email, reference, and key are the required fields you need to pass to the request before it can go through.

In web.php here's a sample route to be able to call route('agentPay') from the 'Pay Now' button in your code.

Route::post('/land/{id}/pay', 'PagesController@redirectToGateway')->name('agentPay');

ghost commented 5 years ago

@aeadedoyin Please have you encountered this error before? Client error:POST https://api.paystack.co/transaction/initializeresulted in a401 Unauthorizedresponse: { "status": false, "message": "Invalid key" } Note: I have updated my .env file, i have also set the callback url to response

shoutershub commented 5 years ago

if you are certain your API Keys are correctly placed, because this might seem to be the possible reason, maybe you should try clearing config cache php artisan config:cache and php artisan cache:clear

ghost commented 5 years ago

yea @shoutershub I did that several times and I ended up getting the same error message. So I switched to Rave but would have preferred to use Paystack since it supports international payment. Any assistance on this @unicodeveloper

codenaz commented 5 years ago

There are a lot of open issues and PRs on this package. I don’t know if it’s still being maintained. The paystack official doc is well detailed and you can implement anything you want with few lines of code. Since there is really no update happening on this package just consume the paystack API with guzzle.

rapsonwalex commented 5 years ago

Hi guys ... so i used dis package worked perfectly on my local server buh when i deployed it i get the "URI must be a string or UriInterface"... i currently dont know how to fix it ...

@Pauloo101 i experienced this same issue and it took me three days to discover that i didn't update my .env with paystack details in production server (in deployment) as shown below. hope this help someone.

PAYSTACK_PUBLIC_KEY=xxxxxxxxxxxxxxxx PAYSTACK_SECRET_KEY=xxxxxxxxxxxxxxxxx PAYSTACK_PAYMENT_URL=https://api.paystack.co MERCHANT_EMAIL=unicodeveloper@gmail.com

aremu-smog commented 4 years ago

You will most likely experience this issue on a live server. Here is how to fix

  1. Remove '.env' from .gitignore file
  2. Update your Paystack details in .env
  3. Add, Commit and Push the updates to your live server
  4. Readd '.env' to .gitignore
  5. Add, Commit and Push the changes to your live server

Explanation The reason you are seeing this error is due to the fact that you added Paystack details after publishing your website to a live server since .env is in gitignore file, it means that the changes you make are not tracked on the live server. So by removing .env from the gitignore file, the changes can now be tracked an effected. You can also decide to readd .env to gitignore after your changes take effect.

odutolaabisoye commented 4 years ago

@aremu-smog This is a wrong approach. You don't expose your env file like that and not all server will recognize your env file. If you using Google cloud, you will need app.yaml file. If your using heroku you have to write your configuration in your configvar

aremu-smog commented 4 years ago

Thanks a lot for this @odutolaabisoye. It would be nice to know a better approach to resolve this particular issue though because I battled this for over a week before trying that approach.

odutolaabisoye commented 4 years ago

Which server are you using?

aremu-smog commented 4 years ago

heroku

On Mon, 16 Mar 2020 at 12:04, odutolaabisoye notifications@github.com wrote:

Which server are you using?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/unicodeveloper/laravel-paystack/issues/57#issuecomment-599474985, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALP3ZWUAGSAULZ72WPM6OY3RHYBS7ANCNFSM4FPRN3FA .

--

odutolaabisoye commented 4 years ago

Goto Settings -> Config Vars -> Reveal Config Vars -> Add your confugurations

aremu-smog commented 4 years ago

Thanks a lot for this.

godfredakpan commented 2 years ago

if you are still facing this issue, the simplest way is to remove <input type="hidden" name="reference" value="{{ Paystack::genTranxRef() }}"> from your blade and generate the reference on your controller using this $reference = Paystack::genTranxRef();. Then you are good.

benjamintemitope commented 2 years ago

Hi guys ... so i used dis package worked perfectly on my local server buh when i deployed it i get the "URI must be a string or UriInterface"... i currently dont know how to fix it ...

@Pauloo101 i experienced this same issue and it took me three days to discover that i didn't update my .env with paystack details in production server (in deployment) as shown below. hope this help someone.

PAYSTACK_PUBLIC_KEY=xxxxxxxxxxxxxxxx PAYSTACK_SECRET_KEY=xxxxxxxxxxxxxxxxx PAYSTACK_PAYMENT_URL=https://api.paystack.co MERCHANT_EMAIL=unicodeveloper@gmail.com

This solved my problem.

Thanks!

smarts8855 commented 1 year ago

URI must be a string or UriInterface I have been facing this error and have tried different solution it keep show this error I need help to solve this pls