Paying my account works fine. But now I want to catch from the database

I am using Stripe Payment. I have enabled Stripe validation system on my php website. With Static prices, it works well. But I don't want to get prices from my database. And it shows on the screen that it is charged. But in my lane account, it doesn't send money.

$charge = Stripe_Charge::create(array(
  "amount" => 999999, // I want here $price from my database.
  "currency" => "usd",
  "card" => $_POST['stripeToken'],
  "description" => 'This is Different Thing'
));

      

When I add $price

instead of a static price 99999

, it doesn't send money to my lane payments. But when I add 99999 again it starts working. My database is fine. All checks and connections to the database are fine. The problem is only here .. How can I fix it .. If you want my complete code.

include 'header.php';  //Connection File is in header.php
error_reporting(0);
try {

    require_once('Stripe/lib/Stripe.php');
    Stripe::setApiKey("sk_test_GkvxX3TWD6juGRLhZwP2LQ1x");

$req_id = $_REQUEST['order_id'];
$get_req = "SELECT * FROM `requests` WHERE `req_id` = '$req_id'";
$result = mysqli_query($dbc, $get_req);
while($row = mysqli_fetch_array($result)){
$req_id = $row['req_id'];
$request_title = $row['request_title'];
$username = $row['username'];
$user_id = $row['user_id'];
$price = $row['price'];
$request_time = $row['request_time'];
$req_date = $row['req_date'];
$category = $row['category'];
$sub_category = $row['sub_category'];
$from_address = $row['from_address'];
$to_address = $row['to_address'];
$from_state = $row['from_state'];
$to_state = $row['to_state'];
$from_city = $row['from_city'];
$to_city = $row['to_city'];
$req_desc = $row['req_desc'];
$status = $row['req_status'];

$paid = $row['paid'];

}

$charge = Stripe_Charge::create(array(
  "amount" => 999999,
  "currency" => "usd",
  "card" => $_POST['stripeToken'],
  "description" => 'This is Different Thing'
));


$status = "";
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $errors = array();


    if (isset($_POST['stripeToken'])) {
        $token = $_POST['stripeToken'];
        echo 'Payment Done ';

$status = 1;



//print_r($token);
    } else {
        $errors['token'] = 'The order cannot be processed. You have not been charged.
                            Please confirm that you have JavaScript enabled and try again.';
echo "payment not successfully done.Please try again";
$status = 0;
    }
} // End of form submission conditional.




}
catch(Stripe_CardError $e) {

}

//catch the errors in any way you like

 catch (Stripe_InvalidRequestError $e) {
  // Invalid parameters were supplied to Stripe API

} catch (Stripe_AuthenticationError $e) {
  // Authentication with Stripe API failed
  // (maybe you changed API keys recently)

} catch (Stripe_ApiConnectionError $e) {
  // Network communication with Stripe failed
} catch (Stripe_Error $e) {

  // Display a very generic error to the user, and maybe send
  // yourself an email
} catch (Exception $e) {

  // Something else happened, completely unrelated to Stripe
}

if($status2 = 1){
$query = "UPDATE `requests` SET `req_status`='1', `paid`='1' WHERE `req_id`='$req_id'";
$result = mysqli_query($dbc,$query);
}else{ 


}

      

+3


source to share


1 answer


I haven't seen in your code what the $ price output is. So, while I do this, don't assume that the $ price taken from your database is incorrectly prepared, this is as stated in the Stripe documentation, which is needed to express the price in cents. Thus if you put this code

$findme = ".";
$pos = strpos($price, $findme);
$PosPlus = $pos+1;
$Part1=substr($price, 0, $pos);
$Part2=substr($price, $PosPlus);
$price = ($Part1.$Part2);

      

over your line,



$charge = Stripe_Charge::create(array(   //.....

      

your payment must succeed.

0


source







All Articles