Skip to content

Instantly share code, notes, and snippets.

@daveh
Last active May 24, 2024 09:21
Show Gist options
  • Save daveh/26b68e4706b2820f5f2279ccce755655 to your computer and use it in GitHub Desktop.
Save daveh/26b68e4706b2820f5f2279ccce755655 to your computer and use it in GitHub Desktop.
Simple PHP Stripe Checkout (code to accompany https://youtu.be/1KxD8J8CAFg)
<?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);
<!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>
<!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>
@Emmanue707
Copy link

Thanks man

@SR-57
Copy link

SR-57 commented Mar 26, 2024

Thank you

@antmanho
Copy link

thanks bro

@umaramin66
Copy link

thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment