-
Notifications
You must be signed in to change notification settings - Fork 684
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac5ce34
commit 03b39c2
Showing
3 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!-- Create a button that your customers click to complete their purchase. Customize the styling to suit your branding. --> | ||
<button | ||
style="background-color:#6772E5;color:#FFF;padding:8px 12px;border:0;border-radius:4px;font-size:1em" | ||
id="checkout-{{ $sessionId }}" | ||
role="link" | ||
> | ||
{{ $label }} | ||
</button> | ||
|
||
<div id="error-message"></div> | ||
|
||
<script> | ||
var checkoutButton = document.getElementById('checkout-{{ $sessionId }}'); | ||
checkoutButton.addEventListener('click', function () { | ||
// When the customer clicks on the button, redirect them to Checkout. | ||
Stripe('{{ $stripeKey }}').redirectToCheckout({ | ||
sessionId: '{{ $sessionId }}' | ||
}).then(function (result) { | ||
// If `redirectToCheckout` fails due to a browser or network | ||
// error, display the localized error message to your customer | ||
// using `result.error.message`. | ||
}); | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace Laravel\Cashier; | ||
|
||
use Stripe\Checkout\Session; | ||
use Illuminate\Support\Facades\View; | ||
|
||
class Checkout | ||
{ | ||
/** | ||
* @var \Illuminate\Database\Eloquent\Model | ||
*/ | ||
protected $owner; | ||
|
||
/** | ||
* @var \Stripe\Checkout\Session | ||
*/ | ||
protected $session; | ||
|
||
/** | ||
* Create a new Checkout instance. | ||
* | ||
* @param \Illuminate\Database\Eloquent\Model $owner | ||
* @param \Stripe\Checkout\Session $session | ||
* @return void | ||
*/ | ||
public function __construct($owner, Session $session) | ||
{ | ||
$this->owner = $owner; | ||
$this->session = $session; | ||
} | ||
|
||
/** | ||
* Get the View instance for the button. | ||
* | ||
* @param string $label | ||
* @param array $options | ||
* @return \Illuminate\Contracts\View\View | ||
*/ | ||
public function button($label = 'Checkout', array $options = []) | ||
{ | ||
return View::make('cashier::checkout', array_merge($options, [ | ||
'label' => $label, | ||
'stripeKey' => Cashier::stripeKey(), | ||
'sessionId' => $this->session->id, | ||
])); | ||
} | ||
|
||
/** | ||
* @return \Stripe\Checkout\Session | ||
*/ | ||
public function asStripeCheckoutSession() | ||
{ | ||
return $this->session; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters