我当前的问题所在。这是因为它不添加卡信息,但是如果我在consol.log("Hello World")
之前添加 StripeTokenHandler ,那么它将创建客户+卡信息等。但是,它必须添加了 paymentIntentSecret 。
我选择对stripeTokenHandler进行评论,因为它创建了客户+卡等。但是,如果我对此进行评论,则无济于事。那么,简短信息和客户的payIntentSecret不会出现。
我的js代码:
var form = document.getElementById('payment-form');
form.addEventListener('submit', function (event) {
event.preventDefault();
const Id = document.getElementById("PricVat").value;
const CompaniesId = document.getElementById("CompaniesId").value;
console.log(Id, CompaniesId);
var errorElement = document.getElementById('card-errors');
stripe.createToken(card).then(function (result) {
if (result.error) {
//Inform the user if there was an error.
errorElement.textContent = result.error.message;
} else {
//Send the token to your server.
//stripeTokenHandler(result.token);
$.ajax({
url: '/Members/AddMembership/' + Id + '/' + CompaniesId, //jump to httppost action,meet [Route("Members/AddMembership/{id}/{CompaniesId}")]
dataType: "json",
data: "",
type: "Post",
contentType: 'application/json',
success: function (paymentIntentSecret) {//receive response from httppost action
//result is the response of the httppost action,you can handle it
console.log("New: " + Id, CompaniesId);
console.log(paymentIntentSecret) //Say: "This customer has no attached payment source"
//stripeTokenHandler(result.token);
console.log("HELLO WORLD");
stripe.handleCardPayment(paymentIntentSecret).then(function (result) {
if (result.error) {
//Display error.message in your UI.
//Inform the user if there was an error.
errorElement.textContent = result.error.message;
console.log("Test 1")
} else {
//The payment has succeeded. Display a success message.
errorElement.textContent = "succe";
console.log("Test 2")
}
});
},
error: function (xhr) {
console.log(xhr)
}
});
}
});
});
// Submit the form with the token ID.
function stripeTokenHandler(token) {
// Insert the token ID into the form so it gets submitted to the server
var form = document.getElementById('payment-form');
var hiddenInput = document.createElement('input');
hiddenInput.setAttribute('type', 'hidden');
hiddenInput.setAttribute('name', 'Source');
hiddenInput.setAttribute('value', token.id);
form.appendChild(hiddenInput);
// Submit the form
form.submit();
}
因此,当我单击“提交”时,我会得知Stripe is referring me to this page。
因此,我所有的console.log都提供了我想要的信息,但是提供了console.log(paymentIntentSecret)
信息,即“ 该客户没有附加的付款来源”
我需要帮助的地方/问题所在的地方:向客户添加PaymentIntentSecret和卡信息。这对我来说现在的错误是向客户添加这两个信息。其他所有信息都很好。