2
我有一個表單和細節嵌入它。該表單由AJAX提交。表單的一部分是條形付款表單。當我點擊但提交按鈕時,我希望Stripe查看詳細信息是否正確,但不是提交收費,直到表格的其餘部分已經過檢查並提交。然後可以提交條紋付款。同時提交條紋和自定義表單
這裏是我的表單提交代碼(寫我自己,大規模簡化):
JS:
$(".booking-form").submit(function(e) {
e.preventDefault();
// JavaScipt form validation stuff. If all correct, submit form via AJAX
var data = $(".form").serialize();
$.post(bookingDetails.ajaxurl, data, function(response) {
if (response['data'] == "success") {
// Show some stuff to the user that confirms the submission, etc
}
});
});
PHP:
function sendData() {
$name = $_POST['name'];
$email = $_POST['email'];
$to = "[email protected]";
$subject = "New email";
$message = "New Email contents";
if ((!empty($name)) && (!empty($email))) { // check that fields have data before submitting
$mail = mail($to, $subject, $message, $headers);
wp_send_json_success("success"); // yes, this site runs on WordPress
}
}
和條狀的東西(從WP - 但很高興編輯它或其他)
JS:
function stripeResponseHandler(status, response) {
if (response.error) {
$(".payment-errors").show().html(response.error.message);
} else {
var form$ = $("#wp-stripe-payment-form");
var token = response['id'];
form$.append("<input type='hidden' name='stripeToken' value='" + token + "' />");
var newStripeForm = form$.serialize();
$.ajax({
type : "post",
dataType : "json",
url : ajaxurl,
data : newStripeForm,
success: function(response) {
$('.wp-stripe-details').prepend(response);
}
});
}
}
$("#wp-stripe-payment-form").submit(function(event) {
event.preventDefault();
$(".wp-stripe-notification").hide();
var amount = $('.total-vat').val() * 100; //amount you want to charge
Stripe.createToken({
name: $('.wp-stripe-name').val(),
number: $('.card-number').val(),
cvc: $('.card-cvc').val(),
exp_month: $('.card-expiry-month').val(),
exp_year: $('.card-expiry-year').val()
}, stripeResponseHandler);
if (paymentSuccessful) {
console.log("the payment was successful");
}
return false; // prevent the form from submitting with the default action
}
所以我的問題是,我如何整合條紋的東西和我的自定義的東西?
湯姆你有沒有發現如何做這個伴侶?因爲我堅持着同樣的問題! – Birdy
嗨@Birdy - 回答如下,我的方法做到這一點。希望有所幫助! –