PayPal: skip trial period - paypal

I have created a hosted PayPal button for monthly subscription and included its code on my website.
The subscription offers a free trial period of 1 week.
I would like to check if the user has already used their trial and is trying to subscribe again. And if so, how do I let PayPal know that it should not allow a trial period for that user?
The button's code looks something like this:
<form action="https://www.sandbox.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="ABCDEFGHIJKLM">
<input type="hidden" name="on0" value="Your email">
<label for="plan-email">Your email</label>
<input id="plan-email" type="email" name="os0" placeholder="joanne.doe#gmail.com" required maxlength="200">
<button type="submit">Subscribe</button>
</form>
It would be even better, if you know a way to use Subscription Plan (created in https://www.paypal.com/billing/plans) as an HTML form similar to the one above (pure HTML form, without using PayPal JavaScript SDK) instead of a Button (created in https://www.paypal.com/buttons/). I need to pass an extra option (user's email) to PayPal as well as whether to allow a trial period or not.

Related

Why would paypal notification URL different

Okay, so we have a member site using Joomla, and a component that allows users to perform certain tasks (creating teams). They are allowed to login, and create a team, but they can't add members to this team until they pay a $25.00 fee.
This happens through Paypal IPN. There is essentially this form below... (some personal data removed).
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="item_name" value="<?php echo $item_name;?>">
<input type="hidden" name="business" value="blah#blah.com">
<input type="hidden" name="amount" value="25">
<input type="hidden" name="quantity" value="1">
<input type="hidden" name="no_note" value="1">
<!--<input name="userId" value="<?php //echo $user->id;?>" type="hidden">-->
<!--<input name="task" value="paypal_register" type="hidden">-->
<input type="hidden" name="currency_code" value="USD">
<!-- Enable override of buyers's address stored with PayPal . -->
<!-- Set variables that override the address stored with PayPal. -->
<input type="hidden" name="return" value="<?php echo JURI::ROOT().'index.php?option=com_fastball&view=payment&task=paypal_register';?>">
<input type="hidden" name="notify_url" value="<?php echo JURI::ROOT().'index.php?option=com_fastball&view=payment&task=paypal_register&userId='.$user->id.'&ipn=1';?>">
<!--<input type="image" name="submit" border="0" src="https://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif" alt="PayPal - The safer, easier way to pay online">-->
</form>
Now sometimes the IPN redirects and works just fine. But other times it cuts the url short from "index.php?option=com_fastball&view=payment&task=paypal_register&userId=" to "index.php?option=com_fastball", therefore not activating the view in Joomla that contains the code to update the database on notification.
It seems fairly random. There are several scenarios, 1 - New User Creating New Team. 2 - Old User Creating New Team. 3- Old User Renewing Old Team.
But regardless of that, they ALL hit this payment form button with THESE notify URL as hidden input.
So I'm not sure where paypal is either A.) Getting the shortened URL, or B.) They are cutting it short for some reason. It returns to the shortened URL with all of the Paypal Post info showing in the URL Parameters (&st=Completed&amt=25.00 etc from paypals servers)
This has been extremely frustrating and I may not have explained it well so if you have any questions or thoughts, just let me know. Thanks!
For URL paths you should use JURI::base() not JURI::ROOT. You can check the documentation here https://docs.joomla.org/Constants.
This appears to be a recent PayPal problem. All the urls (return, cancel_return, and notify_url) PayPal is stripping the url of all content after the first '&'.
Note also that the issue appears to be intermittent; it may be dependent on the PayPal server you connect to (QueryString values removed from the IPN endpoint by PayPal).
I have made some modifications to my own PayPal form replacing just the '&' with '&' (the encoded version) and that seems to work.

Paypal - Dynamic Buy button to charge our clients customer

I need to implement a method where we can allow a clients customer to make a payment to the client via our website - all of which will be setup via our custom CMS.
Our initial plan was to use the following form script to generate a transaction and ask the client to add a return address to our website.
<form name="_xclick" action="https://www.paypal.com/uk/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="someone#someon.com">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="item_name" value="2 x sessions">
<input type="hidden" name="amount" value="50">
<input type="image" class="btn btn-default nom paypalBtn" src="" border="0" name="submit" alt="£50">
</form>
This would potentially work fine - as we could dynamically add the value, business email and item name. Though we are worried that any web savvy person could simply inspect the form in a browser and change the payment value to a more pleasing figure! So we feel we need a better solution.
Does anyone have any suggestions for a cleaner solution?
Log into your PayPal account, click on Merchant Services at the top of the page and then click one Create Payment Buttons for your website. When you create buttons on PayPal they are hosted and secure.

Multiple items with different tax rates on a PayPal Website Payments Standard button

I am creating an e-shop builder, i.e. a site where a user creates their site and e-shop. The products are entered into my custom CMS by the person who builds the e-shop. I ask the shop builder to link the shop to their PayPal account by entering their e-mail.
I am currently trying to create a checkout button for my cart.
Problem is, multiple products might have different tax rates, for instance alcoholic beverages might have a 13% tax rate whereas other products have 23%. Is there a way to incorporate this in the post request?
Ideally what I would like to do is this:
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="item_name_1" value="Some product">
<input type="hidden" name="item_number_1" value="1">
<input type="hidden" name="amount_1" value="20.00" />
<input type="hidden" name="tax_rate_1" value="23">
<input type="hidden" name="item_name_2" value="Some alcoholic product">
<input type="hidden" name="item_number_2" value="1">
<input type="hidden" name="amount_2" value="15.00" />
<input type="hidden" name="tax_rate_2" value="13">
<!-- other fields omitted for brevity -->
</form>
The tax_rate_1 and tax_rate_2 fields are hypothetical, I don't know if something like this is possible.
If I RTFM'ed correctly, setting per-item tax rates should be possible if you register the products yourself in the PayPal website interface. This is exactly what I am trying to avoid, because the products are entered by the end user on my CMS.
If what I want isn't possible with a Website Payments Standard button, I would also welcome other ideas on how to forward such orders to PayPal. I am trying to avoid the Express Checkout payment product because if I understand correctly I won't have full control of the cart. I want to have a custom cart and later be able to offer more payment options besides PayPal.
Please help in any way you can! I am a total noob with PayPal.
To answer my own question, what I want is indeed possible and is described in the manual. In my situation where I have built a custom shopping cart, I want to use the Cart upload command of the Website Payments Standard product.
To do a "cart upload" I've set the following fields:
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
The variables are tax_1, tax_2, etc. They need to be specified as currency, not percentage.

Paypal: trying to pass an amount with a Donation button

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">

Trying to setup Paypal registration form, need some help!

I'm trying to setup a registration form for some workshops that last a week. Basically, they can sign up for the workshops individually or the whole week. Depending on what they select, the price will change. I get how to send this information to paypal, however I also want to submit information to my own DB. How would I submit to paypal and file the info into my DB at the same time?
I also want to have a variable that is returned that verifies they have paid so I can mark it in my DB.
Would I just have another page that would put all this info into the DB (once submitted) then also put the info into hidden form fields and then automatically submit to paypal?
Thanks in advance! :)
"When payment is successful your user is returned to your self which is when you can record the payment in the db."
That's exactly what you shouldn't be doing.
Depending on a buyer to return to your website in order to update an order status is the worst thing you can do.
PayPal IPN was designed with especially this use case in mind.
Simply add in
This will ensure PayPal will POST to you whenever the payment has completed. Even if your buyer has already closed his/her browser.
You can use the 'custom' fields to link an IPN POST to a transaction made on your site. For example:
will ensure you get an IPN POST with $_POST['custom'] of '1122334455'. From there, it's simply a matter of making a db call to update the order status to 'paid', or whatever you use to mark it as payment received.
Oh, and don't forget to post the data back to https://www.paypal.com/cgi-bin/webscr?cmd=_notify-validate to validate the IPN POST. More info is available at https://www.paypal.com/ipn/
So I guess you are probably using Website payment standard.
If so the process is like this:.
Users signs up for a particular workshop using your form (select prices, time etc etc)
On submit you process the form (check validation etc)
If you happy with this then you generate a from that is automatically posted to paypal that looks like this:
<body onLoad="document.forms['paypal_auto_form'].submit();">
<p>Please wait</p>
<form method="post" action="https://www.paypal.com/cgi-bin/webscr" name="paypal_auto_form"/>
<input type="hidden" name="rm" value="2" />
<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="currency_code" value="AUD" />
<input type="hidden" name="quantity" value="1" />
<input type="hidden" name="business" value="PAYPAL#EMAIL.COM" />
<input type="hidden" name="return" value="http://domain.com/paypal/success" />
<input type="hidden" name="cancel_return" value="http://domain.com/paypal/cancel" />
<input type="hidden" name="notify_url" value="http://domain.com/paypal/ipn" />
<input type="hidden" name="custom" value="1234567890" />
<input type="hidden" name="item_name" value="Paypal Test Transaction" />
<input type="hidden" name="item_number" value="6941" />
<input type="hidden" name="amount" value="197" />
<p><input type="submit" name="pp_submit" value="Pay Now!" /></p></form>
</body>
The values you of course customize to what you want. Look at Appendix A of the paypal documentation for the variables. You can also add your own log with cpp_header_image or something like that.
The users is taken to paypal to process payments
When payment is successful your user is returned to your self which is when you can record the payment in the db. You might use some for of key or cookie variable to track the payment they have made.
You probably want to use the IPN to double check that it was successfully paid.
If all this is too hard just use http://wufoo.com/ and add the payment module to the form.