I have a page using Paypal Payments Standard with "buy one now" buttons on many products such as this.
<form id="form1" target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="image" name="submit2" align="right" src="https://www.paypal.com//en_US/i/btn/sc-but-03.gif" alt="Make payments with PayPal - it's fast, free and secure!" />
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="business" value="email#gmail.com" />
<input type="hidden" name="no_note" value="1" />
<input type="hidden" name="add" value="1" />
<input type="hidden" name="lc" value="US" />
<input type="hidden" name="return" value="http://domain.com/confirm.html" />
<input type="hidden" name="cancel_return" value="http://domain.com" />
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="bn" value="PP-ShopCartBF" />
<input type="hidden" name="amount" value="5.00" />
<input type="hidden" name="item_name" value="A009" />
</form>
The above code is repeated down the page for each product where only the form id's and product numbers are changed. In this case, all products are the same price.
Before jQuery, I would just put all the repetitive parts within an SSI.
However, now I'm learning jQuery and I'd like to reduce this all to a text link instead of the PayPal button and embed the product number within the link. This link would not be between any form tags if possible.
<a class="cartBuy" href="#" id="A009">Add to Cart</a>
I know I can select my links like this...
$('.cartBuy a[id]')
But now I'm a little lost. How can I use jQuery to submit this form? Will I still need to surround my link with form tags? The whole point of this is so that I don't have to have a unique form for every single product... just a single link for each product and let one script construct something that gets submitted (via ajax?). I looked at the jQuery Form Plugin but I'm lost with this too as it looks like I'd still need to have every item inside a unique form element. I also looked at having jQuery write all the HTML for each form but that's not really much different than what I was doing before with SSI.
(These are "buy one now" links so there is no need to keep track of multiple selections... simply want to submit each one at a time.)
Thank-you!
ANSWER:
I used the Answer below by Josh Leitzel.
I included one form element on the page which contained all the hidden input elements common to everything.
I totally removed the submit button from the form since it's not needed.
I added a hidden input element to the one form for the item_name with a blank value.
The way you would do this would be to select the reference ID from the link when it's clicked, write it to the appropriate form input, and then submit the form:
$('.cartBuy a').click(function(){
var id = $(this).attr('id'); // gets the item name from the link's id
$('#form1 input[name=item_name]').val(id); // writes the item name to the form field
$('#form1').submit(); // submits the form
return false; // prevents the link from being followed
});
Related
I asked these questions in PayPal's forum but I did not receive any answers. Hopefully, I'll get them here :)
So as I understand if I want to integrate subscriptions I can do it 2 ways
First one is to integrate subscription button using a form, something like this:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<!-- Identify your business so that you can collect the payments. -->
<input type="hidden" name="business" value="businessEmail">
<!-- Specify a Subscribe button. -->
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<!-- Identify the subscription. -->
<input type="hidden" name="item_name" value="Alice's Weekly Digest">
<input type="hidden" name="item_number" value="DIG Weekly">
<!-- Set the terms of the regular subscription. -->
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="a3" value="5.00">
<input type="hidden" name="p3" value="1">
<input type="hidden" name="t3" value="M">
<input type="hidden" name="notify_url" value="notify url">
<!-- Set recurring payments until canceled. -->
<input type="hidden" name="src" value="1">
<!-- Display the payment button. -->
<input type="image" name="submit"
src="https://www.paypalobjects.com/en_US/i/btn/btn_subscribe_LG.gif"
alt="Subscribe">
<img alt="" width="1" height="1"
src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" >
I guess this approach has more drawbacks than benefits, it allows me to create a subscription without creating a product and a plan for the subscription..?
But on the other hand, a user that created a subscription in this way cannot change subscription, only cancellation is possible? Furthermore, I cannot change 'notify_url' if I for example change my website?
The second way to create subscriptions is to use subscriptions API. Create Product and a Plan, as I understand this gives us much more control and removes the drawbacks of the HTML form subscription.
Thank you!
Everything you said is correct, the only thing I would add is that there is also a generator you can use for the old HTML 'Subscribe' and new JS 'PayPal Subscribe' buttons at: https://www.paypal.com/buttons
If you want the old generator to create editable code, you should uncheck the Step 2 option to Save the button at PayPal, then after generating the button click the link above to remove code protection.
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">
<input type="hidden" name="business" value="dummy#example.com">
<input type="hidden" name="cmd" value="_xclick-auto-billing" /> <!-- _xclick-subscriptions works here -->
<input type="hidden" name="a3" value="1" />
<input type="hidden" name="p3" value="12" />
<input type="hidden" name="t3" value="M" />
<input type="hidden" name="src" value="1" />
<input type="hidden" name="no_note" value="1" />
<input type="submit" name="submit" />
<input type="hidden" value="PP-SubscriptionsBF" name="bn">
</form>
I was trying to find out what the differences are between _xclick-subscriptions and _xclick-auto-billing. Above form works when the cmd value is _xclick-subscriptions. However, when I replace it with _xclick-auto-billing, Paypal returns an error page saying "item amount" is incorrect. I check Paypal's documentation but there isn't much explanation or example about _xclick-auto-billing. So how should I use this cmd and what are the differences?
In general, auto-billing should not be used unless you are able to generate a sample auto billing button via https://www.paypal.com/buttons
When doing so, uncheck the option in section 2 to save the button at PayPal. When viewing the generated code, click the option to remove the code protection. Then you will have sample working HTML that you can adapt to your needs.
If you cannot create such a button, it is because your account does not support it. Subscriptions are much more widely supported and should be used instead, generally speaking.
Instead of the old-style Subscribe button, consider the new Smart Payment Buttons which use plans and products as a base and offer a much more modern checkout experience. See https://www.paypal.com/billing/plans
I'm hoping there's an accepted method for this, as I seem to be able to get it to kind of work.
I have a donate form that has an optional 'One-off/Every month' select box.
Ideally the user should be able to either donate a one-off amount, or create a donation subscription.
The issue I'm facing is that there's a subscription button, and there is a donate button, but no donate subscription button.
So the code I've cobbled together so far almost works:
<form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_donations" />
<input type="hidden" name="no_note" value="1" />
<input type="hidden" name="a3" value="5.00" />
<input type="hidden" name="p3" value="24" />
<input type="hidden" name="t3" value="M" />
<input type="hidden" name="src" value="1" />
<input type="hidden" name="sra" value="1" />
<input type="hidden" name="bn" value="PP-DonationsBF:btn_donateCC_LG.gif:NonHostedGuest" />
<input type="hidden" name="business" value="X" />
<input type="hidden" name="currency_code" value="GBP" />
<input type="hidden" name="no_note" value="0" />
<input type="hidden" name="return" value="X" />
<input type="hidden" name="item_name" value="X" />
<input type="submit" name="submit" value="Donate now" />
</form>
(X replacing sensitive values)
So this will pass the user to a page that at least looks kind of right:
It's a donation form, with a subscription checkbox - almost there!
However you'll notice that the amount isn't present, and the recurring box isn't ticked.
If I include the amount attribute with the form then none of the subscription bits show up, and it reverts to a standard donation page.
Is what I'm trying to do actually possible? I mean it really should be, but the only content on the PayPal site that refers to it (via a Google search) takes me to a 404 page, so who knows: https://www.paypal.com/webapps/mpp/get-started/create-recurring-donation-button
(It's also not on the WayBack machine, unfortunately)
The description text on Google looks promising… so I'll keep my fingers crossed that somebody knows what used to be on that page…
Edit: The above link appears to be functioning correctly now. Must be due to some weird territory/permissions bug, as yesterday while logged in it was just a 'Sorry this page does not exist' page; logging out seems to have granted me access to PayPal's knowledge.
However the content is a tad ambiguous (maybe):
The instructions below will show you how to create a recurring donation button by creating a Subscription button, then changing some of the HTML … to make it appear as a Donate button.
I'm not sure I really see any advantage to this - are they saying this process will create a subscription button that just looks like a donation button? Not sure what the purpose of that would be…
After speaking with PayPal this morning on the phone I can confirm that #geewiz and the common advice is definitely the way to go. i.e. just use a standard subscription.
The piece of the puzzle I was missing (partially due to this being work for a client) is that the fee's applied are based on the account, not the payment type. i.e. a 'donation' through paypal is no different than any other payment, it's just a different button (and a slightly modified form at the other end).
If you're registered as a charity etc. then a standard subscription is sufficient, and the walkthrough provided by PayPal in my OP is the best resource for that. Just be warned that you might see a 'Sorry, that page doesn't exist' message when visiting the link. Logging out of PayPal worked for me.
I have a form that adds items to a cart. But I want to give them an option to ship the item to a store.
My form looks like this...
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="upload" value="1" />
<input type="hidden" name="business" value="XXXXXXXXXXXXXX" />
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="amount_1" value="19.99" />
<input type="hidden" name="item_name_1" value="MyCoolTshirt" />
<input type="hidden" name="quantity_1" value="2" />
<input type="image" src="Checkout-Button.jpg" name="submit" alt="cart add" />
</form>
Can I add a code in there that will deliver the comment to me, indicating "Ship to store" so customer can pickup instead of shipping it to them?
You can take a look at the standard variables list to see what all is available for you to use. There are a few different things you could do.
You could save everything into your local database first, complete with all notes or anything you'd want to reference. Then you can pass that "invoice ID" into the invoice parameter of your form, and you would always be able to relate back and pull that data from your own system.
You could also just use the "custom" parameter to pass anything you want up to 255 characters.
I'd browse through that list, though, as there could be lots of different things you decide you'd like to use.
I have a Donate button set up for the user to enter the donation amount. I am trying to send an amount with the button. I can enter amount=1.00 in the Add Advanced Variables in the button setup - that works fine. However, I have had no success sending the amount as part of the URL. I have added the following line to the PayPal button form:
<input type="hidden" name="amount" value="9.99" />
but the amount field is blank when I get to PayPal. Any thoughts what I am doing wrong?
If you're creating a so called 'hosted button' (that is, a button where the button details are stored on the PayPal side), then the 'amount' POST parameter is ignored for requests to https://www.paypal.com/cgi-bin/webscr.
This is a security feature to prevent people from being able to manipulate the amount passed to PayPal for checkout.
You can identify whether you're using a hosted button by the following data;
Hosted buttons will have a value for cmd of _s-xclick and include the hosted_button_id parameter.
If this is the case, you cannot update the amount by passing in an extra amount POST parameter.
However, because you're dealing with donations and the amount is flexible by definition, you don't in fact need a 'hosted button'.
In the button creation form, turn off 'Host button with PayPal', or write your own to point to PayPal.
If you do this, you can set the amount via the amount POST parameter.
For example, the below works fine;
<form method="POST" action="https://www.paypal.com/cgi-bin/webscr">
<input type="hidden" name="cmd" value="_donations">
<label for="amount">Amount: </label><input type="text" name="amount" value="">
<input type="submit" name="submit" value="Pay with PayPal">
</form>
Robert's solution is on the right track, however a non-hosted PayPal form will not work without the hidden "business" field (which should have a value of the email address associated with your PayPal account.)
Other fields should be included for thoroughness:
<input type="hidden" name="business" value="myemail#here.com">
<input type="hidden" name="item_name" value="Donation Description">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="tax" value="0">