Paypal Return URL is not triggering properly - c#

Our website has following one time payment buttons.
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="custom" value="#Model.UserId.ToString()">
<input type="hidden" name="notify_url" value="http://www.testweb.com/paypal/IpnHandler">
<input type="hidden" name="return" value="http://www.testweb.com/paypal/Onetimeyearlysuccess">
<input type="hidden" name="cancel_return" value="http://www.testweb.com/paypal/cancel">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="8xxxxxxC">
<input type="image" src="#Url.Content("~/images/OneTime55year.png")" border="0" name="submit" style="width: 130px !important; height: 47px !important;" alt="PayPal - The safer, easier way to pay online!" >
</form>
After done the paypal payment, we could see we are getting 404 error.
The issue is that we are getting wrong URL.
https://www.testweb.com/PaypalOnetimeyearlysuccess?amt=55.00&cc=USD&cm=22028&item_name=oneTimeAnnual55&st=Completed&tx=59M0424544743135Y
We don’t know why the slash missing after paypal.
The correct URL should be
https://www.testweb.com/Paypal/Onetimeyearlysuccess?amt=55.00&cc=USD&cm=22028&item_name=oneTimeAnnual55&st=Completed&tx=59M0424544743135Y
There needs to be slash symbol after paypal in the address URL.
You can see the correct URL from the return URL of the paypal button also.
Why it is redirecting to wrong address?
Also for testing purpose,we changed the return URL of the paypal button. We simply modified to “http://www.testweb.com/paypal/Onetimeyearlysuccesstest.”
But we could see after changed the return URL , paypal is not redirecting to modified URL.
Actually we are confused ,we need to know where the return URL is creating.

PayPal only recognize the value of 'return' variable. The key point is located at this URL (http://www.testweb.com/paypal/Onetimeyearlysuccess). You are advised to create a fixed single page without redirect function like .html, .php, .aspx, etc., to see the result.

Related

How to Redirect to new URL during form submission in ASP.NET MVC

When I am trying to submit a form with action url, I am not able to redirect to that particular url. The URL contains 6 query string parameters (JWT token etc). The URL char length is around 9000.
Current URL: http://localhost:2712/Record/Value
Trying to redirect to: https://
I have tried to redirect from controller but I am getting the following error
Refused to load the script 'http://localhost:61962/' because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-inline' 'unsafe-eval'. Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.
Passing the url with Query string parameters from Controller to a partial view.
#model LaunchModel
<div><form id="idForm" action="#Model.Url" method="post">
<input type="submit" value="Submit" />
</form>
<script>
document.getElementById("idForm").submit();
</script></div>
Tried with hidden parmeter as well
#model LaunchModel <div><form id="idForm" action="#Model.Url" method="post"><input type="hidden" name="token" value="#Model.token" />
<input type="hidden" name="val" value="#Model.val" />
.
.
<input type="submit" value="Submit" class="d-none" />
</form>
<script>
document.getElementById("lti1p3RequestForm").submit();
</script></div>
Please help.

C# Building a website Form response using WebRequest

I have a device with a built-in WebGUI that is accessible through it's IP address. I am trying to be able to programmatically manipulate inputs to the device with a console app. The device's login page (https://192.168.x.x/login.html) contains the following form:
<form class="settingNameTxt" method="post" action="back.shtml">
<table>
<tr>
<td>Password:</td>
<td><input type="password" size="8" maxlength="8" name="Password"></td>
</tr>
</table>
<br/>
<input type="submit" value="Submit"/>
<input type="reset"/>
/form>
I want to build a WebRequest that is the equivalent of a user viewing the page in a browser, filling in the password field, and clicking the Submit button. I've searched around here and found a few things that seem to give me the idea that it can be done, but I'm struggling to figure it out. Any ideas?

Antiforgerytoken MVC C# search form

I have a search box on my site.
The controller looks like this:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult SearchResults(SearchModel model)
{
View:
<div class="siteSearch clearfix" role="search">
<form id="HeaderSearchForm">
#Html.AntiForgeryToken()
<label for="tbSiteSearch">Search:</label>
<input type="text" id="tbSiteSearch" name="tbSiteSearch" class="text" />
<button type="submit" class="btn submit">
<i class="icon-search"></i>
</button>
</form>
</div>
So when I do a search, I can see the hidden label with the Anti Forgery Token present. This all works as expected because if I take a blank html page, copy the form code and leave the '__RequestVerificationToken' blank, I get told that the token hasn't been set and the search doesn't run. Which is what I would expect.
The issue I have is if I submit a search, copy the token from my site and place it in to my blank html page e.g.
<html>
<body>
<script>history.pushState('', '', '/')</script>
<form action="https://www.adomainname.co.uk/Search/SearchResults/" method="POST">
<input type="hidden" name="SearchTerm" value="testing" />
<input type="hidden" name="__RequestVerificationToken" value="theverificationtokengoeshere" />
<input type="submit" value="Submit request" />
</form>
</body>
</html>
The request is submitted - even if I am running the above code on localhost. I would have expected the form to not submit as it was coming from a different domain. Am I misunderstanding how this should work?
If I refresh the page and resubmit Im obviously allocated a new AFT and so the submit fails again but this doesn't feel right.
Ideally I would prefer the form action to only run on the domain it's on and not be able to execute the action from another site. I thought using AntiForgeryToken prevent Cross-Site Request Forgery.
If any of this is unclear, please let me know and I'll explain more.

Get input value on server side

I'm having some trouble and not sure what's going on.
I have a form with input value and want to be able to get that input value and send it back to my controller (server side).
My html code
<form action="/Home/Search" method="get">
<button class="search-btn-widget"></button>
<input class="search-field" id="sub" type="text" onblur="if(this.value=='')this.value='Search';" onfocus="if(this.value=='Search')this.value='';" value="Search" />
</form>
Then in my controller I have
string sub = Request["sub"];
However it ends up being null and not sure what's going on. Any ideas?
Just to make it work: add the name attribute
<input class="search-field" id="sub" name="sub" ...
but check this.
You need to add the name attribute to the input tag.
If you pull up the developer console and take a look at the HTTP GET request that is being sent, you will see that no query string is being associated with the request. This will let you know that the issue on the HTML side and not the ASP.Net MVC side.
Update input tag:
<input class="search-field" id="sub" name="sub" type="text" onblur="if(this.value=='')this.value='Search';" onfocus="if(this.value=='Search')this.value='';" value="Search" />
Update Controller Action to:
public ActionResult Search(string sub)
1) If you wanna see your input into the Request you must send your Form as POST:
<form action="/Home/Search" method="POST">
2) Make sure that input has a name:
<input class="search-field" id="sub" name="name"
type="text"
onblur="if(this.value=='')this.value='Search';"
onfocus="if(this.value=='Search')this.value='';"
value="Search" />
Then you will be able so see It in the request
You should add the name attribute to the input element.

Paypal Express Checkout & ASP.NET

I am working on a ASP.NET + Paypal Express project,
Website only have 1 $10 product but customer can buy it in quantities (i.e 1 or 4 or 20 etc )
Its like a paypal cart but only with 1 product with quantities.
I have searched a lot but unable to find some suitable one.
Also I want to redirect my customer to a form after paying money on paypal website.
Can you just tell me the simplest method ?
Also I have few more question :-
using minicart Paypal is suitable for this?
Do I need to configure Paypal Express account & what to configure ?
Thanks a lot :)
=================================================================
Update : Use Paypal mini cart if you need simple integration
Add cart script.js before the body tag ( https://minicart.paypal-labs.com/ )
After that All you need to add this code in your html
<div class="demo container" align="center" >
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<fieldset>
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="add" value="1">
<input type="hidden" name="business" value="#gmail.com">
<input type="hidden" name="item_name" value="Buy Our Services">
<input type="hidden" name="amount" value="6.00">
<%--<input type="hidden" name="discount_amount" value="1.00">--%>
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="return" value="https://minicart.paypal-labs.com/?success">
<input type="hidden" name="cancel_return" value="https://minicart.paypal-labs.com/?cancel">
<strong>Service</strong>
<ul>
<li>Price: $6.00</li>
</ul>
<input type="submit" name="submit" value="Add to cart" class="button">
</fieldset>
</form>
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" class="last">
<fieldset>
<input type="hidden" name="business" value="#gmail.com">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="display" value="1">
<input type="submit" name="submit" value="View your cart" class="button">
</fieldset>
</form>
</div>
Change parameter accordingly & remove link to paypal instead of sandbox
You Paypal cart is ready to go.
If you want a more flexible solution then you should check this URL http://www.codeproject.com/KB/aspnet/paypal_c_aspnet.aspx
Thanks
Panky are you sure is it the right way ?
Customer come on site
Choose product/s and quantity/ies
Before do that you should store in session/database/cookies info that you need and pass to paypal only the stuff that you need with an id or other stuff which could be used to recognized customer too.
then move to pay to paypal.
Customer pay on paypal and paypal send back info about transaction
With these details you may re-create all the info that you need ans can use to complete first step back office tasks or even you may only show some message to cusotmer.
then you will wait ipn's(Instant Payment Notification) callback in order to make all tasks needed in backoffice automation.
This is the right way to do it.
Also you may able to make a good exception handling in order to prevent issue within it.

Categories