如何让我的注册脚本检查付款验证


How can I make my signup script check for payment validation

//Users Registration Function
function vpb_users_registration() 
{
	var reg = /^([A-Za-z0-9_'-'.])+'@([A-Za-z0-9_'-'.])+'.([A-Za-z]{2,4})$/;
	var vpb_fullname = $("#fullname").val();
	var vpb_username = $("#username").val();
	var vpb_email = $("#email").val();
	var vpb_passwd = $("#passwd").val();
	
	if(vpb_fullname == "")
	{
		$("#signup_status").html('<div class="info">Please enter your fullname in the required field to proceed.</div>');
		$("#fullname").focus();
	}
	else if(vpb_username == "")
	{
		$("#signup_status").html('<div class="info">Please enter your desired username to proceed.</div>');
		$("#username").focus();
	}
	else if(vpb_email == "")
	{
		$("#signup_status").html('<div class="info">Please enter your email address to proceed.</div>');
		$("#email").focus();
	}
	else if(reg.test(vpb_email) == false)
	{
		$("#signup_status").html('<div class="info">Please enter a valid email address to proceed.</div>');
		$("#email").focus();
	}
	else if(vpb_passwd == "")
	{
		$("#signup_status").html('<div class="info">Please enter your desired password to go.</div>');
		$("#passwd").focus();
	}
	else
	{
		var dataString = 'vpb_fullname='+ vpb_fullname + '&vpb_username=' + vpb_username + '&vpb_email=' + vpb_email + '&vpb_passwd=' + vpb_passwd + '&page=signup';
		$.ajax({
			type: "POST",
			url: "vpb_save_details.php",
			data: dataString,
			cache: false,
			beforeSend: function() 
			{
				$("#signup_status").html('<br clear="all"><br clear="all"><div align="left"><font style="font-family:Verdana, Geneva, sans-serif; font-size:12px; color:black;">Please wait</font> <img src="images/loadings.gif" alt="Loading...." align="absmiddle" title="Loading...."/></div><br clear="all">');
			},
			success: function(response)
			{
				var vpb_result_broght = response.indexOf('completed');
				if (vpb_result_broght != -1 ) 
				{
					$("#fullname").val('');
					$("#username").val('');
					$("#email").val('');
					$("#passwd").val('');
					$("#signup_status").hide().fadeIn('slow').html(response);
				}
				else
				{
					$("#signup_status").hide().fadeIn('slow').html(response);
				}
				
			}
		});
	}
}
//Users Login Function
function vpb_users_login() 
{
	var vpb_username = $("#username").val();
	var vpb_passwd = $("#passwd").val();
	
	if(vpb_username == "")
	{
		$("#login_status").html('<div class="info">Please enter your account username to proceed.</div>');
		$("#username").focus();
	}
	else if(vpb_passwd == "")
	{
		$("#login_status").html('<div class="info">Please enter your account password to go.</div>');
		$("#passwd").focus();
	}
	else
	{
		var dataString = 'vpb_username=' + vpb_username + '&vpb_passwd=' + vpb_passwd + '&page=login';
		$.ajax({
			type: "POST",
			url: "vpb_save_details.php",
			data: dataString,
			cache: false,
			beforeSend: function() 
			{
				$("#login_status").html('<br clear="all"><br clear="all"><div align="left"><font style="font-family:Verdana, Geneva, sans-serif; font-size:12px; color:black;">Please wait</font> <img src="images/loadings.gif" alt="Loading...." align="absmiddle" title="Loading...."/></div><br clear="all">');
			},
			success: function(response)
			{
				var vpb_result_broght = response.indexOf('completed');
				if (vpb_result_broght != -1 ) 
				{
					$("#login_status").html('');
					$("#username").val('');
					$("#passwd").val('');
					window.location.replace("index1.php");
					
				}
				else
				{
					$("#login_status").hide().fadeIn('slow').html(response);
				}
				
			}
		});
	}
}

我希望我的注册表格在将用户凭据保存到数据库之前检查付款是否已处理,这将使他们能够访问会员部分。一旦付款处理完毕,我想让用户的信息登录到他们的账户中。我设置代码的方式是将用户名/数据库保存在托管网站的txt文件中。

您发布的内容与付款、信用卡号等无关。我只看到全名、用户名、密码和电子邮件。看起来像是登录或创建用户的功能。

在服务器端,你必须有一些用于商家处理的代码(例如PHP),它应该返回一个处理,告诉你收费是否成功。如果你还没有为Paypal实现代码,我建议你使用Stripe,它们的费用低2.9%,没有月费,而且非常容易实现。

在Javascript中,在客户端,您可以使用$.post方法或$.ajax,就像您在调用vbp_save_details.php 时所做的那样

就我个人而言,我使用$.post方法。在服务器上,我的支付处理脚本返回一个json对象,让您知道它是否被批准。类似这样的东西:

$.post('stripe.php',payload,
    function(data) {
        $('#submit_button').removeAttr('disabled');
        var json = JSON.parse(data);
        console.log(json);
        if ( json.disposition == 1 ) {
            console.log("APPROVED");
            window.location.href = "thank_you.php";
        } else {
            console.log("DECLINED");
        }
    }
);