Form string Post redirection in MVC - asp.net-mvc

I was trying to integrate Payumoney Payment gateway in one of a E Commerce site developed in MVC4. To redirect to the gateway for payment I have to submit :
<form id="PostForm" name="PostForm" action="https://test.payu.in/_payment" method="POST">
<input type="hidden" name="lastname" value="">
<input type="hidden" name="address2" value="">
<input type="hidden" name="udf5" value="">
<input type="hidden" name="curl" value="">
<input type="hidden" language='javascript'>
var vPostForm = document.PostForm;
vPostForm.submit();
</script>
In ASP.Net, this is the code
Page.Controls.Add(new LiteralControl(strForm));
How to achieve this in MVC?
Thanks,
Prasant

Page.Controls.Add(new LiteralControl(strForm));
Instead of above line of code just write :
Response.Write(strForm);

Create it as partial. Put this markup in its view. And in your main view code use #Html.RenderPartial("Payment")

Related

How to convert HTML form to C# for PayPal subscription

I have the following HTML which works well for subscription payments in my test environment.
<form action="paypalWebAddress" method="post" target="_top">
<input type="hidden" name="cmd" value="_xclick-subscriptions"/>
<input type="hidden" name="business" value="myPaypalAccountId"/>
<input type="hidden" name="paymentaction" value="sale"/>
<input type="hidden" name="item_name" value="Subscription For abc123"/>
<input type="hidden" name="currency_code" value="GBP"/>
<input type="hidden" name="no_note" value="1" />
<input type="hidden" name="a3" value="50"/>
<input type="hidden" name="p3" value="6"/>
<input type="hidden" name="t3" value="M"/>
<input type="hidden" name="src" value="1" />
<input type="hidden" name="srt" value="0" /><!--needs to be never ending-->
<input type="hidden" name="return" value="www."/>
<input type="hidden" name="notify_url" value="www."/>
<input type="hidden" name="cancel_url" value="www."/>
<input type="hidden" name="custom" value="abc123"/>
<input TYPE="hidden" name="charset" value="utf-8">
<input type="hidden" name="bn" value="Me_Subscribe_WPS_UK" />
<input type="submit" name="submit" value="Make Payment"/>
</form>
I'm about to go live and concerned that some one could easily manipulate the DOM and I'm suddenly sending bogus payments. I feel it would be safer to somehow post these values from the code behind so the user can't tamper with the values but, the user will still need to use the PayPal interface in their browser to log in and subscribe.
PayPal-NET-SDK has a quick start and shows how to get going. I have completed this (copied and pasted and ran in debug mode) and it executes fine. However, this doesn't cover subscriptions, probably for the reason explained above (and would probably prevent them accessing the PayPal gui in their browser).
I get the option in the PayPal dashboard area to create a button and reference by button, but, this won't work for me as I need to be able to set the custom field per subscription as a user can subscribe to 1 or more services and each service is unique to that user.
I can't understand how to achieve this
If I understand this right, every subscription is unique per customer in your case and that won't work with the static buttons, so the API seems the only way to go.
The PayPal API does cover subscriptions, they're called Billing Plans. Because each subscription is different, you could create a new Billing Plan for each unique service (or combination of services). This can be done without any intermediate SDK using the HttpClient directly to their API.
Alternatively, the PayPal-NET-SDK you mentioned also seems to cover Billing plans. Their Sample application has quite a lot of examples on how to create, enumerate and issue Billing Plans. Make sure you check out the billing_agreement_tokens collection on the Payment class. You might add multiple "service" tokens there.
No matter how close you are to releasing, a lot of testing still seems to be in order here.
You can try using HttpClient, something like this will help
HttpContent content = new FormUrlEncodedContent(
new List<KeyValuePair<string, string>> {
new KeyValuePair<string, string>("key1",
"value1"),
new KeyValuePair<string,string>("key2","value2")
});
content.Headers.ContentType = new
MediaTypeHeaderValue("application/x-www-form-
urlencoded");
content.Headers.ContentType.CharSet = "UTF-8";
HttpResponseMessage resposne = await
client.PostAsync(new Uri("paypalWebAddress"),
content);
You should not hardcode the values in forms, instead you should create an API in the backend which will return the correspoding values.Then you can dynamically create the form based on the response of the API.
Make sure you create this form after you have received the response from the API.You can have a check like if response is null show some spinner.
<form action="paypalWebAddress" method="post" target="_top">
<input type="hidden" name="cmd" value="{response.cmd}"/>
<input type="hidden" name="business" value={response.business}"/>
<input type="hidden" name="paymentaction" value={response.action}/>
<input type="hidden" name="item_name" value="{response.item}"/>
<input type="submit" name="submit" value="Make Payment"/>
</form>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="business.test.com">
<input type="hidden" name="item_name" value="Memory Stick">
<input type="hidden" name="item_number" value="MEM32507725">
<input type="hidden" name="amount" value="3">
<input type="hidden" name="tax" value="1">
<input type="hidden" name="quantity" value="1">
<input type="hidden" name="currency_code" value="USD">
<!-- Enable override of buyers's address stored with PayPal . -->
<input type="hidden" name="address_override" value="1">
<!-- Set variables that override the address stored with PayPal. -->
<input type="hidden" name="first_name" value="John">
<input type="hidden" name="last_name" value="Doe">
<input type="hidden" name="address1" value="345 Lark Ave">
<input type="hidden" name="city" value="San Jose">
<input type="hidden" name="state" value="CA">
<input type="hidden" name="zip" value="95121">
<input type="hidden" name="country" value="US">
<input type="image" name="submit"
src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif"
alt="PayPal - The safer, easier way to pay online">
</form>
On Click on buy now :
<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="herschelgomez#xyzzyu.com">
<!-- Specify a Buy Now button. -->
<input type="hidden" name="cmd" value="_xclick">
<!-- Specify details about the item that buyers will purchase. -->
<input type="hidden" name="item_name" value="Premium Umbrella">
<input type="hidden" name="amount" value="50.00">
<input type="hidden" name="currency_code" value="USD">
<!-- Prompt buyers to enter the quantities they want. -->
<input type="hidden" name="undefined_quantity" value="1">
<!-- Display the payment button. -->
<input type="image" name="submit" border="0"
src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif"
alt="Buy Now">
<img alt="" border="0" width="1" height="1"
src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" >
</form>

HTML.BeginForm not Routing to Controller Method

I'm writing an MVC website in C# with razor syntax.
I have some code here:
#using (Html.BeginForm("DoSignUp", "SignUpController", FormMethod.Post))
{
<input type="text" width="3000" value="" name="Name" />
<input type="submit" value="Register" /
}
So this form should post to the SignUpController on the DoSignUp method. Instead of doing that it just posts back to the page I'm currently on which is called SignUp. I suspected there might be something wrong with my routing but when I look at the html that is being generated through the browser developer tools i see this:
<form action="" method="post">
<input type="text" width="3000" value="" name="selectedURL">
<input type="submit" value="Register">
</form>
Edit: Well I wrote this out and then looked at my code again. The problem which I keep bloody doing is that SignUpController should just be SignUp.
Remove the 'Controller' from your controller name (SignUp, not SignUpController). It's assumed to be a controller by convention
#using (Html.BeginForm("DoSignUp", "SignUp", FormMethod.Post))
{
<input type="text" width="3000" value="" name="Name" />
<input type="submit" value="Register" /
}

JamboPay and Rails Integration

I have JamboPay api that i want to integrate with my rails application. It looks something like this;
<form method="post" action="https://www.jambopay.com/JPExpress.aspx" target="_blank">
<input type="hidden" name="jp_item_type" value="cart"/>
<input type="hidden" name="jp_item_name" value="test shop"/>
<input type="hidden" name="order_id" value="455879"/>
<input type="hidden" name="jp_business" value="business#yourdomain.com"/>
<input type="hidden" name="jp_amount_1" value="51"/>
<input type="hidden" name="jp_amount_2" value="0"/>
<input type="hidden" name="jp_amount_5" value="0"/>
<input type="hidden" name="jp_payee" value="email#yourcustomer.com"/>
<input type="hidden" name="jp_shipping" value="company name"/>
<input type="hidden" name="jp_rurl" value="http://www.yourwebsite.com/testpost/Result.aspx?ii=0"/>
<input type="hidden" name="jp_furl" value="http://www.yourwebsite.com/testpost/Result.aspx?ii=1"/>
<input type="hidden" name="jp_curl" value="http://www.yourwebsite.com/testpost/Result.aspx?ii=2"/>
<input type="image" src="https://www.jambopay.com/jambohelp/jambo/rsc/paymentsbyJamboPay.jpg"/>
</form>
I want to be able to send this information from my transactions controller in the create method.
Any ideas how i can pass this form from my controllers because i keep the same form for all payment methods in the views.
Thank you in advance.
You can send this post request using Net::HTTP library all you have to do is to send this information to your controller action and then send post request from action.

URL POST parameters

I want to make a program in C# which will go/login and do stuff on a website. I'm using Fiddler to see which URL should I use.
So, in Fiddler I write:
https://landfill.bugzilla.org/bugzilla-tip/post_bug.cgi?Bugzilla_login=mymail#hotmail.com&Bugzilla_password=mypassword&product=WorldControl&version=1.0&component=WeatherControl&rep_platform=All&op_sys=All&priority=P2&bug_severity=normal&target_milestone=World 202.0&bug_status=CONFIRMED&assigned_to=mymail#hotmail.com&short_desc=bla
And I send it with POST. I get a message which says: "Are you sure you want to commit these changes anyway? This may result in unexpected and undesired results."
Then, there is a button which says 'Confirm changes'. Its code in the result html page is:
<form name="check" id="check" method="post" action="post_bug.cgi">
<input type="hidden" name="product"
value="WorldControl">
<input type="hidden" name="version"
value="1.0">
<input type="hidden" name="component"
value="WeatherControl">
<input type="hidden" name="rep_platform"
value="All">
<input type="hidden" name="op_sys"
value="All">
<input type="hidden" name="priority"
value="P2">
<input type="hidden" name="bug_severity"
value="normal">
<input type="hidden" name="target_milestone"
value="World 2.0">
<input type="hidden" name="bug_status"
value="CONFIRMED">
<input type="hidden" name="assigned_to"
value="mymail#hotmail.com">
<input type="hidden" name="short_desc"
value="bla">
<input type="hidden" name="token"
value="aGipS2Hfim">
<input type="submit" id="confirm" value="Confirm Changes">
What should I write as URL in Fiddler or in browser to click this Confirm button?
You should submit POST data to URL https://landfill.bugzilla.org/bugzilla-tip/post_bug.cgi .
POST data should be as follows :
version=1.2&Component=WeatherControl& .... etc
Don't forget to encode POST data and set content type to "application/x-www-form-urlencoded"
UPDATE: When you receive first answer with confirm button, parse it as DOM and submit it again to same URL.This should behave same as you click on confirm button
The problem was that the parameters shouldn't be in the URL. This isn't GET method.

Google Checkout in ASP.Net MVC

I have a fairly simple ASP.Net site that uses google checkout (I have an imagebutton with the PostBackUrl set to the Google address passing values of hidden fields) which works fine.
I've been moving this app to MVC and I'm not sure how to handle this. I thought about using jQuery form but I don't believe this would work in this situation because there are times when they're redirected to the google pages. Has anyone used google checkout in an asp.net MVC app?
You can do the same thing as you were doing before, just you end up doing it manually.
Sounds like you're using just the basic version, yes?
You create an HTML form that has the Action set to the Google checkout process, add in the proper Hidden fields (the model your controller passes down would be populated w/ the correct values for those) and then you have a submit button (or image if you prefer).
So, an example off Google's Basic HTML page, modified for some MVC-ish-ness would be something like this:
<form method="POST"
action="https://checkout.google.com/api/checkout/v2/checkoutForm/Merchant/<%= Model.MerchantId %>"
accept-charset="utf-8">
<input type="hidden" name="item_name_1" value="<%= Model.Item.Name %>"/>
<input type="hidden" name="item_description_1" value="<%= Model.Item.Description %>>
<input type="hidden" name="item_quantity_1" value="<%= Model.Item.Quantity %>"/>
<input type="hidden" name="item_price_1" value="<%= Model.Item.Price %>"/>
<input type="hidden" name="item_currency_1" value="<%= Model.Item.Currency %>"/>
<input type="hidden" name="ship_method_name_1" value="<%= Model.Shipping.Price %>"/>
<input type="hidden" name="ship_method_price_1" value="<%= Model.Shipping.Price %>"/>
<input type="hidden" name="ship_method_currency_1" value="<%= Model.Shipping.Currency %>"/>
<input type="hidden" name="tax_rate" value="<%= Model.Tax.Rate %>"/>
<input type="hidden" name="tax_us_state" value="<%= Model.Tax.State %>"/>
<input type="hidden" name="_charset_"/>
<input type="image" name="Google Checkout" alt="Fast checkout through Google"
src="http://checkout.google.com/buttons/checkout.gif?merchant_id=<%= Model.MerchantId %>&w=180&h=46&style=white&variant=text&loc=en_US"
height="46" width="180"/>
</form>
Obviously, you could make all that even more MVC-ish by using the form helper Html.Hidden and so on, but that shows the really basic version of what you need to do.

Resources