Created
December 11, 2020 19:11
-
-
Save cjavilla-stripe/872a3509c902ec32a8cef82b39d8e0b8 to your computer and use it in GitHub Desktop.
Simple one button Checkout with php
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
<?php | |
require_once('vendor/autoload.php'); | |
\Stripe\Stripe::setApiKey('sk_test_...'); | |
$session = \Stripe\Checkout\Session::create([ | |
'payment_method_types' => ['card'], | |
'line_items' => [[ | |
'price_data' => [ | |
'currency' => 'usd', | |
'product_data' => [ | |
'name' => 'T-shirt', | |
], | |
'unit_amount' => 2000, | |
], | |
'quantity' => 1, | |
]], | |
'mode' => 'payment', | |
'success_url' => 'http://localhost:4242/success', | |
'cancel_url' => 'http://example.com/cancel', | |
]); | |
?> | |
<html> | |
<head> | |
<title>Buy cool new product</title> | |
<script src="https://js.stripe.com/v3/"></script> | |
</head> | |
<body> | |
<button id="checkout-button">Checkout</button> | |
<script> | |
var stripe = Stripe('pk_test_vAZ3gh1LcuM7fW4rKNvqafgB00DR9RKOjN'); | |
const btn = document.getElementById("checkout-button") | |
btn.addEventListener('click', function(e) { | |
e.preventDefault(); | |
stripe.redirectToCheckout({ | |
sessionId: "<?php echo $session->id; ?>" | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
obi1arena
commented
Mar 11, 2023
via email
The github session. Are you attending it now?
On Friday, March 10, 2023 at 02:23:06 AM CST, Satoru Morishima ***@***.***> wrote:
Re: ***@***.*** commented on this gist.
What does $session->id refer to?
—
Reply to this email directly, view it on GitHub or unsubscribe.
You are receiving this email because you commented on the thread.
Triage notifications on the go with GitHub Mobile for iOS or Android.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment