Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将金额设置为$variable_Javascript_Php_Stripe Payments - Fatal编程技术网

Javascript 将金额设置为$variable

Javascript 将金额设置为$variable,javascript,php,stripe-payments,Javascript,Php,Stripe Payments,我正在使用条带支付,我正在尝试将金额设置为一个变量。我看到有很多关于这个的问题,但我一直没有找到答案 在页面顶部,我查询数据库中的a数字,并做一些基本的数学运算来设置数量。我重复成本,只是为了确保它正常工作。这是代码 require_once('../stripe/lib/Stripe.php'); require_once("../auth/config.class.php"); require_once("../auth/auth.class.php");

我正在使用条带支付,我正在尝试将金额设置为一个变量。我看到有很多关于这个的问题,但我一直没有找到答案

在页面顶部,我查询数据库中的a数字,并做一些基本的数学运算来设置数量。我重复成本,只是为了确保它正常工作。这是代码

require_once('../stripe/lib/Stripe.php');
        require_once("../auth/config.class.php");
        require_once("../auth/auth.class.php");

        $config = new Config;

        $dbh = new PDO("mysql:host={$config->dbhost};dbname={$config->dbname}", $config->dbuser,     $config->dbpass);
        $auth = new Auth($dbh, $config);

        $id= $_GET['rid'];

        $query = $dbh->prepare("SELECT hours FROM svcrequest WHERE id=? ");
        $query->execute(array($id));    
        $rslt = $query->fetch(PDO::FETCH_ASSOC);
        $cost    = ($rslt[hours] * 27)*100;
        echo $cost;
然后,我尝试将成本分配给某个if语句和异常中的另一个变量金额,并尝试响应金额,但什么也得不到

// Set the order amount somehow:
        $amount  = $cost; //  in cents
        echo $amount;
        $email       = "info@intelycare.com";
        $description = "Jane Doe"; //customer
当我
echo$amount
时,什么也不显示。这里是页面的完整代码。我需要一些帮助

<?php 
// Created by Larry Ullman, www.larryullman.com, @LarryUllman
// Posted as part of the series "Processing Payments with Stripe"
// http://www.larryullman.com / series / processing - payments - with - stripe /
// Last updated February 20, 2013
// The class names are based upon Twitter Bootstrap (http://twitter.github.com / bootstrap / )

// This page is used to make a purchase.

// Every page needs the configuration file:


// Uses sessions to test for duplicate submissions:
session_start();

?><!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>
            IntelyCare
        </title>
        <script type="text/javascript" src="https://js.stripe.com/v2/"> </script>
        <script src="http://code.jquery.com/jquery-1.11.1.min.js">  </script>
        <script src="http://code.jquery.com/mobile/1.4.3/jquery.mobile-1.4.3.min.js"> </script>
    </head>
    <body>
        <?php
            require_once('../stripe/lib/Stripe.php');
            require_once("../auth/config.class.php");
            require_once("../auth/auth.class.php");

            $config = new Config;

            $dbh = new PDO("mysql:host={$config->dbhost};dbname={$config->dbname}", $config->dbuser,     $config->dbpass);
            $auth = new Auth($dbh, $config);

            $id= $_GET['rid'];

            $query = $dbh->prepare("SELECT hours FROM svcrequest WHERE id=? ");
            $query->execute(array($id));    
            $rslt = $query->fetch(PDO::FETCH_ASSOC);
            $cost    = ($rslt[hours] * 27)*100;
            echo $cost;



        // Set the Stripe key:
        // Uses STRIPE_PUBLIC_KEY from the config file.
        echo '<script type="text/javascript">Stripe.setPublishableKey("' . STRIPE_PUBLIC_KEY . '");</script>';

        // Check for a form submission:
        if($_SERVER['REQUEST_METHOD'] == 'POST')
        {

            // Stores errors:
            $errors = array();

            // Need a payment token:
            if(isset($_POST['stripeToken']))
            {

                $token = $_POST['stripeToken'];

                // Check for a duplicate submission, just in case:
                // Uses sessions, you could use a cookie instead.
                if(isset($_SESSION['token']) && ($_SESSION['token'] == $token))
                {
                    $errors['token'] = 'You have apparently resubmitted the form. Please do not do that.';
                }
                else
                {
                    // New submission.
                    $_SESSION['token'] = $token;
                }

            }
            else
            {
                $errors['token'] = 'The order cannot be processed. Please make sure you have JavaScript enabled and try again.';
            }

            // Set the order amount somehow:
            $amount  = $cost; //  in cents
            echo $amount;
            $email       = "info@intelycare.com";
            $description = "Jane Doe"; //customer


            // Validate other form data!

            // If no errors, process the order:
            if(empty($errors))
            {

                // create the charge on Stripe's servers - this will charge the user's card
                try
                {



                    // Include the Stripe library:



                    // set your secret key: remember to change this to your live secret key in production
                    // see your keys here https://manage.stripe.com / account
                    Stripe::setApiKey(STRIPE_PRIVATE_KEY);

                    // Charge the order:
                    // Create a Customer
                    $customer = Stripe_Customer::create(array(
                            "card"       => $token,
                            "description"=> $description
                        )
                    );
                    // Charge the Customer instead of the card
                    Stripe_Charge::create(array(
                            "amount"  => $amount    ,# amount in cents, again
                            "currency"=> "usd",
                            "customer"=> $customer->id
                        )
                    );
                    // Save the customer ID in your database so you can use it later
                    //saveStripeCustomerId($user, $customer->id);

                    // Later...
                    //$customerId = getStripeCustomerId($user);

                    $charge = Stripe_Charge::create(array(
                            "amount"  => $amount,// amount in cents, again
                            "currency"=> "usd",
                            "customer"=> $customer
                        )
                    );

                    // Check that it was paid:
                    if($charge->paid == true)
                    {

                        // Store the order in the database.
                        // Send the email.
                        // Celebrate!

                    }
                    else
                    {
                        // Charge was not paid!
                        echo '<div class="alert alert-error"><h4>Payment System Error!</h4>Your payment could NOT be processed (i.e., you have not been charged) because the payment system rejected the transaction. You can try again or use another card.</div>';
                    }

                } catch(Stripe_CardError $e)
                {
                    // Card was declined.
                    $e_json = $e->getJsonBody();
                    $err    = $e_json['error'];
                    $errors['stripe'] = $err['message'];
                } catch(Stripe_ApiConnectionError $e)
                {
                    // Network problem, perhaps try again.
                } catch(Stripe_InvalidRequestError $e)
                {
                    // You screwed up in your programming. Shouldn't happen!
                } catch(Stripe_ApiError $e)
                {
                    // Stripe's servers are down!
                } catch(Stripe_CardError $e)
                {
                    // Something else that's not the customer's fault.
                }

            } // A user form submission error occurred, handled below.

        } // Form submission.




        ?>

        <h1>
            IntelyCare
        </h1>

        <form action="buy.php" method="POST" id="payment-form">

            <?php // Show PHP errors, if they exist:
            if(isset($errors) && !empty($errors) && is_array($errors))
            {
                echo '<div class="alert alert-error"><h4>Error!</h4>The following error(s) occurred:<ul>';
                foreach($errors as $e)
                {
                    echo "<li>$e</li>";
                }
                echo '</ul></div>';
            }?>

            <div id="payment-errors">
            </div>

            <span class="help-block">
                Form of Payment accepted: Mastercard, Visa, American Express, JCB, Discover, and Diners Club.
            </span>
            <br />
            <input type="text" name="clientid" value="<?php if(isset($_GET['rid'])) {echo $_GET['rid']; } ?>"   >
            <br />  
            <label> Card Number </label>
            <input type="text" size="20" autocomplete="off" class="card-number input-medium">
            <span class="help-block">   Enter the number without spaces or hyphens.     </span>
            <label> CVC     </label>
            <input type="text" size="4" autocomplete="off" class="card-cvc input-mini">
            <label> Expiration (MM/YYYY)    </label>
            <input type="text" size="2" class="card-expiry-month input-mini">
            <span>  /   </span>
            <input type="text" size="4" class="card-expiry-year input-mini">
            <button type="submit" class="btn" id="submitBtn">
                Submit Payment
            </button>

        </form>

        <script src="../stripe/buy.js">
        </script>

    </body>
</html>

英特利卡

我联系了Stripe,他们给了我一些建议,这里有一个解决问题的方法,希望它能让其他人受益。我可以通过一个可变金额的条纹付款。下面是我的charge.php文件,我还没有处理错误,但我将在以后包含它

<?php
require_once(dirname(__FILE__) . '/config.php');
require_once("../auth/config.class.php");
require_once("../auth/auth.class.php");

$config = new Config;

$dbh = new PDO("mysql:host={$config->dbhost};dbname={$config->dbname}", $config->dbuser,     $config->dbpass);
$auth = new Auth($dbh, $config);

$id= $_GET['rid'];

$query = $dbh->prepare("SELECT hours, cid FROM svcrequest WHERE id=? ");
$query->execute(array($id));    
$rslt = $query->fetch(PDO::FETCH_ASSOC);
$cost    = ($rslt['hours'] * 23)*100;
echo $cost;
$cid = $rslt['cid'];

$query  = $dbh->prepare("SELECT email, fname, lname FROM client JOIN users ON client.uid = users.id WHERE uid =(SELECT uid FROM client WHERE id=?)");
$query->execute(array($cid));
$user =$query->fetch(PDO::FETCH_ASSOC);
$email = ($user['email']);
echo $email;



$token = $_POST['stripeToken'];





$customer = Stripe_Customer::create(array(
'email' => $email,
'card' => $token
));

$charge = Stripe_Charge::create(array(
'customer' => $customer->id,
'amount' => $cost,
'currency' => 'usd'
));

echo '<h3>Charge today:</h3>' . $cost;
?>

也许您可以在以下方面获得帮助