Hello, I would like to create a Paypal purchase button that has a dynamic amount set. I would like to pass the amount to the input text field on the form and item_number using a hidden field.
The problem is that ever I get an encrypted s-xclick button from paypal. This button does not allow you to put hidden variables in the form.
I think I need an xclick button. My goal is to allow users to increase their internal credit on my site.
EDIT (by moving the appendix to the question from the answer to the question) (from here @tokam:
To add this to the discussion, I would like to show my current solution to the problem:
Here we have some Javascript validation that helps the user with input. Admit it opens lightbox with success
function validatePaypalForm() { var val = $('#paypalPaymentAmount').val().replace(/\s*$/, "").replace(/,/ , ".").replace(/€$/, ""); var errormsg = ''; var ret, amountField; if( val==='' || isNaN( parseFloat(val) ) || !isFinite(val) ) { errormsg = 'Bitte geben Sie einen gültigen Betrag an'; }else if( parseFloat( val ) < <?php echo $this->minimum?> ) { errormsg = 'Das Einzahlungsminimum beträgt <?php echo $this->minimum?>€'; } ret = ( errormsg === '' ); amountField = $( '#paypalAmountField' ); if( ret ) { amountField.removeClass( 'error' ); $('#paypalAmountErrorMessage').html( ' ' ); $('#paypalPaymentAmount').val( val ); fb.start( '<p><strong>Sie werden in kürze zur Seite von Paypal weitergeleitet.</strong></p>', 'width:700 showPrint:false modal:true showClose:false showOuterClose:true showItemNumber:false closeOnNewWindow:false outsideClickCloses:true innerBorder:0 imageClickCloses:false scrolling: no' ); }else{ amountField.addClass( 'error' ); $('#paypalAmountErrorMessage').html( errormsg ); } return ret;
} Now comes my button. The problems that I encounter are, for example, that it is easy for a user to set a different currency code. I could handle this in my IPN listener by refunding the payment. Are there other problems with unencrypted button changes?
<form onsubmit="return validatePaypalForm();" class="stn-form" action="https://www.paypal.com/cgi-bin/webscr" method="post"> <fieldset id="fieldset-p"><legend><span>2.</span>myproject Guthaben aufladen per Paypal Zahlung</legend> <div id='paypalAmountField' class="field"> <label for='paypalPaymentAmount' >Betrag €:</label> <input id='paypalPaymentAmount' type="text" name='amount' value='' /> <span style='display:block;' id='paypalAmountErrorMessage' class='errorText'>' </span> </div> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="business" value="THE_ID_OF_MY_CLIENT"> <input type="hidden" name="lc" value="DE"> <input type="hidden" name="item_name" value="myproject Advertiser Vorkasse"> <input type="hidden" name='item_number' value="11500"> <input type="hidden" name="currency_code" value="EUR"> <input type="hidden" name="button_subtype" value="services"> <input type="hidden" name="no_note" value="1"> <input type="hidden" name="no_shipping" value="1"> <input type="hidden" name="bn" value="PP-BuyNowBF:btn_paynowCC_LG.gif:NonHosted"> <input type="hidden" name="rm" value="1"> <input type="hidden" name='cbt' value="Zu myproject.de zurückkehren"> <input type="hidden" name="currency_code" value="EUR"> <input type="hidden" name="return" value="http://myproject.somedomain.net/advertiser/guthaben-aufladen/ret/success" /> <input type="hidden" name="cancel_ return" value="http://myproject.somedomain.net/advertiser/guthaben-aufladen/ret/canceled" /> <div class="actionrow"> <input type="image" src="https://www.paypalobjects.com/de_DE/DE/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="Jetzt einfach, schnell und sicher online bezahlen – mit PayPal."> <img alt="" border="0" src="https://www.paypalobjects.com/de_DE/i/scr/pixel.gif" width="1" height="1"> </div> </fieldset> </form>
source share