Skip to content

Instantly share code, notes, and snippets.

@maboelfotoh
Last active November 4, 2021 14:57
Show Gist options
  • Save maboelfotoh/e3eaab952ce3465a8a6cb3c187bca2c0 to your computer and use it in GitHub Desktop.
Save maboelfotoh/e3eaab952ce3465a8a6cb3c187bca2c0 to your computer and use it in GitHub Desktop.
Stripe callback handler sample PHP code (payment charge callback message demo)
<?php
$inputJSON = file_get_contents('php://input');
$input = json_decode($inputJSON);
if(null == $input || false == $input) {
// this shouldn't happen
header('HTTP/1.1 200 OK');
die();
}
$chargesdata = $input->data->object;
// e.g. "charge"
$object = $chargesdata->object;
// amount in pennies
$amount = $chargesdata->amount;
// e.g. "succeeded"
$status = $chargesdata->status;
// true/false
$paid = $chargesdata->paid;
$payment_intent = $chargesdata->payment_intent;
header('HTTP/1.1 200 OK');
if($object === "charge" && $paid && $status === "succeeded") {
echo '{"result":"charge succeeded"}';
$amount = $amount/100;
// do something with {payment charge success, amount, payment intent} info,
// e.g. store client payment confirmation and amount in database
} else echo '{}';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment