gpt4 book ai didi

javascript - 使用 Bootstrap 定价 slider 的每月 Paypal 付款

转载 作者:太空宇宙 更新时间:2023-11-03 16:14:23 25 4
gpt4 key购买 nike

我有一个不错的 Bootstrap 定价 slider ,它最初来自这里:http://amirolahmad.github.io/bootstrap-pricing-slider/

在我的 Bootstrap Pricing Slider 中,我在所有数学运算后得到了“总金额”,并且我得到了一个表示总金额的分数。

我有“处理”按钮,它通常什么都不做,也不会转发到任何地方。

我希望当我获得总分并单击“处理”时,金额将复制到 Paypal 付款中,该按钮会将我转发到 Paypal 进行付款,并将包括总分上显示的金额。我需要它来支付月度和年度费用。

完整代码如下:

<!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 $10 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 天的订阅。

关于javascript - 使用 Bootstrap 定价 slider 的每月 Paypal 付款,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30365658/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com