dongyan7988 2014-04-08 20:50
浏览 82
已采纳

条带错误'exp_month'参数应该是一个整数(相反,未定义)PHP / Stripe.js

I have a form that I am trying to process payments for by following this example (https://gist.github.com/boucher/1750375). I am using PHP and Stripe.js and I keep getting this error:

The 'exp_month' parameter should be an integer (instead, is undefined)

Below is the code I am using. Am I missing something obvious?

<?php
session_start();
$name = htmlspecialchars($_POST['name']);
$description = "Test Transaction";
$amount = trim($_POST['amount']);
$email = htmlspecialchars(trim($_POST['email']));
$receipt_error = "Email receipt did not send!";

require_once 'includes/stripe-php-1.12.0/lib/Stripe.php';

if ($_POST) {
  Stripe::setApiKey("sk_test_XXXXXX");
  $error = '';
  $success = '';
  try {
    if (!isset($_POST['stripeToken']))
      throw new Exception("The Stripe Token was not generated correctly");
    Stripe_Charge::create(array("amount" => $amount * 100,
                "description" => $description,
                                "currency" => "usd",
                                "card" => $_POST['stripeToken']));

    //PREPARE EMAIL
    $to = $email;
    $subject = "Receipt";
    $headers =
     'From: XXXX ' . "
" .
     'Reply-To: XXXX ' . "
" .
     'Bcc: XXXX' . "
" .
     'Content-type: text/html' . "
" .
     'X-Mailer: PHP/' . phpversion();
    include_once('includes/email_receipt.php'); //Sent $message

    //Send the email!
    if(mail($to,$subject,$message,$headers)){
         header("Location: thank-you.php");
    }
    else{
        die($receipt_error);
    }   

  }
  catch (Exception $e) {
    $error = $e->getMessage();
  }

}
?>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript" ></script>
<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
    <!-- jQuery is used only for this example; it isn't required to use Stripe -->
    <script type="text/javascript">
            // this identifies your website in the createToken call below
            Stripe.setPublishableKey('pk_test_XXX');

            function stripeResponseHandler(status, response) {
                if (response.error) {
                    // re-enable the submit button
                    $('.submit_button').removeAttr("disabled");
                    // show the errors on the form
                    $(".payment-errors").html(response.error.message);
                } else {
                    var form$ = $("#donation_form");
                    // token contains id, last4, and card type
                    var token = response['id'];
                    // insert the token into the form so it gets submitted to the server
                    form$.append("<input type='hidden' name='stripeToken' value='" + token + "' />");
                    // and submit
                    form$.get(0).submit();
                }
            }

            $(document).ready(function() {
                $("#donation_form").submit(function(event) {
                    // disable the submit button to prevent repeated clicks
                    $('.submit_button').attr("disabled", "disabled");

                    // createToken returns immediately - the supplied callback submits the form if there are no errors
                    Stripe.createToken({
                        number: $('.number').val(),
                        name: $('.name').val(),
                        description: $('.description').val(),
                        cvc: $('.cvc').val(),
                        exp_month: $('.exp_month').val(),
                        exp_year: $('.exp_year').val()
                    }, stripeResponseHandler);
                    return false; // submit from callback
                });
            });
        </script>

<form method="post" action="" class="reply-input" id="donation_form" >
                                        <div class="input-block">
                                            <label for="amount" class="label_comment"><strong>Donation Amount</strong>*</label>
                                            <input type="text" name="amount" value="<?php echo $_POST['amount']; ?>" placeholder="$" data-stripe="amount" id="amount" required="">
                                        </div>

                                        <div class="input-block">
                                            <label for="name" class="label_comment"><strong>Cardholder Name</strong>*</label>
                                            <input type="text" name="name" value="<?php echo $_POST['name']; ?>" data-stripe="name" id="name" required="">
                                        </div>

                                        <div class="input-block">
                                            <label for="email" class="label_comment"><strong>Email</strong>*</label>
                                            <input type="email" name="email" value="<?php echo $_POST['email']; ?>" data-stripe="email" id="email" required="">
                                        </div>

                                        <div class="input-block">
                                            <label for="credit_card" class="label_comment"><strong>Credit Card Number</strong>*</label>
                                            <input type="number" name="credit-card" value="" id="credit_card" data-stripe="number" required="">
                                        </div>

                                        <div class="input-block">
                                            <label for="cvc" class="label_comment"><strong>CVV</strong>*</label>
                                            <input type="number" name="cvc" value="" data-stripe="cvc" id="cvv" required="" maxlength="4">
                                        </div>

                                        <div class="input-block">
                                            <label for="exp_month" class="label_comment"><strong>Expiration Month</strong>*</label>
                                            <div class="clear"></div>
                                            <select name='exp_month' id='exp_month' data-stripe="exp-month">
                                                <option value=''>Month</option>
                                                <option value='01'>Janaury</option>
                                                <option value='02'>February</option>
                                                <option value='03'>March</option>
                                                <option value='04'>April</option>
                                                <option value='05'>May</option>
                                                <option value='06'>June</option>
                                                <option value='07'>July</option>
                                                <option value='08'>August</option>
                                                <option value='09'>September</option>
                                                <option value='10'>October</option>
                                                <option value='11'>November</option>
                                                <option value='12'>December</option>
                                            </select> 
                                            <select name='exp_year' id='exp_year' data-stripe="exp-year">
                                                <option value="">Year</option>
                                                <?php
                                                for($i=0;$i<21;$i++){
                                                    echo "<option value='".(date('Y')+$i)."'>".(date('y')+$i)."</option>
";
                                                }
                                                ?>
                                            </select> 
                                        </div>


                                        <input type="submit" class="btn btn-success btn-large submit_button" value="Click to Donate Today">
                                        <div class="clear"></div>
                                    </form>
  • 写回答

1条回答 默认 最新

  • dongming0505 2014-04-08 21:24
    关注

    In your code, you're querying by classname '.exp_month' when there isn't a class with '.exp_month' in your HTML. If you're trying to query by id, it should be $('#exp_month')

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)