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')

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

报告相同问题?

悬赏问题

  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式
  • ¥50 关于多次提交POST数据后,无法获取到POST数据参数的问题
  • ¥15 win10,这种情况怎么办
  • ¥15 如何在配置使用Prettier的VSCode中通过Better Align插件来对齐等式?(相关搜索:格式化)
  • ¥100 在连接内网VPN时,如何同时保持互联网连接
  • ¥15 MATLAB中使用parfor,矩阵Removal的有效索引在parfor循环中受限制
  • ¥20 Win 10 LTSC 1809版本如何无损提升到20H1版本
  • ¥50 win10 LTSC 虚拟键盘不弹出
  • ¥30 微信小程序请求失败,网页能正常带锁访问
  • ¥15 Matlab求解微分方程,如何用fish2d进行预优?