Can I test my IPN listener VB.NET code under localhost (ASP.NET Web Forms)? - paypal-ipn

The 'Local development testing' section of PayPal's IPN Testing page implies that it is possible to test your IPN listener code via localhost, using a test page to simulate a message from PayPal.
My TestIPN.aspx page contains the following markup, which appears to follow the example provided by PayPal, but when I open it in Firefox under localhost (via Visual Studio 2019) and click the Submit Query button I get a 'File not found' error for https://localhost:44390/PayPal/IPNHandler.aspx.vb.
Needless to say, IPNHandler.aspx.vb does exist in my PayPal folder (using "PayPal/IPNHandler.aspx" in the form tag on my test page makes no difference). I also get the same error when I run it on my live site.
Any guidance on how to debug this problem would be much appreciated.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Test IPN message</title>
</head>
<body>
<!--
<form target="_new" method="post" action="https://www.YourDomain.com/Path/YourIPNHandler.php">
-->
<form target="_new" method="post" action="PayPal/IPNHandler.aspx.vb">
<input type="hidden" name="receiver_email" value="admin%40mysite.co.uk"/>
<input type="hidden" name="business" value="admin%40mysite.co.uk"/>
<input type="hidden" name="first_name" value="Fred"/>
<input type="hidden" name="last_name" value="Bloggs"/>
<input type="hidden" name="payer_email" value="fred.bloggs%40gmail.com"/>
<input type="hidden" name="address_city" value="Southampton"/>
<input type="hidden" name="payment_type" value="instant"/>
<input type="hidden" name="payment_date" value="19:54:19 Apr 12, 2021 GMT"/>
<input type="hidden" name="payment_status" value="Completed"/>
<input type="hidden" name="mc_currency" value="GBP"/>
<input type="hidden" name="mc_gross" value="5.00"/>
<input type="hidden" name="custom" value="25"/>
<input type="submit"/>
</form>
</body>
</html>

I get a 'File not found' error for https://localhost:44390/PayPal/IPNHandler.aspx.vb
Is that the correct port? What happens if you put https://localhost:44390/PayPal/IPNHandler.aspx.vb in the URL bar? Use a URL that works to the handler on your localhost, which does not return a 404. Set the action accordingly.
Consider something like https://ngrok.com for testing as well.
Why are you integrating IPN anyway? It's 20 or so years old, and not required for current PayPal Checkout integrations you should be using instead...
Follow the Set up standard payments guide and make 2 routes on your server, one for 'Create Order' and one for 'Capture Order', documented here. Both routes should return only JSON data (no HTML or text). Inside the 2nd route, when the capture API is successful you should store its resulting payment details in your database (particularly purchase_units[0].payments.captures[0].id, which is the PayPal transaction ID) and perform any necessary business logic (such as sending confirmation emails or reserving product) immediately before forwarding your return JSON to the frontend caller.
Pair those 2 routes with the frontend approval flow: https://developer.paypal.com/demo/checkout/#/pattern/server

Related

PayPal: skip trial period

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.

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.

How to integrate paypal on website

I have a paypal account but are completely new of how to set up a paypal solution on my website. I develop on my computer so the website is not up on the internet yet.
I will sell digital goods which are textfiles and ebooks.
I try to use the wizard: https://devtools-paypal.com/integrationwizard
So in step 2, this creates a button which I placed on my website including putting "paypalfunctions.php", "orderconfirm.php", "checkout.php", "cancel.php" in the rootdirectory of the website.
In the .php file, I have changed those to the ones in the sandbox:
$API_UserName="xxxxxx_api1.hotmail.com";
$API_Password="xxxxxxpassword";
$API_Signature="xxxxxxxxxxxxxxxxxxxxxxp.yxxxxxxxxx";
I have created a sandbox account here: https://developer.paypal.com/developer/applications
When I click the paypal button on my website. It opens up a small window which has the same content as my actual page on the website where I clicked the paypal button. I don't understand what is happening here.
Shouldn't paypal payment processing be opened in that window?
I don't know what I am missing to start to set this up correctly?
I don't really know where to begin?
Thank you
Stop trying to make it so difficult. Use my example below, it is extremely simple. This will give you an idea on how things work. Go from there.
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="item_name" value="ITERMNAME HERE">
<input type="hidden" name="business" value="PAYPAL-EMAIL-ACCOUNT-HERE">
<input type="hidden" name="cn" value="CUSTOM FIELD HERE IF YOU WISH">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynow_LG.gif:NonHosted">
<input type="submit" name="submit">SUBMIT</input>
If your file that contains the button does not reside in the same directory as the php files you setup your form will fail and probably render whatever your server used as a default.
<form action='expresscheckout.php' METHOD='POST'>
In this case it expects expresscheckout.php to reside in the same folder. You may need to adjust this, such as /expresscheckout.php or similar.

Accepting a Paypal payment through a custom-built website

I have been making a hotel booking software that calculates, for given dates and specifications, a price for staying at a hotel. I'm looking to use Paypal for accepting the payment, but having browsed their website, can't find a solution that seems to be compatible with this.
Since the price is dynamic, it's not like a normal one-price product which Paypal seems to handle best. I need a method where I can send the cost to Paypal, have Paypal charge the customer, then have Paypal send a confirmation back to the website that the payment has processed correctly at which point the booking is complete.
I presume Paypal is capable of handling a dynamically priced item like this. Could anyone point me in the direction of where I should be looking?
I just completed this process in my current website: bpremium.com, basically I built a webservice api for the payment process where it can send commands over javascript until it gets to the last stage, which is where you build the form you send to paypal.
in order to record the payment, you setup another webservice for the notify url and this will catch all the $_POST data and process it into your database.
<form id="form-payment-paypal" action="https://www.paypal.com/cgi-bin/webscr">
<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="bn" value="PP-BuyNowBF" />
<input type="hidden" name="charset" value="utf-8" />
<input type="hidden" name="business" value="YOUR_ACCOUNT_EMAIL_ADDRESS" />
<input type="hidden" name="item_name" value="THE PRODUCT NAME" />
<input type="hidden" name="item_number" value="YOUR_RECOGNISABLE_SALE_ID?>" />
<input type="hidden" name="currency_code" value="EUR" />
<input type="hidden" name="lc" value="THE LANGUAGE CODE: es_ES, en_GB, etc" />
<input type="hidden" name="amount" value="<?=$amount+($amount*0.04)?>" />
<input type="hidden" name="return" value="/payment/complete/" />
<input type="hidden" name="notify_url" value="/webservice/payment/notify/paypal/" />
<p class="ac span300">
<input type="submit" class="form-style-bt" value="PAY" />
</p>
</form>
that is basically what we use, you can see we put the $amount + $amount*0.04 because you needed to add a 4% surcharge in spain, where I am. perhaps thats different in your code.
I think the rest of it is pretty self explanatory.
on the /webservice/ url, you need to record everything into your database, it sends you the information whether it succeeded or failed, but it's not a call to your website, you won't see this page, it's a "back channel" call to your website, so it's not your landing page, it's simple the url paypal sends all the raw data to, you're supposed to record it, process it and perhaps send out emails, etc.
then if the user returns to your website, you land on the /payment/complete page, so this page could show the result, whether everything is ok, or something failed.
hope it helps.
Paypal's Direct Integration can handle pricing like this. I'd imagine some of their less involved solutions will too, but I know that DI does.
Edit:
ExpressCheckout appears to also:
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_SetExpressCheckout

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.