Using Url::to in a controller?

Hi,

I’m trying to integrate Stripe to my web-app. In order to do so I need a success_url and an cancel_url.
I have to pass it like this :

$checkout_session = \Stripe\Checkout\Session::create([
        'success_url' => url,
        ...
...])

But as I already am in a Controller (let’s call it PaymentController) I guess that I need to access this Url differently than usually because a Url::to(‘controller/action’) does not work. Also I’m developing on local but the Stripe API needs an http url.

If you have an idea of how I should proceed let me know.

Thank you.

It should always work. How exactly it doesn’t work?

Actually it works but what I want it to return is something like “http://localhost/html/my-site/…” but what I get with Url::to() is something like “/html/my-site/…” and I want it to also work in a production server.

I guess the second parameter is what you need
https://www.yiiframework.com/doc/api/2.0/yii-helpers-baseurl#to()-detail

1 Like

Thanks that’s it, I forgot there was a second argument to this function :smile: