F
Filament10mo ago
NolanN

Redirect to a url after action

I'm trying to create an action that will allow a user to create a new Stripe Connect account. In that workflow, an account is created first and then an account link is created and the user is redirected to complete their Stripe onboarding. I'm trying to do this utilizing the the action and url methods from the Action but I'm immediately redirected to the url when I click the button
4 Replies
NolanN
NolanNOP10mo ago
For reference, the Stripe Connect workflow I described looks something like this:
$stripe = new \Stripe\StripeClient(
config('services.stripe.secret')
);

$account = $stripe->accounts->create([
'type' => 'express',
]);

$link = $stripe->accountLinks->create([
'account' => $account,
'refresh_url' => 'http://example.test/manage',
'return_url' => 'http://example.test/manage',
'type' => 'account_onboarding',
]);

// redirect the user to the link
$stripe = new \Stripe\StripeClient(
config('services.stripe.secret')
);

$account = $stripe->accounts->create([
'type' => 'express',
]);

$link = $stripe->accountLinks->create([
'account' => $account,
'refresh_url' => 'http://example.test/manage',
'return_url' => 'http://example.test/manage',
'type' => 'account_onboarding',
]);

// redirect the user to the link
I want the user to click a button and be presented with a wizard to gather the data that will be necessary for the account creation, then create the account via the Stripe API, then finally redirect the user to the generated account link so they can finalize the onboarding process. The following code is not working but hopefully will paint a picture for what I'm trying to do:
Actions\Action::make('link')
->steps([
// gather data
])
->action(function (array $data): string {
$stripe = new \Stripe\StripeClient(
config('services.stripe.secret')
);

$account = $stripe->accounts->create([
'type' => $data['account_type'],
]);
})
->url(function (array $data): string {
$stripe = new \Stripe\StripeClient(
config('services.stripe.secret')
);

$link = $stripe->accountLinks->create([
'account' => $data['account'],
'refresh_url' => 'http://example.test/manage',
'return_url' => 'http://example.test/manage',
'type' => 'account_onboarding',
]);

return $link->url;
})
Actions\Action::make('link')
->steps([
// gather data
])
->action(function (array $data): string {
$stripe = new \Stripe\StripeClient(
config('services.stripe.secret')
);

$account = $stripe->accounts->create([
'type' => $data['account_type'],
]);
})
->url(function (array $data): string {
$stripe = new \Stripe\StripeClient(
config('services.stripe.secret')
);

$link = $stripe->accountLinks->create([
'account' => $data['account'],
'refresh_url' => 'http://example.test/manage',
'return_url' => 'http://example.test/manage',
'type' => 'account_onboarding',
]);

return $link->url;
})
Ric Le Poidevin
Ric Le Poidevin9mo ago
@NolanN Did you mange to get this to work? I have a similar issue, needing to redirect after an action
NolanN
NolanNOP9mo ago
@Ric Le Poidevin Not really. I've ended up relying on other classes to do the work and then return the relevant URL. This is a different example but this is the approach that I've been using for this sort of thing:
Actions\Action::make('link')
->label('Link Stripe account')
->url(fn (): string => (new \App\Services\StripeService)->oauthUrl())
->openUrlInNewTab(),
Actions\Action::make('link')
->label('Link Stripe account')
->url(fn (): string => (new \App\Services\StripeService)->oauthUrl())
->openUrlInNewTab(),
ericmp
ericmp9mo ago
@NolanN if u try:
->action(function (array $data): string {
$stripe = new \Stripe\StripeClient(
config('services.stripe.secret')
);

$account = $stripe->accounts->create([
'type' => $data['account_type'],
]);

$url = yoururl
$this->redirect($url);
})
->action(function (array $data): string {
$stripe = new \Stripe\StripeClient(
config('services.stripe.secret')
);

$account = $stripe->accounts->create([
'type' => $data['account_type'],
]);

$url = yoururl
$this->redirect($url);
})
it does the job?
Want results from more Discord servers?
Add your server