Last active
November 4, 2021 14:57
-
-
Save maboelfotoh/e3eaab952ce3465a8a6cb3c187bca2c0 to your computer and use it in GitHub Desktop.
Stripe callback handler sample PHP code (payment charge callback message demo)
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 | |
$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