Authorize.Net SIM Form submission in Kentico - c#

Kentico is a C# / Asp.NET Content Management System that we use and I'm trying to implement authorize.net SIM integration (redirecting the user to the authorize.net servers to make purchase through a form post). Kentico uses master pages so it's proving to be a beast. First issue was getting the form to even post to the authorize.net Servers. I was able to do this using the following.
<script type="text/javascript">
theForm.action = "https://test.authorize.net/gateway/transact.dll";
</script>
Easy Enough (theForm == the master page form), now the issue lies in the fact that I originally was using code behind to populate the hidden input fields and it changes all of the names of these input fields. This makes it impossible for authorize.net to know what you are doing.
Has anyone done any integration like this before? And if so, what is the most appropriate way to solving this problem?
I have a few ideas but they all involve what I consider extremely dirty methods for getting it to work.

you will need to follow these steps to take the names of your input fields under your control:
1) Use your code to set the payment gateway URL
2) Place ASP.NET Literal control on ASPX page, something like:
<asp:Literal runat="server" ID="myFields" />
3) Go to code behind and initialize the literal with HTML code of all your input fields. For each input field set its custom identifier. e.g:
myFields.Text += "<input type="text" id="carnumber" name="cardnumber" />"; ....
After the button is clicked, user is redirected to the payment gateway URL where the POSTed data from your input fields are available under the required identifiers. I hope you will find it helpful.

Related

Is there a generally accepted way to pass data from one ASP.Net form to another after validation?

I have an ASP.Net form (Page1) where the user enters some data and then clicks the submit button.
As part of Page1, I have some Validators, including a CustomValidator which needs to do its validation back on the server.
When the user clicks the submit button a post is done to Page1 and the validation routine is run on the server and as long as I check Page.IsValid in the button click routine the form knows whether things have passed or not.
When the validation doesn't pass everything properly goes back to Form1 and the error message is displayed.
When the form does pass validation, I want to pass the data that the user entered to a second form (Page2) so that Page2 can be rendered correctly based on the data the user entered on Page1.
Is there a generally accepted way, or best way, to pass the data to Page2? Here are some ways I know about:
Call Page2 with a query string: This won't work as I need the data to not be visible to the user in certain cases.
Use the PostBackUrl on the submit button to go to Page2: As far as I know, this won't work correctly because then the server side validation routines for Page1 won't be run.
Use Session Variables: I don't know of a particular reason why this would be bad.
Use Server.Transfer: I don't really have any experience with this.
I would think that this would be a pretty standard thing to do but I'm having a hard time finding any information on the correct way to do it.
If you don't have a form of secondary storage for this data, using either Session storage or Server.Transfer would work.
You might find Server.Transfer is a little neater as, this way, you'll retain your POST values across the transfer. This will potentially save you a lot of cumbersome code playing around with session state, which, depending on how complex your forms are, could open the way to all kinds of unusual behaviour that you'd have to predict and plan to deal with in advance such as what happens when a user clicks the "back" button or - if you're posting across multiple pages - what happens when a session expires (plus Servy's examples of having multiple tabs open on the same page(s), all sharing the same session). Working with session state can be messy.
Perform your validation on PostBack then, if Page.IsValid, do:
Server.Transfer("/FormPage2.aspx");
Server.Transfer preserves Request.QueryString and Request.Form, so you can pick up your POST values on FormPage2 and do whatever you need with them here - whether it be using them for conditional logic or rendering them out again as hidden fields to join them up with the values from the second page of the form (bear in mind that if you're doing this you'll have to revalidate the hidden inputs at this stage).
http://msdn.microsoft.com/en-us/library/y4k58xk7.aspx
I have used session state for handling complex forms in the past and found myself wishing I'd used Server.Transfer, which I plan to use for all similar endeavours in the future, unless I have a very good reason not to.
You might also consider using a multiview, but in my experience these can be very messy.
Hope this helps.
I think that the easiest solution would be to specify a PreviousPageType directive. It specifies a type that the page should expect to receive and you would do a normal POST to that page.
On the second page of your application, use the following directive:
<%# PreviousPageType VirtualPath="~/FirstPage.aspx" %>
You will be able to access the properties exposed and check for validity by using something like this:
if (PreviousPage != null && PreviousPage.IsValid)
Using the Session object is a standard way to pass information across forms.
#Servy gives a good explaination (in the comments below) on how Server.Transfer can help you in this case.
The other options you stated all have problems, just like you mentioned...
If you want to use Session:
In the postback of Page1 you can set the values:
Session["myVar"] = <Data you want to pass to page2>
In page2 in the OnLoad:
if (Session["myVar"] != null)
{
myVar = Session["MyVar"]
}
You can achieve this with Server.Transfer by adding a property to your page1. In your second page in page_load for example:
Page1 prev = Page.PreviousPage as Page1;
if (prev != null)
{
// access your property here and set up the page
}
Server.Transfer can safely receive a query string without fear of the user seeing it.
Instead of Session use Context.Items.
Context.Items["validationProblems"] = "...";
Server.Transfer("FixProblems.aspx");
My other comment is that in my experience it's more "standard" to keep the validation UI contained in the same form that's collecting the information. This enables "real time" feedback. In practice I think it's better to give a user information that their doing something wrong as early as possible.
Note, that's just in my experience though.. it's a big world.
It may be more that you presently require, but one alternative is to save the data in a database:
http://msdn.microsoft.com/en-us/library/6tc47t75%28v=VS.100%29.aspx
http://www.asp.net/web-forms/videos/how-do-i/how-do-i-set-up-the-sql-membership-provider

maintain viewstate for html elements?

I have a generic 'form page' user control that we use that allows editors to insert whatever kind of html form they want to inside of it, and it handles all of the form posts.
My question is, is there a way to store the vanilla non-asp form entries in the viewstate or otherwise save the entries on a form post, in the case that some server-side validation fails, so they can be restored when the page refreshes?
We currently already do upfront javascript validation that catches the majority of the input errors. We store all the form post data in a db before we do further processing, and some of the entries contain junk (spam we wish to ignore) or only partial info (i'm assuming those are cases where the user doesn't have javascript enabled). I'm trying to catch these last fringe cases so we do not process them.
If I am understanding this correctly,
1>User fills form
2>Clicks submit
3>Error detected on the server side
4>The Html posted back should contain the form i already filled with an error message on top.
Have you considered using JQuery Ajax?
The jquery ajax will post to a web method. The web method returns a JSON response. If the response is success redirect user to the next page, else show error on top of the page.
That way you don't need to maintain the state of the user input (since it is never lost).
If you dont know what the form fields are ahead of time then I would reccomend that you look into partial postbacks.
Or else post the forms via ajax.
you could store the text HTML in
<asp:HiddenField ID="hid1" runat="server" />
this will be passed in View State

PayPal with image button ASP.NET ( sandbox account) incorrectly formatted item amount

Easy one for the experts I hope. I am a student, please help!
I have an incorrectly formatted amount when I checkout in Paypal with my asp.net page, any tips?
Here is my code in c# asp:
<asp:ImageButton ID="ImageButton3" runat="server"
ImageUrl="~/Catalog/Images/Thumbs/buynow.jpg"
PostBackUrl='<%# "https://www.sandbox.paypal.com/cgi-bin/webscr?" +
"cmd=_xclick" +
"&business=seller_1346751061_biz#gmail.com" +
// seller email is also static
"&item_name=" + Eval("ModelName") +
// ValueX is dynamic name of product item
"&amount=" + Eval("UnitCost") +
// ValueY is dynamic cost of product item
"&currency_code=AUD" // this is also static
%>'
/>
What you try to do is simple NOT working.
The data item_name, amount etc, must be send using POST and not place them on the url using GET.
Also, by placing the PostBackUrl on this button you post all the page data to the paypal, and not the actually data that paypal needs.
The correct way is to make a totally custom made form like paypal ask on his examples and the manual, and this can not be done that way from a usually asp.net form.
One trick that you can make is to use a dynamic form maker, as on this example:
http://www.codeproject.com/Articles/37539/Redirect-and-POST-in-ASP-NET
and ether make dynamic post, ether place your buttons there and ask the user to click on it.
Also you can consider this articles with sample code:
http://www.codeproject.com/Articles/42894/Introduction-to-PayPal-for-C-ASP-NET-developers
http://www.codeproject.com/Articles/19184/Use-of-the-PayPal-payment-system-in-ASP-NET
http://www.codeproject.com/Questions/120427/Paypal-API-Integration-into-ASP-Net-Web-Site
And do not forget the paypal SDK for asp.net:
https://www.paypal.com/us/cgi-bin/webscr?cmd=p/pdn/sdk_asp_net_how-it-works-outside

Pop Up Window Data Variable Passing

I am creating a web application for my company that needs to deal with form processing and database manipulation. The application is implemented using .NET Framework 3.5 using C# and Visual Studio 2008 as the IDE and Microsoft SQL Server 2005 as the database.
Here is my problem:
I have a lot of forms
But my boss only want me to create a single page for the database
processing (easier to extend in the future)
I figured out the only way to solve this problem is by having only 1 .aspx file (that contains everything about the database) and having it invoked as a pop up window everytime a forms need to deal with the database.
Here is another problem of mine:
Due to stateless nature of HTTP, I am unable to process and pass
variable between 2 different windows.
I managed to create certain Javascript functions and have the
variable transferred on display, however it can only pass a variable
that is the primary key in the table. To process other columns in
the table is possible but as the consequence I have to write a very
long inline script in my .aspx page and after it is compiled people
can easily view how to access my company database easily. Hence, I
don't favor this (beside to deal with 1 form, I need to create a
long code already, imagine if i have more than 1000 forms!)
So there are two ways you guys can help me:
Suggest another way other than popping up a new window for my
problem, maybe even advise on how it's implemented.
If you think popping up is the solution, you mind to share some
snippets that can help me figure out the variable passing between
two different windows. I can use some advise especially from some
Javascript expert on this :).
Note: Solution must be workable in ASP.NET Framework 3.5 and tested using IE browser version: 8.
P.S: This is a short explanation about my application flow
Let's say I entered data about a product (it has few properties id, name, price, etc) into the database
Later on somehow I want to edit one or few properties of that product, so I have to launch a form which called "editor.aspx"
Instead of entering the product id (which is the primary key) into the form (and edit the data based on the entered product id) and risking to miscalculately edit the correct data, I provide a small button in the form (let's name it btSearch), that will launch a new popup window which contains the gridview of the database of all product (with selection enabled)
Now I just need to browse through the gridview, select a particular row, it will close the popup and I expect to see few data from that row appeared on my original page (in the textboxes/labels)
I hope my explanation above clears the air, thank you.
I recently wrote something like that: A database handler as aspx file. But i invoked it by using ajax / jquery.
When my aspx file is done, i write something to the response stream, some code, a json string, what ever.
Example:
$.post("yourdatabasehandler.aspx", { name: "John", lastname: "Smith" }, function(data) {
alert("Response from page: " + data);
});
In that example, name and lastname are values that are posted to your site. You can access them like that:
string name = Request.Params["name"]
// Do your database , validation and whatever logic here
Response.Write("Cool dude");
The above javascript will alert "Cool dude" after your databasehandler is done. Inside your javascript you can react to the response how ever you want - For example reload a page.
Hope that helps? Regards
"1. Due to stateless nature of HTTP, I am unable to process and pass
variable between 2 different windows."
You very wrong with this comment to start with, trying MSDN and ASP.Net "How to pass values between ASP.Net Web pages". Passing between Windows only requires a little bit more thought and possibly a little Javascript to refresh a parent windows or cause a postback on a shild window etc.
If you're using a popup window, you can always use QueryStrings to pass a value going to your popup.
window.open("popup_page.aspx?id=" + id + "&name=" + name)
to access it in popup_page.aspx
string sID = Request.QueryString("id");
string sName = Request.QueryString("name");
Update: if you're using IE the this might help you.
function ShowPopup(strMessage)
{
var returnValue= window.showModalDialog("popup_page.aspx");
}
popup_page.aspx
<asp:Button ID="btnReturnValue" runat="server" Text="Proceed" OnClientClick="window.returnValue='some message';window.close();" />
Note: Please note this only works in IE, so I suggest consider using the followings instead:
jQuery
AjaxControlToolkit ModalPopup
I personally suggest the use of jQuery. :)
Thank's for all answers, comments. rates, and feedback. Just now I found a very helpful link here. Basically the answer is based on that particular code. I just need to alter some part.
<script language="javascript">
function GetRowValue(val)
{
window.opener.document.getElementById("ctl00_ContentPlaceHolder1_TextBox2").value = val;
// make sure you change the TextBoxId as respective to your creation
window.close();
}
</script>
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1">
<Columns>
<!-- Reserve the code below, as after you configure data source you -->
<!-- will alter this code drastically therefore-->
<!--you have to make sure to paste this code -->
<!-- again inside this Gridview element once you configure your data source -->
<asp:TemplateField>
<AlternatingItemTemplate>
<asp:Button ID="btnSelect" runat="server" Text="Select" />
</AlternatingItemTemplate>
<ItemTemplate>
<asp:Button ID="btnSelect" runat="server" Text="Select" />
</ItemTemplate>
</asp:TemplateField>
<!-- This part must be reserved -->
</Columns>
Also remember to specify the connection string and the sql command in the datasource.
The rest just follow that tutorial and copy paste the code entirely.

Getting hidden control of parent from iFramed code-behind

In my parent page I have a hidden control:
<input type="hidden" id="CaseID" value="" runat="server" />
I need for my page in the iFrame to be able to get this value from C# code-behind. I have so far been unsuccessful.
In the child page's code-behind I have tried variations of this:
var theParent = this.Page.Parent;
But I always get null back.
Any assistance would be greatly appreciated.
From the server's perspective, there is no relationship at all between a page which launches an iframe, and the page which is contained within that iframe. They are two completely distinct and unrelated HTTP Requests. In your code-behind, they have nothing in common and there is no way to refer to one from the other.
Thus, you'll need to use the same approach as you would if you needed to "move" data from one page to another. Two common ways (though by no means are these the only ways or even the best ways) are:
The Session object. PageABC can store a piece of data in the session, and PageXYZ can read that data from the session.
URL Parameter on the request. PageABC can call a URL (maybe even use it as the SRC of an iFrame, hint-hint) something like this: PageXYZ.aspx?someKey=someValue. PageXYZ can access URL params from the Request object (Request["someKey"])
Something else to consider: if PageABC and PageXYZ operate in conjunction with each other, maybe having them be separate pages isn't the best approach. It may make more sense for PageXYZ to actually be ControlXYZ and be contained on PageABC. It can still be presented to the user as a popup using jQuery dialogs (or using UpdatePanels and ModalPopupExtenders, if you're masochistic ;).

Categories

Resources