1

I am looking to create a donate and Dowload script that allows you to put in your own money amount and then it automatically downloads and takes you to paypal. 0 needs to be an option amount also. Here is an example: http://www.losttype.com/font/?name=liberator

I have created a PayPal donate script and edited to add an input amount, but can anyone suggest a way to automatically start the download and allow 0 as an amount?


Maybe I should start again, I have the following code that allows the user to donate with paypal. This has an input amount, and redirects the user to paypal in a new window. What would be the best way to on submit to start the download? even if the person puts in zero, and while they can donate in another window. Code:

<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>
Hue
  • 461
  • 2
  • 9
  • 25
  • How can this be done? Can anyone help me create the script to do this? – Hue Feb 18 '12 at 10:08
  • Not without a specific question - we're here to help you with specific problems you face; not to give you all the code you need. – Repox Feb 18 '12 at 10:22
  • you can always read the PayPal API and examples, there are many. – LoG Feb 18 '12 at 10:26
  • I have edited my question, can anyone suggest the best way to automatically direct the PayPal submit to also download at the same time? – Hue Feb 18 '12 at 10:28
  • I have also included my code so far, anyone help with redirecting to a download link as well as opening Paypal window? – Hue Feb 18 '12 at 14:03
  • You would need an intermediate step after the form has been submitted that would handle this. The step would open a new window that would forward the user form your site to PayPal, and also start the download. – Josh Feb 18 '12 at 23:14
  • Thanks for the advice, how do you think this could be done? I was wondering if JavaScript could open a link to the file on the click of the submit button, but I guess this would stop the redirect to PayPal – Hue Feb 18 '12 at 23:34

2 Answers2

2

Easy enough really. Detect whether an amount has been chosen, and if it has, redirect to PayPal.
If it hasn't, redirect directly to the file.

Below is a very basic, unchecked example:

    <?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/');
    }
}

    ?>
Robert
  • 19,326
  • 3
  • 58
  • 59
  • Hi Robert - I am trying this version, and adding all my links etc but just cant get it to redirect anywhere on submit the form just refreshes, any idea why? – Hue Feb 21 '12 at 09:43
  • Have a look in your webserver's error log; I did a quick local test and it's working fine for me. – Robert Feb 21 '12 at 11:56
  • Ah, I see the problem I tried it locally on MAMP but wasn't working. Tried it online and it is not allowing it in my Wordpress theme due to headers already being sent. Can I get this to work with Wordpress or is the headers a problem? – Hue Feb 21 '12 at 12:59
  • I take that back, I have it working on a fresh install of wordpress, must be a conflict with a plugin. Thank you ever so much for your help Robert! – Hue Feb 21 '12 at 13:24
0

This seems to be easier done from client side javascript code. Unpon clicking the donate & download button, JS determines the amount entered. If it is 0, it opens a new page that points to the downloads and return false (to stop processing to paypal) and if it's more than 0, then it opens the download page and returns true (to handoff the payment to paypal).

T0xicCode
  • 4,583
  • 2
  • 37
  • 50
  • I would prefer to do this with JavaScript if possible. Could you possibly suggesti code to use? I'd really appreciate any help – Hue Feb 20 '12 at 21:44