Skip to content

UI mode 'custom' is not working when creating checkout session #1780

@mirkoappy

Description

@mirkoappy

Cashier Stripe Version

16.0.1

Laravel Version

12.8.1

PHP Version

8.4.4

Database Driver & Version

MySQL Ver 8.4.4 for Linux on aarch64 (Source distribution)

Description

Laravel Cashier doesn't not support ui_mode set to custom. It handles that as hosted mode.

Issue seems to be with create method in Checkout class with the code:

if (isset($data['ui_mode']) && $data['ui_mode'] === 'embedded') {
    $data['return_url'] = $sessionOptions['return_url'] ?? route('home');

    // Remove return URL for embedded UI mode when no redirection is desired on completion...
    if (isset($data['redirect_on_completion']) && $data['redirect_on_completion'] === 'never') {
        unset($data['return_url']);
    }
} else {
    $data['success_url'] = $sessionOptions['success_url'] ?? route('home').'?checkout=success';
    $data['cancel_url'] = $sessionOptions['cancel_url'] ?? route('home').'?checkout=cancelled';
}

It should be changed to:

if (isset($data['ui_mode']) && ($data['ui_mode'] === 'embedded' || $data['ui_mode'] === 'custom')) {
    $data['return_url'] = $sessionOptions['return_url'] ?? route('home');

    // Remove return URL for embedded UI mode when no redirection is desired on completion...
    if (isset($data['redirect_on_completion']) && $data['redirect_on_completion'] === 'never' && $data['ui_mode'] === 'embedded') {
        unset($data['return_url']);
    }
} else {
    $data['success_url'] = $sessionOptions['success_url'] ?? route('home').'?checkout=success';
    $data['cancel_url'] = $sessionOptions['cancel_url'] ?? route('home').'?checkout=cancelled';
}

Steps To Reproduce

Try to initiate checkout with

$checkout = $user->checkout(['price_1SC...'], [
    'ui_mode' => 'custom',
    'return_url' => $this->returnUrl,
]);

If you have no 'home' route defined it will throw an error "Route [home] not defined."
If there is 'home' route defined, it will throw an error "The following parameters are not supported with 'ui_mode: custom': cancel_url, success_url."

Expected behaviour would be to return Stripe session object.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions