Changeset - e0f0ee820fe3
[Not reviewed]
0 2 0
Bradley Kuhn (bkuhn) - 9 years ago 2014-12-03 23:10:45
bkuhn@ebb.org
Monthly supporter can enter variable amount.

This required some doing. I'm not completely sure it works, but I
roughly followed the tutorial available at:
https://www.paypal.com/webapps/mpp/get-started/create-recurring-donation-button
with back-reference to this:
https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/

My main concern with this setup currently is that 'p3' must be set to
'1', which would seem from the documentation to be saying the payment
will recur only once. There is a subtle hint via the tutorial that
setting 'src' to 1 will override 'p3' with whatever is found in 'srt',
but that's not said anywhere explicitly that I can find. So, I'm going
with this and I'll just test it myself with a monthly subscription to
see if it's indefinite (which is the behavior we herein desire).

Finally, note that "amount" is now a class rather than id, since I'm now
using the associated jQuery .on('input') code for both the annual and
monthly amount boxes.
2 files changed with 19 insertions and 7 deletions:
0 comments (0 inline, 0 general)
www/conservancy/static/supporter-page.js
Show inline comments
...
 
@@ -33,45 +33,46 @@ $(document).ready(function() {
 
        $control.find('.toggle-content').slideDown("slow");
 
    });
 
    $(".t-shirt-size-selector").hide();
 
    $('input[name=os1]:radio').change(function() {
 
        var input=$(this);
 
        var value = input.val();
 
        if (value == "Yes") {
 
            $(".t-shirt-size-selector").show();
 
        } else {
 
            $(".t-shirt-size-selector").hide();
 
        }
 
    });
 
    $('#amount').addClass("valid");
 
    $('#amount').on('input', function() {
 
    $('.amount').addClass("valid");
 
    $('.amount').on('input', function() {
 
        var input=$(this);
 
        var value = input.val();
 
        var errorElement=$("span", input.parent());
 
        var noCommaValue = value;
 
        noCommaValue = value.replace(/,/g, "");
 
        var re = /^((\d{1,3}(,?\d{3})*?(\.\d{0,2})?)|\d+(\.\d{0,2})?)$/;
 
        var isValid = ( re.test(value) && parseInt(noCommaValue) >= 120);
 
        var isValid = ( re.test(value) &&
 
                        parseInt(noCommaValue) >= parseInt(input.attr("minimum")));
 
        if (isValid)  {
 
           input.removeClass("invalid").addClass("valid");
 
           errorElement.removeClass("form-error-show").addClass("form-error");
 
           $("#form-correction-needed").removeClass("form-error-show").addClass("form-error");
 
        }
 
        else {
 
            input.removeClass("valid").addClass("invalid");
 
            errorElement.removeClass("form-error").addClass("form-error-show");
 
        }
 
    });
 
    $("#supporter-form-submit").click(function(event){
 
	var valid = $('#amount').hasClass("valid");
 
	var valid = $('.amount').hasClass("valid");
 
        if (! valid) {
 
            $("#form-correction-needed").removeClass("form-error").addClass("form-error-show")
 
                                        .css("font-weight", "bold").css("font-size", "150%");
 
	    event.preventDefault();
 
        } else {
 
            $("#form-correction-needed").removeClass("form-error-show").addClass("form-error");
 
        }
 
    });
 
    /* Handle toggling of annual/monthly form selections */
 
    $('.supporter-type-selection#monthly').hide();
 
    $('#annualSelector').css("font-weight", "bold").css("font-size", "127%");
 

	
www/conservancy/static/supporter/index.html
Show inline comments
...
 
@@ -131,25 +131,25 @@ internal policies</a> are published and available for scrutiny.</p>
 
<hr/>
 
  <strong>Become a Supporter Now:</strong>  <a id="annualSelector" href="#annual">Annual</a> | <a id="monthlySelector" href="#monthly">Monthly</a></div>
 
<div id="annual" class="supporter-type-selection">
 
<h3>Join as an Annual Supporter</h3>
 
<a id="annual"></a>
 
<form id="supporter-form" action="https://www.paypal.com/cgi-bin/webscr" method="post" name="supporter">
 
<div id="supporter-form-inputs">
 
            <input type="hidden" name="return" value="https://sfconservancy.org/supporter/thank-you.html" />
 
            <input type="hidden" name="cmd" value="_xclick" />
 
            <input type="hidden" name="business" value="supporter@sfconservancy.org" />
 
            <input type="hidden" name="item_name" value="Conservancy Supporter, Annual" />
 
  <label for="amount"><strong>Amount:</strong> $</label>
 
  <input id="amount" type="text" name="amount" size="7" value="120" />
 
  <input class="amount" type="text" name="amount" size="7" minimum="120" value="120" />
 
  <span class="form-error"><small>$120 is a minimum for Conservancy
 
  Supporters.  <a href="/donate">Donate smaller amounts here</a>.</small></span><br/>
 

	
 
                      <label for="wantGift"><strong>Do you want to receive a t-shirt? </strong></label>
 
                      <input type="hidden" name="on1" value="wantGift" />
 
                      <input type="radio" name="os1" value="Yes" />Yes
 
                      <input type="radio" checked="checked" name="os1" value="No" />No
 
                      <br />
 
                      <span class="t-shirt-size-selector">
 
                      <label for="wantGift"><strong>T-shirt size: </strong></label>
 
                      <input type="hidden" name="on3" value="size"/>
 
                      <select name="os3" id="os3">
...
 
@@ -185,28 +185,39 @@ internal policies</a> are published and available for scrutiny.</p>
 
        card, bank account or PayPal balance payment methods.  Select options first.</small>
 
                      </div>
 

	
 
</form>
 
</div>
 
<div id="monthly" class="supporter-type-selection">
 
<h3>Join as an Monthly Supporter</h3>
 
<a id="monthly"></a>
 
<p>Monthly supporters will not receive any supporter benefits (including the t-shirt) until they've been
 
  monthly supporters for 12 months.</p>
 
<form id="supporter-form" action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
 
<div id="supporter-form-inputs">
 
            <input type="hidden" name="business" value="supporter@sfconservancy.org" />
 
            <input type="hidden" name="item_name" value="Conservancy Supporter, Monthly" />
 
            <input type="hidden" name="return" value="https://sfconservancy.org/supporter/thank-you.html" />
 
            <input type="hidden" name="cmd" value="_s-xclick">
 
            <input type="hidden" name="cmd" value="_xclick-subscriptions">
 
            <input type="hidden" name="lc" value="US">
 
            <input type="hidden" name="no_note" value="1">
 
            <input type="hidden" name="t3" value="M" />
 
            <input type="hidden" name="p3" value="1" />
 
            <input type="hidden" name="src" value="1" />
 
            <input type="hidden" name="srt" value="0" />
 
            <input type="hidden" name="item_name" value="Conservancy Supporter, Monthly" />
 
            <input type="hidden" name="hosted_button_id" value="UU7VBCXYV7UPQ">
 
  <label for="amount"><strong>Monthly Amount:</strong> $</label>
 
  <input class="amount" type="text" name="a3" size="5" minimum="10" value="10" />
 
  <span class="form-error"><small>$10/month is a minimum for Conservancy
 
  Supporters.  <a href="/donate">Donate smaller amounts here</a>.</small></span><br/>
 
                      <label for="wantGift"><strong>Do you want to receive a t-shirt? </strong></label>
 
                      <input type="hidden" name="on1" value="wantGift" />
 
                      <input type="radio" name="os1" value="Yes" />Yes
 
                      <input type="radio" checked="checked" name="os1" value="No" />No
 
                      <br />
 
                      <span class="t-shirt-size-selector">
 
                      <label for="wantGift"><strong>T-shirt size: </strong></label>
 
                      <input type="hidden" name="on3" value="size"/>
 
                      <select name="os3" id="os3">
 
                        <option name="os3" id="os3" value="MenS">Men's S</option>
 
                        <option name="os3" id="os3" value="MenM">Men's M</option>
 
                        <option name="os3" id="os3" value="MenL">Men's L</option>
0 comments (0 inline, 0 general)