Where Do I Call The "payment Was Successful" Message From?
I have integrated Stripe into my site. The code below is copied directly from stripe's documentation. Although there are minor differences between this code and my implementation,
Solution 1:
Just figured it out shortly after posting.
First I noticed that $charge
is an output in this context, so I ran echo var_dump($charge);
which opened up a massive wealth of information.
Rather than look at it there, I can find the api reference here, scroll down to "The Charge Object". Within that, status
(relating to $charge['status']
) can confirm if it was successful or not.
The working code if($charge['status'] === "succeeded"){}
is the correct place to put a success message.
Solution 2:
try{
require'vendor/autoload.php';
\Stripe\Stripe::setApiKey("<test key here>");
$token = $_POST['stripeToken'];
$charge = \Stripe\Charge::create([
'amount' => 999,
'currency' => 'aud',
'description' => 'Example charge',
'source' => $token,
]);
if(isset($charge->id) && $charge->id != ''){
echo"Payment has been made successful, Transaction ID : ".$charge->id;exit;
}
} catch (\Stripe\Error\Base $e) {
echo"Something went wrong with payment, Note : ".$e->getMessage();exit;
}
Post a Comment for "Where Do I Call The "payment Was Successful" Message From?"