Paypal Buy Now button for multiple items - paypal

I want to add a buy now button to my website. I already have a cart system and I need to send all the items to checkout with Paypal buy now button.
A few years back I remember using the buy button with a form and I could set multiple items by specifying multiple hidden inputs like:
<input type="hidden" name="item_name_1" value="item name 1">
<input type="hidden" name="item_name_2" value="item name 2">
...
<input type="hidden" name="item_name_n" value="item name n">
Now with the new buy button JS API I can't seem to do that anymore.
Am I missing something here? How can I add a buy button for multiple items?

You can still use an HTML form to create the buttons and use the Upload command.
The JavaScript buttons aren't currently available to work with the Upload command unless you modify the associated JavaScript file. The Mini-Cart does kind of use the Upload feature. If you want to take a look at that it may offer you the functionality you're after. There should be a link to it from the "PayPal payment buttons" page.

Related

PayPal ignoring "return" variable on PayPal Subscribe Button, even though "Auto return" option is enabled

PayPal is ignoring my return variable on PayPal Subscribe Button, even though "Auto return" option is enabled.
At first, I did not have the "Auto return" option enabled, and PayPal just showed a receipt page after the user subscribed, with no link back to our site, despite passing the return variable with our receipt page.
Then we enabled the "Auto return" option and was forced to enter some URL, so we created a generic page for PayPal to hit to verify the page exists, which I understand is required to enable the feature.
However, now users are able to subscribe and they see that awesome "If you are not redirected... in 10 seconds... click here" message, which takes the user to the static return page we setup in the "Auto return" settings, not the dynamic URL we passed to PayPal using the return variable.
Here's what our button code looks like:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="MYHOSTEDBUTTONID">
<input type="hidden" name="custom" value="MyCustomData">
<input type="hidden" name="return" value="https://www.example.com/secure/page/receipt?specialId=1234">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_subscribeCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
Did PayPal break this feature or am I doing something wrong?
For hosted buttons, the return doesn't belong there, it should be in the Advanced Variables section of step 3 of creating the button.
These HTML buttons are deprecated, they are from ~18 years ago and some new PayPal accounts can no longer create them (my understanding is all will not be able to create them soon enough.) The recommended integration method is a "Smart Subscribe" button, which uses JS and a client ID to identify the receiver account. To be notified of completed payments with a smart subscribe button, create a listener URL on your server for the webhook event PAYMENT.SALE.COMPLETED (that is the only subscription webhook event that is truly useful, all others are of limited utility). As for redirecting a Smart payer, if you need to do that you can add a window.location.href redirect from the onApprove function. Modern websites don't redirect unless they absolutely need to, consider using this function to display whatever message in the DOM w/o a redirect. But don't depend on sending data to a server from the client onApprove, as for whatever reason the client may never notify the server. The PAYMENT.SALE.COMPLETED webhook is the only reliable way to get notifications. For reconciliation, there is a similar custom_id variable available alongside the plan_id when creating the subscription in the createSubscription function.

Finding PayPal Buy Now Button redirection link

I am trying to make a program that can scrape a site and search for PayPal buy now button redirection links.
I can scrape the site but I realize that when you hit the button, it does not contain the URL that you will be redirected to make purchase. How would I go about finding the button redirection link, or even how would I have the site scrape and click on the button to at least have the redirect site appear? Would I somehow have to make the scraper hit the form and submit?
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top"><input name="cmd" type="hidden" value="_s-xclick" /><br />
<input name="hosted_button_id" type="hidden" value="PUEGWVJXLH4FQ" /><br />
<input alt="PayPal - The safer, easier way to pay online!" name="submit" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" type="image" /><br />
<img loading="lazy" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" alt="" width="1" height="1" border="0" /></form>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">_______________________________________________________</p>
</form>
Go to https://www.paypal.co/buttons, log in, and (after logging in) create a new simple Buy Now button with no dropdown options nor text fields (which require HTML) -- and once the button is created and you are viewing the generated code, switch over to the "E-mail" tab above it.
The link in that E-mail tab will have a hosted button ID, which you can swap out / use to dynamically generate the Buy Now "redirection link" you're asking for. When loaded in a browser, that link will initiate a checkout, same as clicking the button.
There are several other types of PayPal payment buttons, including:
Unhosted Buy Now buttons (which are not saved at PayPal, and do not have a hosted_button_id). These buttons use a redirection link or form post that will include HTML variables to set up the payment.
Newer smart buttons, generated via https://www.paypal.com/buttons/smart or similar -- these do not have redirection URL, and instead use JS to open a mini window for payment approval.
Another way to construct a working URL is to begin with the form's action parameter https://www.paypal.com/cgi-bin/webscr, add ? to begin a GET string, and add all the inputs from the form that have a name, in with the syntax name=value, separated by '&' .... so for example:
https://www.paypal.com/cgi-bin/webscr?hosted_button_id=PUEGWVJXLH4FQ&anothername=anothervalue&...

View Paypal shopping cart contents on my site

I have paypal "add to cart" buttons set-up throughout my site and a "view cart" button at the top of every page.
The code for the view cart button is:
<form target='paypal' action='https://www.paypal.com/cgi-bin/webscr' method='post'>
<input type='hidden' class='displaynone' name='cmd' value='_cart' />
<input type='hidden' class='displaynone' name='business' value='XXXXXXX123' />
<input type='hidden' class='displaynone' name='display' value='1' />
<input type='submit' class='paypalcart' value='View Cart' />
</form>
Currently, clicking "view cart" opens up a new browser tab and displays the items added on a paypal website.
Instead, I'd like clicking the "view cart" button to take the user to my page www.example.com/cart and then have the contents of the paypal cart displayed on that page in a <div> or <iframe> (or something else).
Any suggestions?
Thanks very much.
You need to build a custom cart into your website instead of using the PayPal cart. There are a number of ways to do this. Are you using WordPress, by chance? If so, I'd recommend installing WooCommerce, and then the PayPal for WooCommerce plugin.
If you're using some other type of framework you may be able to find a nice shopping cart solution for it. Otherwise, you'd just have to build it yourself.
Then you can either use the cart upload method to send cart details to PayPal for checkout, or you could go with the Express Checkout (which I would recommend) if you're familiar with web service API's.
You can use Minicart Js. Source which really dont suit your requirement, but it does'nt redirect to paypal site when you click "Add to Cart" instead opens lightbox inside your own website eventually when you click "Checkout" it takes you to paypal checkout page.
Sample Demo

PayPal Buy Now button on my site with redirection issue

I must be going crazy, or I'm completely lost when it comes to understanding what is doable when it comes to PayPal buttons on my site - either way I must apologise if this seems obtuse.
I'm building a custom CMS for my clients, and I'm trying to let them utilize PayPal on their sites by simply entering in either their merchant ID, or their PayPal e-mail address, and then let CMS will do the rest. Ideally:
Client enters merchant ID / PayPal e-mail address into CMS backend
CMS generates "Buy Now" button for client's buyers to click on
Buyer pays on PayPal's site
Buyer gets redirected to client's site
My headache disappears
This seems to be easier said than done. I've read the developer documentation on generating your own buttons, and used that Javascript-based button generator to create a button with an IPN callback, but that's not going to redirect the buyers back to my clients' websites.
Thus my questions: is it at all possible to achieve what I'm looking to do with just my clients' merchant ID's? Is it possible to do it without them having to configure anything additional in their PayPal account settings to avoid set-up issues? Should I be looking at a different PayPal processing mechanism instead of the "Buy Now" button?
I should probably mention that I have a free PayPal account, not a Premium or Business account, but that should be irrelevant to this situation as it's not me that's trying to get paid.
Thanks in advance, and any help is GREATLY appreciated!
create a hidden field named 'return' in your form and put your return URL as the 'value'
A thank you to Billy for his answer, and while researching this topic some more, I've discovered that what I'm looking to do CANNOT be done with the current payment standards buttons on a standard free PayPal account. You can't achieve automatic redirection back to your site from PayPal with the Buy Now button.
As Billy mentioned, you can add return URLs that will give the user the option to click on a link that will return them to your site afterwards (PayPal will add these links to their side of operations themselves). To do this you would need to add the appropriate hidden fields to your PayPal form.
This worked for me:
<form method="post" action="https://www.paypal.com/cgi-bin/webscr">
<input type="hidden" name="button" value="buynow">
<input type="hidden" name="item_name" value="Item 1">
<input type="hidden" name="amount" value="1234.56">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="quantity" value="1">
<input type="hidden" name="env" value="www">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="return" value="http://www.site.com/success">
<input type="hidden" name="cancel_return" value="http://www.site.com/error">
<input type="hidden" name="business" value="your#email.com">
</form>
I hope this helps someone avoid headache and unnecessary documentation scouring!

PayPal IPN - minimum fields required for a purchase button?

I am using "buy it now" PayPal buttons but I DO NOT want to use the previously saved buttons on my PayPal account, I want to create a custom form that has a submit button. However, I need to know which fields are the minimum required ones for a form. I thought it would be something like this
<input type="hidden" name="cmd" value="_s-xclick" >
<input type="hidden" name="business" value="me#myemail.com" >
<input type="hidden" name="item_name" value="some item name" >
<input type="hidden" name="item_number" value="some item number" >
<input type="hidden" name="amount" value="10.00" >
But this keeps on kicking back as an unpecified error on PP. Any thoughts?
The following link has a minimal example: https://www.paypal.com/cgi-bin/webscr?cmd=_pdn_xclick_techview_outside . The most important parts are making sure the action is correct and the cmd field is correct. (I'm not familiar with _s-xclick as a command – I always use _xclick myself – but my knowledge in the area is admittedly a bit dated.)
For more tips on making the form just right, I recommend poking around on the PayPal Developer network: https://www.x.com/index.jspa
Also, please note: PayPal IPN is a feature that does callback posts from PayPal to you, the merchant, after a purchase is made, and doesn't quite seem to be what you're working with here, which is the button's form posted from the user's browser to PayPal. This form submission in a buy-now button is just considered part of the buy-now button feature.