条带错误:用户信用卡失败

时间:2014-01-18 15:24:04

标签: javascript php stripe-payments

我正在使用Stripe处理我网站上的付款。但是,当我尝试付款时,我收到的是“用户信用卡失败”错误。我已经在不同的网站上使用了这些代码并且它们可以工作但是由于某种原因它在这里不起作用。有谁知道问题可能是什么?卡上肯定有钱:

function stripeResponseHandler(status, response)
{
if (response.error) 
{
  // Stripe.js failed to generate a token. The error message will explain why.
  // Usually, it's because the customer mistyped their card info.
  // You should customize this to present the message in a pretty manner:
  alert(response.error.message);
} 
else
{  
  // Stripe.js generated a token successfully. We're ready to charge the card!
  var token = response.id;
  var email = $("#email").val();
   var price = $("#price").val();
   var id = $("id").val();

  // Make the call to the server-script to process the order.
  // Pass the token and non-sensitive form information.
  var request = $.ajax ({
     type: "POST",
     url: "pay.php",
     dataType: "json",
     data: {
        "stripeToken" : token,
        "email" : email,
        "price" : price,
        "id" : id 
        }
  });

  request.done(function(msg)
  {
     if (msg.result === 0)
     {
        // Customize this section to present a success message and display whatever
        // should be displayed to the user.
         window.location.replace("http://foo.com");

     }
     else
     {
        // The card was NOT charged successfully, but we interfaced with Stripe
        // just fine. There's likely an issue with the user's credit card.
        // Customize this section to present an error explanation
        alert("The user's credit card failed.");
     }
  });

  request.fail(function(jqXHR, textStatus)
  {
     // We failed to make the AJAX call to pay.php. Something's wrong on our end.
     // This should not normally happen, but we need to handle it if it does.
     alert("error");
  });
  }
 }

  function showErrorDialogWithMessage(message)
  {
  // For the tutorial, we'll just do an alert. You should customize this function to 
 // present "pretty" error messages on your page.
 alert(message);
// Re-enable the order button so the user can try again
$('#buy-submit-button').removeAttr("disabled");
}

$(document).ready(function() 
{
$('#buy-form').submit(function(event)
{
  // immediately disable the submit button to prevent double submits
  $('#buy-submit-button').attr("disabled", "disabled");

  var fName = $('#first-name').val();
  var lName = $('#last-name').val();
  var email = $('#email').val();
  var cardNumber = $('#card-number').val();
  var cardCVC = $('#card-security-code').val();

  // First and last name fields: make sure they're not blank
  if (fName === "") {
     showErrorDialogWithMessage("Please enter your first name.");
     return;
  }
  if (lName === "") {
     showErrorDialogWithMessage("Please enter your last name.");
     return;
  }

  // Validate the email address:
  var emailFilter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  if (email === "") {
     showErrorDialogWithMessage("Please enter your email address.");
     return;
  } else if (!emailFilter.test(email)) {
     showErrorDialogWithMessage("Your email address is not valid.");
     return;
  }

  // Stripe will validate the card number and CVC for us, so just make sure they're not         blank
  if (cardNumber === "") {
     showErrorDialogWithMessage("Please enter your card number.");
     return;
  }
  if (cardCVC === "") {
     showErrorDialogWithMessage("Please enter your card security code.");
     return;
  }


Stripe.createToken({
number: cardNumber,
cvc: cardCVC,
exp_month: $('#expiration-month').val(),
exp_year: $('#expiration-year').val()
 }, stripeResponseHandler);

 // Prevent the default submit action on the form
 return false;
 });
 });

提前致谢

0 个答案:

没有答案