Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/366.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
Stripe.js/Stripe.php-所有卡错误都有效(过期、cvc、不正确),拒绝的卡除外_Php_Javascript_Arrays - Fatal编程技术网

Stripe.js/Stripe.php-所有卡错误都有效(过期、cvc、不正确),拒绝的卡除外

Stripe.js/Stripe.php-所有卡错误都有效(过期、cvc、不正确),拒绝的卡除外,php,javascript,arrays,Php,Javascript,Arrays,我正在测试一个使用stripe进行付款的简单结账表单。我遵循了教程的例子,除了拒绝卡错误,其他一切都正常。根据api,使用4000000000000002模拟拒绝的卡。它只是破坏了我的charge.php文件。下面是html表单和charge.php文件中的代码 现场版本: form.html- <html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta nam

我正在测试一个使用stripe进行付款的简单结账表单。我遵循了教程的例子,除了拒绝卡错误,其他一切都正常。根据api,使用4000000000000002模拟拒绝的卡。它只是破坏了我的charge.php文件。下面是html表单和charge.php文件中的代码

现场版本:

form.html-

<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
  <meta name="generator" content=
  "HTML Tidy for Linux/x86 (vers 11 February 2007), see www.w3.org" />
  <meta http-equiv="Content-type" content="text/html; charset=us-ascii" />

  <title>Stripe Getting Started Form</title>
  <script type="text/javascript" src="https://js.stripe.com/v1/">
</script><!-- jQuery is used only for this example; it isn't required to use Stripe -->

  <script type="text/javascript" src=
  "https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js">
</script>
  <script type="text/javascript">
//<![CDATA[
                                // this identifies your website in the createToken call below
                                Stripe.setPublishableKey('ihidthis');

                                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$ = $("#payment-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() {
                                        $("#payment-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({
                                                name: $('.card-name').val(),
                                                number: $('.card-number').val(),
                                                cvc: $('.card-cvc').val(),
                                                exp_month: $('.card-expiry-month').val(),
                                                exp_year: $('.card-expiry-year').val()
                                                }, stripeResponseHandler);
                                                return false; // submit from callback
                                        });
                                });

                                if (window.location.protocol === 'file:') {
                                        alert("stripe.js does not work when included in pages served over file:// URLs. Try serving this page over a webserver. Contact support@stripe.com if you need assistance.");
                                }
  //]]>
  </script>
</head>

<body>
  <h1>Trial $4.99 with recurring $74.98 after 18 days</h1>
  <!-- to display errors returned by createToken -->

  <form action="charge.php" method="post" id="payment-form" name="payment-form">
    <div class="form-row">
      <label>Name on Card</label> <input type="text" size="20" autocomplete="off" class=
      "card-name" />
    </div>

    <div class="form-row">
      <label>Email</label> <input type="text" size="20" autocomplete="off" name=
      "email" />
    </div>

    <div class="form-row">
      <label>Card Number</label> <input type="text" size="20" autocomplete="off" class=
      "card-number" />
    </div>

    <div class="form-row">
      <label>CVC</label> <input type="text" size="4" autocomplete="off" class=
      "card-cvc" />
    </div>

    <div class="form-row">
      <label>Expiration (MM/YYYY)</label> <input type="text" size="2" class=
      "card-expiry-month" /> <span>/</span> <input type="text" size="4" class=
      "card-expiry-year" />
    </div>

    <div class="form-row">
      <label>Shipping address</label> <input type="text" size="20" autocomplete="off"
      name="address" />
    </div>

    <div class="form-row">
      <label>City</label> <input type="text" size="20" autocomplete="off" name="city" />
    </div>

    <div class="form-row">
      <label>State</label> <input type="text" size="20" autocomplete="off" name=
      "state" />
    </div>

    <div class="form-row">
      <label>Zip Code</label> <input type="text" size="20" autocomplete="off" name=
      "zip" />
    </div><button type="submit" class="submit-button">Submit Payment</button>
  </form>
</body>
</html>
charge.php-

<?php

require_once('stripe-php/lib/Stripe.php');

Stripe::setApiKey("ihidthis");

// get the single use token from the form submitted by stripeResponseHandler
// set your secret key: remember to change this to your live secret key in production
// see your keys here https://manage.stripe.com/account

// get the credit card details submitted by the form
$token = $_POST['stripeToken'];
$email = $_POST['email'];

//combine these variables and post them all to stripe's customer description
$address = $_POST['address'];
$city    = $_POST['city'];
$state   = $_POST['state'];
$zip     = $_POST['zip'];

$description = $address . " " . $city . " " . $state . " " . $zip;


$customer = Stripe_Customer::create(array(
    "card" => $token,
    "plan" => "001",
    "description" => $description,
    "email" => $email
));

Stripe_Charge::create(array(
    "amount" => 499, # amount in cents, again
    "currency" => "usd",
    "customer" => $customer->id
));



echo '<h1>Thank you for your business!</h1>';
?>

您需要捕获在第二页返回的错误。第一页上的响应仅验证卡号

try {
    Stripe_Charge::create(array(
        "amount" => 499,
        "currency" => "usd",
        "customer" => $customer->id)
    );
    $success = 'Your payment was successful.';
} catch (Exception $e) {    
    $error = $e->getMessage();
}

您需要捕获在第二页返回的错误。第一页上的响应仅验证卡号

try {
    Stripe_Charge::create(array(
        "amount" => 499,
        "currency" => "usd",
        "customer" => $customer->id)
    );
    $success = 'Your payment was successful.';
} catch (Exception $e) {    
    $error = $e->getMessage();
}

Nicolas在下面是正确的,但由于我使用一次性收费,并与客户签订了定期计划,因此我需要在try-catch区块中同时包含客户和收费

try {

$customer = Stripe_Customer::create(array(
    "card" => $token,
    "plan" => "001",
    "description" => $description,
    "email" => $email)
);
Stripe_Charge::create(array(
    "amount" => 499,
    "currency" => "usd",
    "customer" => $customer->id)
);
$success = 'Your payment was successful.';
} catch (Exception $e) {    
$error = $e->getMessage();
}

Nicolas在下面是正确的,但由于我使用一次性收费,并与客户签订了定期计划,因此我需要在try-catch区块中同时包含客户和收费

try {

$customer = Stripe_Customer::create(array(
    "card" => $token,
    "plan" => "001",
    "description" => $description,
    "email" => $email)
);
Stripe_Charge::create(array(
    "amount" => 499,
    "currency" => "usd",
    "customer" => $customer->id)
);
$success = 'Your payment was successful.';
} catch (Exception $e) {    
$error = $e->getMessage();
}

不适合我。它仍然给我一个内部服务器错误500。我关闭了友好的HTTP错误…它只是给我显示了一个空白屏幕。你在隐瞒你的错误吗?看到一些PHP错误或警告会有所帮助。对我来说不起作用。它仍然给我一个内部服务器错误500。我关闭了友好的HTTP错误…它只是给我显示了一个空白屏幕。你在隐瞒你的错误吗?看到一些PHP错误或警告会有所帮助。