Last active
September 15, 2024 08:19
-
-
Save daveh/26b68e4706b2820f5f2279ccce755655 to your computer and use it in GitHub Desktop.
Simple PHP Stripe Checkout (code to accompany https://youtu.be/1KxD8J8CAFg)
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 __DIR__ . "/vendor/autoload.php"; | |
$stripe_secret_key = "your Stripe secret key here"; | |
\Stripe\Stripe::setApiKey($stripe_secret_key); | |
$checkout_session = \Stripe\Checkout\Session::create([ | |
"mode" => "payment", | |
"success_url" => "http://localhost/success.php", | |
"cancel_url" => "http://localhost/index.php", | |
"locale" => "auto", | |
"line_items" => [ | |
[ | |
"quantity" => 1, | |
"price_data" => [ | |
"currency" => "usd", | |
"unit_amount" => 2000, | |
"product_data" => [ | |
"name" => "T-shirt" | |
] | |
] | |
], | |
[ | |
"quantity" => 2, | |
"price_data" => [ | |
"currency" => "usd", | |
"unit_amount" => 700, | |
"product_data" => [ | |
"name" => "Hat" | |
] | |
] | |
] | |
] | |
]); | |
http_response_code(303); | |
header("Location: " . $checkout_session->url); |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Stripe Example</title> | |
<meta charset="UTF-8" /> | |
</head> | |
<body> | |
<h1>Stripe Example</h1> | |
<form method="post" action="checkout.php"> | |
<p>T-shirt</p> | |
<p><strong>US$20.00</strong></p> | |
<button>Pay</button> | |
</form> | |
</body> | |
</html> |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Stripe Example</title> | |
<meta charset="UTF-8" /> | |
</head> | |
<body> | |
<h1>Stripe Example</h1> | |
<p>Thank you for your payment!</p> | |
</body> | |
</html> |
Thank you
thanks bro
thank you
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks man