Skip to content

Commit

Permalink
Server side Checkout redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvints committed Jul 8, 2021
1 parent 638f4d8 commit 9d10c83
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Contracts\Support\Jsonable;
use Illuminate\Contracts\Support\Responsable;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\View;
use JsonSerializable;
use Stripe\Checkout\Session;
use Symfony\Component\HttpFoundation\Response;

class Checkout implements Arrayable, Jsonable, JsonSerializable
class Checkout implements Arrayable, Jsonable, JsonSerializable, Responsable
{
/**
* The Stripe model instance.
Expand Down Expand Up @@ -66,6 +69,7 @@ public static function create($owner, array $sessionOptions = [], array $custome
* @param string $label
* @param array $options
* @return \Illuminate\Contracts\View\View
* @deprecated Use the redirect method instead.
*/
public function button($label = 'Check out', array $options = [])
{
Expand All @@ -76,6 +80,27 @@ public function button($label = 'Check out', array $options = [])
], $options));
}

/**
* Redirect to the checkout session.
*
* @return \Illuminate\Http\RedirectResponse
*/
public function redirect()
{
return Redirect::to($this->session->url, Response::HTTP_SEE_OTHER);
}

/**
* Create an HTTP response that represents the object.
*
* @param \Illuminate\Http\Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function toResponse($request)
{
return $this->redirect();
}

/**
* Get the Checkout Session as a Stripe Checkout Session object.
*
Expand Down

0 comments on commit 9d10c83

Please sign in to comment.