php - Paypal 捐赠你喜欢的下载

标签 php javascript html paypal donations

我想创建一个捐赠和下载脚本,允许您输入自己的金额,然后它会自动下载并带您到 paypal。 0 也需要是一个选项数量。这是一个例子:http://www.losttype.com/font/?name=liberator

我已经创建了一个 PayPal 捐赠脚本并进行了编辑以添加输入金额,但是任何人都可以建议一种自动开始下载并允许 0 作为金额的方法吗?


也许我应该重新开始,我有以下代码允许用户使用 paypal 捐赠。这有一个输入金额,并在新窗口中将用户重定向到 Paypal 。 提交开始下载的最佳方式是什么?即使此人投入零,他们也可以在另一个窗口捐款。 代码:

<div class="donate">
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">
<input type="hidden" name="cmd" value="_donations">
<input type="hidden" name="business" value="myemail">
<input type="hidden" name="lc" value="GB">
<input type="hidden" name="item_name" value="info">
<table> <tr><td>Enter your Amount:</td></tr><tr><td><input type="text" name="amount"     value=""></td></tr> </table>
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="cn" value="Add special instructions to the seller">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="bn" value="PP-DonationsBF:btn_donate_LG.gif:NonHosted">
<input type="image" src="https://www.paypalobjects.com/en_GB/i/btn/btn_donate_LG.gif" border="0" name="submit">
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>

最佳答案

真的很简单。检测是否已选择金额,如果已选择,则重定向到 PayPal。
如果没有,直接重定向到文件。

下面是一个非常基本的未经检查的示例:

    <?php

    echo "<p>Donate fixed amount to CharityName</p>
    <form method='POST' action=''>
    <select name='currency_code'>
    <option value='EUR'>EUR</option>
    <option value='GBP'>GBP</option>
    <option value='USD'>USD</option>
    <input type='text' name='donate_amount' value='0'>
    <input type='submit' name='submit' value='Donate'></form>";

    if(!empty($_POST['submit'])) {
    // Form has been submitted
      if($_POST['donate_amount'] > 0) {
    // Redirect to PayPal
    header('Location: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&item_name=Donation for XXX&amount='.$_POST['donate_amount'].'&currency_code='.$_POST['currency_code'].'&business=mypaypalemail@here.tld&cbt=Download the file&return=http://link-to-the-file&cancel_return=http://back-to-my-website');
    }
    else {
    // No donation amount entered - proceed to file directly
    header('Location: http://link-to-the-file/');
    }
}

    ?>

关于php - Paypal 捐赠你喜欢的下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9339968/

相关文章:

css - 防止定位到:fixed; div from bunching when window is resized的内容

php - 重新索引数字数组键

javascript - 正则表达式阻止连续 4 次以上包含相同数字的电话号码?

javascript - Sweet Alert 框我添加了 4 个按钮,只有一个按钮可以工作

javascript - jquery mobile,图像周围有一个小黑色边框

javascript - 纯 Javascript : event. 目标 : Get the next Sibling, & 第一个 child

php - 修改 JSON 数据格式以用于 FLOT 图表

php - 如何从 CakePHP 3 结果对象中获取第一项

javascript - AngularJS 中 Ember 夹具适配器的等效项

javascript - 使用slideToggle时,如何让所有其他div向后滑动?