使用 Bootstrap 定价滑块的每月 Paypal 付款
Monthly Paypal Payments with Bootstrap Pricing Slider
我有一个不错的 Bootstrap 定价滑块,最初来自这里:http://amirolahmad.github.io/bootstrap-pricing-slider/
在我的 Bootstrap 定价滑块中,我有 "total amount" 经过所有数学运算后,我得到了一个表示总计的分数。
我有 "Process" 按钮,它通常什么都不做,也不会转发到任何地方。
我希望当我获得总分并单击 "Process" 时,金额将复制到贝宝付款中,按钮会将我转到贝宝付款,并将包括总分上显示的金额.我需要它来支付月供和年供。
完整代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap Pricing Slider</title>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<div class="container">
<div class="price-box">
<form class="form-horizontal form-pricing" role="form">
<div class="price-slider">
<h4 class="great">Amount</h4>
<span>Minimum is required</span>
<div class="col-sm-12">
<div id="slider"></div>
</div>
</div>
<div class="price-slider">
<h4 class="great">Duration</h4>
<span>Minimum 1 day is required</span>
<div class="col-sm-12">
<div id="slider2"></div>
</div>
</div>
<div class="price-form">
<div class="form-group">
<label for="amount" class="col-sm-6 control-label">Amount ($): </label>
<span class="help-text">Please choose your amount</span>
<div class="col-sm-6">
<input type="hidden" id="amount" class="form-control">
<p class="price lead" id="amount-label"></p>
<span class="price">.00</span>
</div>
</div>
<div class="form-group">
<label for="duration" class="col-sm-6 control-label">Duration: </label>
<span class="help-text">Choose your commitment</span>
<div class="col-sm-6">
<input type="hidden" id="duration" class="form-control">
<p class="price lead" id="duration-label"></p>
<span class="price">days</span>
</div>
</div>
<hr class="style">
<div class="form-group total">
<label for="total" class="col-sm-6 control-label"><strong>Total: </strong></label>
<span class="help-text">(Amount * Days)</span>
<div class="col-sm-6">
<input type="hidden" id="total" class="form-control">
<p class="price lead" id="total-label"></p>
<span class="price">.00</span>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<button type="submit" class="btn btn-primary btn-lg btn-block">Proceed <span class="glyphicon glyphicon-chevron-right pull-right" style="padding-right: 10px;"></span></button>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<img src="images/payment.png" class="img-responsive payment" />
</div>
</div>
</form>
<p class="text-center" style="padding-top:10px;font-size:12px;color:#2c3e50;font-style:italic;">Created by <a href="https://twitter.com/AmirolAhmad" target="_blank">AmirolAhmad</a></p>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.10.4/jquery-ui.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<script>
$(document).ready(function() {
$("#slider").slider({
range: "min",
animate: true,
value:1,
min: 10,
max: 1000,
step: 10,
slide: function(event, ui) {
update(1,ui.value); //changed
}
});
$("#slider2").slider({
range: "min",
animate: true,
value:1,
min: 1,
max: 365,
step: 1,
slide: function(event, ui) {
update(2,ui.value); //changed
}
});
//Added, set initial value.
$("#amount").val(0);
$("#duration").val(0);
$("#amount-label").text(0);
$("#duration-label").text(0);
update();
});
//changed. now with parameter
function update(slider,val) {
//changed. Now, directly take value from ui.value. if not set (initial, will use current value.)
var $amount = slider == 1?val:$("#amount").val();
var $duration = slider == 2?val:$("#duration").val();
/* commented
$amount = $( "#slider" ).slider( "value" );
$duration = $( "#slider2" ).slider( "value" );
*/
$total = "$" + ($amount * $duration);
$( "#amount" ).val($amount);
$( "#amount-label" ).text($amount);
$( "#duration" ).val($duration);
$( "#duration-label" ).text($duration);
$( "#total" ).val($total);
$( "#total-label" ).text($total);
$('#slider a').html('<label><span class="glyphicon glyphicon-chevron-left"></span> '+$amount+' <span class="glyphicon glyphicon-chevron-right"></span></label>');
$('#slider2 a').html('<label><span class="glyphicon glyphicon-chevron-left"></span> '+$duration+' <span class="glyphicon glyphicon-chevron-right"></span></label>');
}
</script>
</body>
</html>
您需要编辑 update()
函数以将值写入 PayPal 表单。例如;
将其添加到靠近底部的 update()
函数中(在计算完数学后)
$("#paypal_amount").val($amount);
然后添加 PayPal 表格
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick-subscriptions" />
<input type="hidden" name="business" value="MyEmailAddress@gmail.com" />
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="a3" value="" id="paypal_amount" />
<input type="hidden" name="p3" value="1">
<input type="hidden" name="t3" value="D">
<input type="hidden" name="return" value="http://example.com/paypal-return" />
<input type="hidden" name="cancel_return" value="http://example.com/paypal-cancel" />
<input type="hidden" name="notify_url" value="http://example.com/paypal-notify" />
<input type="hidden" name="bn" value="PP-BuyNowBF" />
<input type="image" src="http://www.paypal.com/en_GB/i/btn/x-click-but20.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
http://jsfiddle.net/yk6fkh1s/2/
注意: Paypal 确实有一个 subscription and recurring payment documentation 我建议您阅读。上面的表格将创建 x 天的订阅。
我有一个不错的 Bootstrap 定价滑块,最初来自这里:http://amirolahmad.github.io/bootstrap-pricing-slider/
在我的 Bootstrap 定价滑块中,我有 "total amount" 经过所有数学运算后,我得到了一个表示总计的分数。
我有 "Process" 按钮,它通常什么都不做,也不会转发到任何地方。
我希望当我获得总分并单击 "Process" 时,金额将复制到贝宝付款中,按钮会将我转到贝宝付款,并将包括总分上显示的金额.我需要它来支付月供和年供。
完整代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap Pricing Slider</title>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<div class="container">
<div class="price-box">
<form class="form-horizontal form-pricing" role="form">
<div class="price-slider">
<h4 class="great">Amount</h4>
<span>Minimum is required</span>
<div class="col-sm-12">
<div id="slider"></div>
</div>
</div>
<div class="price-slider">
<h4 class="great">Duration</h4>
<span>Minimum 1 day is required</span>
<div class="col-sm-12">
<div id="slider2"></div>
</div>
</div>
<div class="price-form">
<div class="form-group">
<label for="amount" class="col-sm-6 control-label">Amount ($): </label>
<span class="help-text">Please choose your amount</span>
<div class="col-sm-6">
<input type="hidden" id="amount" class="form-control">
<p class="price lead" id="amount-label"></p>
<span class="price">.00</span>
</div>
</div>
<div class="form-group">
<label for="duration" class="col-sm-6 control-label">Duration: </label>
<span class="help-text">Choose your commitment</span>
<div class="col-sm-6">
<input type="hidden" id="duration" class="form-control">
<p class="price lead" id="duration-label"></p>
<span class="price">days</span>
</div>
</div>
<hr class="style">
<div class="form-group total">
<label for="total" class="col-sm-6 control-label"><strong>Total: </strong></label>
<span class="help-text">(Amount * Days)</span>
<div class="col-sm-6">
<input type="hidden" id="total" class="form-control">
<p class="price lead" id="total-label"></p>
<span class="price">.00</span>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<button type="submit" class="btn btn-primary btn-lg btn-block">Proceed <span class="glyphicon glyphicon-chevron-right pull-right" style="padding-right: 10px;"></span></button>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<img src="images/payment.png" class="img-responsive payment" />
</div>
</div>
</form>
<p class="text-center" style="padding-top:10px;font-size:12px;color:#2c3e50;font-style:italic;">Created by <a href="https://twitter.com/AmirolAhmad" target="_blank">AmirolAhmad</a></p>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.10.4/jquery-ui.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<script>
$(document).ready(function() {
$("#slider").slider({
range: "min",
animate: true,
value:1,
min: 10,
max: 1000,
step: 10,
slide: function(event, ui) {
update(1,ui.value); //changed
}
});
$("#slider2").slider({
range: "min",
animate: true,
value:1,
min: 1,
max: 365,
step: 1,
slide: function(event, ui) {
update(2,ui.value); //changed
}
});
//Added, set initial value.
$("#amount").val(0);
$("#duration").val(0);
$("#amount-label").text(0);
$("#duration-label").text(0);
update();
});
//changed. now with parameter
function update(slider,val) {
//changed. Now, directly take value from ui.value. if not set (initial, will use current value.)
var $amount = slider == 1?val:$("#amount").val();
var $duration = slider == 2?val:$("#duration").val();
/* commented
$amount = $( "#slider" ).slider( "value" );
$duration = $( "#slider2" ).slider( "value" );
*/
$total = "$" + ($amount * $duration);
$( "#amount" ).val($amount);
$( "#amount-label" ).text($amount);
$( "#duration" ).val($duration);
$( "#duration-label" ).text($duration);
$( "#total" ).val($total);
$( "#total-label" ).text($total);
$('#slider a').html('<label><span class="glyphicon glyphicon-chevron-left"></span> '+$amount+' <span class="glyphicon glyphicon-chevron-right"></span></label>');
$('#slider2 a').html('<label><span class="glyphicon glyphicon-chevron-left"></span> '+$duration+' <span class="glyphicon glyphicon-chevron-right"></span></label>');
}
</script>
</body>
</html>
您需要编辑 update()
函数以将值写入 PayPal 表单。例如;
将其添加到靠近底部的 update()
函数中(在计算完数学后)
$("#paypal_amount").val($amount);
然后添加 PayPal 表格
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick-subscriptions" />
<input type="hidden" name="business" value="MyEmailAddress@gmail.com" />
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="a3" value="" id="paypal_amount" />
<input type="hidden" name="p3" value="1">
<input type="hidden" name="t3" value="D">
<input type="hidden" name="return" value="http://example.com/paypal-return" />
<input type="hidden" name="cancel_return" value="http://example.com/paypal-cancel" />
<input type="hidden" name="notify_url" value="http://example.com/paypal-notify" />
<input type="hidden" name="bn" value="PP-BuyNowBF" />
<input type="image" src="http://www.paypal.com/en_GB/i/btn/x-click-but20.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
http://jsfiddle.net/yk6fkh1s/2/
注意: Paypal 确实有一个 subscription and recurring payment documentation 我建议您阅读。上面的表格将创建 x 天的订阅。