Redirect after Spark (v2.3.4 — STRIPE) creates a new subscription
What is the best way to redirect after a new subscription is created with the latest version of Spark?
Our use case is that we allow users to register without a card upfront, but still select a plan. We've already overriden the RegisterResponse to handle the redirect to /billing after the account is registered.
Now we would like to redirect back to the dashboard when a new subscription is created, rather than staying on the billing page.
Following the same approach as overriding the register response, we've tried adding this to SparkServiceProvider:
public function register()
{
$this->app->singleton(
\Spark\Contracts\Actions\CreatesSubscriptions::class,
\App\Actions\Spark\CreateSubscription::class
);
}
This does indeed allow us to override the CreateSubscription action. However, returning a redirect from this action doesn't do anything (the parent logic is executed and the subscription is created, though):
class CreateSubscription extends CreateSubscriptionBase
{
use HandlesPaymentFailures;
/**
* @inheritDoc
*/
public function create($billable, $plan, array $options = [])
{
parent::create($billable, $plan, $options);
return response()->redirectTo('/dashboard');
}
}
Going a step further, we tried overriding the NewSubscriptionController as well; this too did not produce the intended result.
Finally, after looking at the BillingPortal Vue component in Spark's source, it appears there is no way to handle a redirect response:
/**
* Handle a payment response and optionally redirect to the payment page.
*/
handlePaymentResponse(response) {
if (response && response.data.paymentId) {
window.location = '/' + this.$page.props.cashierPath + '/payment/' + response.data.paymentId + '?redirect=' + window.location.origin + '/' + this.$page.props.sparkPath;
} else if (response) {
this.reloadData(['nextPayment', 'plan', 'receipts', 'state', 'trialEndsAt']);
} else {
this.processing = false;
}
},
Any feedback here is greatly appreciated! Thanks!
Please or to participate in this conversation.