我正在尝试在我的应用程序中实现条带支付网关。 一切都适用于静态付款,即55美元或5美元或任何其他金额。但是我想创建基于小时和小时费率动态收费的应用程序。当我写下我的逻辑并尝试过它时,给我看了一个类似的错误。
Fatal error: Uncaught exception 'Stripe\Error\InvalidRequest' with message 'Invalid integer: $price' in C:\wamp64\www\PROJECT\stripe-php\lib\ApiRequestor.php:120 from API request 'req_jN42fBMzXZqjVB' in C:\wamp64\www\PROJECT\stripe-php\lib\ApiRequestor.php on line 120
( ! ) Stripe\Error\InvalidRequest: Invalid integer: $price in C:\wamp64\www\PROJECT\stripe-php\lib\ApiRequestor.php on line 120
下面是我的文件代码:
<?php
if(!isset($_SESSION))
{
session_start();
}
require_once ('dbconfigpdo.php');
print_r($_SESSION);
$parkingslot= $_SESSION["parkingslot"];
$booking_start = $_SESSION["booking_start"];
$booking_end = $_SESSION["booking_end"];
$booking_start_time = $_SESSION["booking_start_time"];
$booking_end_time = $_SESSION["booking_end_time"];
//$price = $_SESSION['price'];
$a = new DateTime($booking_start_time);
$b = new DateTime($booking_end_time);
$interval = $a->diff($b);
echo $duration=$interval->format("%H");
var_dump($duration);
$price = 3 * $duration;
echo $duration;
echo $price;
//echo "$booking_end";
//check whether stripe token is not empty
if(!empty($_POST['stripeToken'])){
//get token, card and user info from the form
$token = $_POST['stripeToken'];
$name = $_POST['name'];
$email = $_POST['email'];
$card_num = $_POST['card_num'];
$card_cvc = $_POST['cvc'];
$card_exp_month = $_POST['exp_month'];
$card_exp_year = $_POST['exp_year'];
//include Stripe PHP library
require_once('stripe-php\init.php');
//set api key
$stripe = array(
"secret_key" => "sk_test_yzsJAYlaZBO5SUcoga067K1s",
"publishable_key" => "pk_test_ApEdDkstpR0xRuASqSbz0fn9"
);
\Stripe\Stripe::setApiKey($stripe['secret_key']);
//add customer to stripe
$customer = \Stripe\Customer::create(array(
'email' => $email,
'source' => $token
));
//item information
$itemName = $parkingslot;
$itemNumber = $parkingslot;
$itemPrice = $price;
$currency = "CAD";
$orderID = rand();
//charge a credit or a debit card
$charge = \Stripe\Charge::create(array(
'customer' => $customer->id,
'amount' => $itemPrice,
'currency' => $currency,
'description' => $itemName,
'metadata' => array(
'order_id' => $orderID
)
));
//retrieve charge details
$chargeJson = $charge->jsonSerialize();
//check whether the charge is successful
if($chargeJson['amount_refunded'] == 0 && empty($chargeJson['failure_code']) && $chargeJson['paid'] == 1 && $chargeJson['captured'] == 1){
//order details
$amount = $chargeJson['amount'];
$balance_transaction = $chargeJson['balance_transaction'];
$currency = $chargeJson['currency'];
$status = $chargeJson['status'];
$date = date("Y-m-d H:i:s");
//include database config file
include_once 'dbConfig1.php';
//insert tansaction data into the database
$sql = "INSERT INTO orders(name,email,card_num,card_cvc,card_exp_month,card_exp_year,item_name,item_number,item_price,item_price_currency,paid_amount,paid_amount_currency,txn_id,payment_status,created,modified) VALUES('".$name."','".$email."','".$card_num."','".$card_cvc."','".$card_exp_month."','".$card_exp_year."','".$itemName."','".$itemNumber."','".$itemPrice."','".$currency."','".$amount."','".$currency."','".$balance_transaction."','".$status."','".$date."','".$date."')";
$insert = $db->query($sql);
$last_insert_id = $db->insert_id;
//if order inserted successfully
if($last_insert_id && $status == 'succeeded'){
$sql="UPDATE `fleming_dwing` SET `Status` = 'RESERVED' WHERE `ParkingSlotNo`=$parkingslot";
$st=$conn->prepare($sql);
$st->execute();
$statusMsg = "<h2>The transaction was successful.</h2><h4>Order ID: {$last_insert_id}</h4>";
}else{
$statusMsg = "Transaction has been failed";
}
}else{
$statusMsg = "Transaction has been failed";
}
}else{
$statusMsg = "Form submission error.......";
}
//show success or error message
echo $statusMsg;
&GT?; 我认为在为条带付款变量分配值时我犯了一些错误。 请帮帮我。