Skip to content

Instantly share code, notes, and snippets.

Created Apr 23, 2020
What would you like to do?
Stripe example PHP code
require 'vendor/autoload.php';
// This is a sample test API key. Sign in to see examples pre-filled with your key.
# retrieve JSON from POST body
header('Content-Type: application/json');
$json_str = file_get_contents('php://input');
$json_obj = json_decode($json_str);
function calculateOrderAmount($items) {
// Replace this constant with a calculation of the order's amount
// Calculate the order total on the server to prevent
// customers from directly manipulating the amount on the client
return 1400;
$paymentIntent = \Stripe\PaymentIntent::create([
'amount' => calculateOrderAmount($json_obj->items),
'currency' => 'usd',
$output = [
'clientSecret' => $paymentIntent->client_secret,
echo json_encode($output);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment