laravel / cashier-stripe

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.
https://laravel.com/docs/billing
MIT License
2.37k stars 670 forks source link

Return Stripe checkout URL from checkout method #1636

Closed sts-ryan-holton closed 7 months ago

sts-ryan-holton commented 7 months ago

Cashier Stripe Version

15.2.0

Laravel Version

10.41.0

PHP Version

8.2.*

Database Driver & Version

MySQL

Description

I'd like to migrate my subscription checkout process over to the Stripe checkout for better maintainability. My Laravel project serves as an API for a Nuxt JS front-end, this means I need to return the URL of the Stripe checkout to redirect the user to in my axios response in my front-end.

The checkout method appears to do something with the redirect method as I see a 303 response code in my browser. I've tried attaching the toResponse method to just get the URL with no luck.

I just need some guidance in returning a URL from the checkout method please here:

Steps To Reproduce

$subscription->create($request->input('token'), [], $subscriptionOptions);

return $subscription->checkout([
    'success_url' => 'http://localhost:3005/account/subscriptions/',
    'cancel_url' => 'http://localhost:3005/account/subscriptions/',
])->toResponse($request);
crynobone commented 7 months ago

Hi there,

Thanks for reporting the problem you are encountering, but it looks like this is a question which may be better suited for a support channel. We only use this issue tracker for reporting bugs with the library itself. If you have a question on how to use functionality provided by this repository you can try one of the following channels:

However, this issue will not be locked and everyone is still free to discuss solutions to your problem!

Thanks.

sts-ryan-holton commented 7 months ago

Duplicated over to: https://github.com/laravel/framework/discussions/49801

sts-ryan-holton commented 7 months ago

Just wondering if anyone from the Cashier team is able to point me in the right direction here? I don't know the codebase or methods, you guys do 🤣

stuartcusackie commented 4 months ago

A toArray() function is available on the Checkout class. It contains a url to stripe checkout.

I haven't used it yet but I'll find out how useful it is soon.

sts-ryan-holton commented 4 months ago

@stuartcusackie That's what I ended up using. My front-end is separated from the backend. Turns out the checkout method returns a url key that I can use Arr::get() to redirect to. Didn't even need the toResponse()