Reading parameters like signup[product][handle] in ASP.NET - c#

I need to read parameters from Context.Request that is written in a format like:
url?event=open&signup[customer][first_name]=John&signup[customer][last_name]=Doe&signup[payment_profile][card_number]=xxxxxxxx
Is there an easy way to parse this into a c# object? Would it be recommended to parse this in to a NameValueCollection, or is it to complex?
I am not familiar with this way of posting data, I don't even know what it is called when you do it like this, anyone care to fill me in? Thanks!
In case you are interested, this is the way stuff get posted:
<form method="post" action="https://....">
<input type="hidden" name="signup[product][handle]" value="basic" />
<input type="text" name="signup[customer][first_name]" />
<input type="text" name="signup[customer][last_name]" />
<input type="text" name="signup[customer][email]" />
<input type="text" name="signup[payment_profile][first_name]" />
<input type="text" name="signup[payment_profile][last_name]" />
<input type="text" name="signup[payment_profile][card_number]" />
<input type="text" name="signup[payment_profile][expiration_month]" />
<input type="text" name="signup[payment_profile][expiration_year]" />
<input type="submit" value="Sign Up" />
</form>

You can parse the query string into a NameValueCollection this way:
var nvc = new NameValueCollection();
nvc.Add(HttpUtility.ParseQueryString(Request.Params));

Related

Payfort Integration with Asp.Net MVC from server side

Currently, We are assigning the values in the below form and post the data to payfort. Which works fine!!
<form method="post" action="https://sbcheckout.payfort.com/FortAPI/paymentPage" id=form1 name=form1>
<input type="hidden" name="signature" />
<input type="hidden" name="command" />
<input type="hidden" name="merchant_reference" />
<input type="hidden" name="amount" />
<input type="hidden" name="access_code" />
<input type="hidden" name="merchant_identifier" />
<input type="hidden" name="currency" />
<input type="hidden" name="language" />
<input type="hidden" name="customer_email" />
<input type="hidden" name="payment_option" />
<input type="hidden" name="order_description" />
<input type="hidden" name="return_url" />
But when we post the data throw above method it shows the credential information to others
Is there any way that we can post the data to payfort from our controller and redirect to posted URL ?
You can use: https://github.com/payfort/payfort-dotnet-sdk/
this is official dotnet SDK from payfort
Yes you can post data to payfort using .Net Client library https://github.com/payfort/start.net
steps to call payfort.
1) Generate card Token
pass open key and card detail.
2) create charge using card token
3) capture charge amount

Directing from registration form to online payment website

I am trying to link a registration form to an online payment website and I was given code from the payment website similar to the one below in order to link the two pages together. I don't see how I would implement this unless it's attributed to an asp:Button like below.
How would I make it so on the button click it would run through this form and this information would be sent? All this information is necessary and if it isn't sent then I just get an error page from the payment server.
<asp:Button ID="submitButton" runat="server" Text="Submit" OnClick="submitButton_Click" />
<form id="input_form" action="https://secure.checkout" method="post">
<input name="LMID" type="hidden" value="000935" />
<input name="unique_id" type="hidden" value="4567"/>
<input name="sTotal" type="hidden" value="150.00"/>
<input name="webTitle" type="hidden" value="2013 Conference" />
<input name="Trans_Desc" type="hidden" value="Conference Registration" />
<input name="contact_info" type="hidden" value="Contact web admin" />
</form>
Why not just do this?
<form id="input_form" action="https://secure.checkout" method="post">
<input name="LMID" type="hidden" value="000935" />
<input name="unique_id" type="hidden" value="4567"/>
<input name="sTotal" type="hidden" value="150.00"/>
<input name="webTitle" type="hidden" value="2013 Conference" />
<input name="Trans_Desc" type="hidden" value="Conference Registration" />
<input name="contact_info" type="hidden" value="Contact web admin" />
<input type="submit" value="submit"/>
</form>

How to send data from one page to another page with querystring and input form?

I am working in C#(asp.net). I have two pages 'abc.aspx' and 'xyz.aspx'. I want to send data from 'abc.aspx' to 'xyz.aspx'. I am using this code.
In 'abc.aspx'
<form action='xyz.aspx?site=google&code=123' method='get'>
<input type='text' name='name1' />
<input type='submit' value='submit' />
</form>
Now, I want to access all three values (site,code and name1). But, in 'xyz.aspx', I got only one value i.e name1. How to get all three values.
You need to put the values into hidden <input /> elements and hard-code the values if you want to have them end up in the query string. You're correct in setting the method='get':
<form action='xyz.aspx' method='get'>
<input type='hidden' name='site' value='google' />
<input type='hidden' name='code' value='123' />
<input type='text' name='name1' />
<input type='submit' value='submit' />
</form>
I think this one is the best.
In abc.aspx
<form action="xyz.aspx?site=google" method="post">
<input type="text" name="name1" />
<input type="submit" value="Submit" />
</form>
In xyz.aspx, access the data like this..
string site = Request.QueryString["site"];
string name = Request.Form["name1"];
//Remaining code...

ASP.NET Photo API (Shutterfly, etc . .)

I have a website with all my photos, I would like people to be able to click on my pictures and order prints, etc through a third party service (Shutterfly, etc). Does anyone have any best practices or code examples of doing this in C#, ASP.NET?
I have no idea if this information is still up to date, but here is a description of the Shutterfly API. The API seems to consist in a simple HTTP form post with embedded name-value pairs.
Example:
<form action="http://www.shutterfly.com/c4p/UpdateCart.jsp" method="post">
<input type="hidden" name="addim" value="1">
<input type="hidden" name="protocol" value="SFP,100">
<input type="hidden" name="pid" value="C4P">
<input type="hidden" name="puid" value="AFFL">
<input type="hidden" name="imnum" value="1">
<input type="hidden" name="imraw-1" value="http://images.partner.com/foo/12345.jpg">
<input type="hidden" name="imrawheight-1" value="1800">
<input type="hidden" name="imrawwidth-1" value="1200">
<input type="hidden" name="imthumb-1" value="http://images.partner.com/foo/12345_thumb.jpg">
<input type="hidden" name="imthumbheight-1" value="150">
<input type="hidden" name="imthumbwidth-1" value="100">
<input type="hidden" name="returl" value="http://www.partner.com/alice">
<input type="submit" value="Submit">
</form>
It should not be a difficult task to write some C# wrapper for it.

Complex model binding to a list

I have been trying out the NameValueDeserializer from MVCContrib, which will take a IList as a parameter to a controller and bind a form and its elements to it, but I was just wondering if MVC Beta had any way of doing this??
I know you can bind a strongly typed Object but I want to bind a List of these Objects for some bulk editing situations.
eg.
public void Save(IList<Item> items)
{
foreach (Item i in items)
{
//Save item
}
}
Is this possible in MVC Beta??
Yes it is, I wrote a detailed blog post about it here. It's really easy for simple types. For complex types, you'd need to do something like:
<input type="hidden" name="products.Index" value="0" />
<input type="text" name="products[0].Name" value="Beer" />
<input type="text" name="products[0].Price" value="7.32" />
<input type="hidden" name="products.Index" value="1" />
<input type="text" name="products[1].Name" value="Chips" />
<input type="text" name="products[1].Price" value="2.23" />
<input type="hidden" name="products.Index" value="2" />
<input type="text" name="products[2].Name" value="Salsa" />
<input type="text" name="products[2].Price" value="1.23" />

Categories