Solved

Values passing to paypal from C#

Posted on 2011-03-10
11
1,006 Views
Last Modified: 2012-05-11
Hi.

Can anyone work out why the values from my item_name and amount fields wont pass to paypal.

Many thanks!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI.HtmlControls;

public partial class OnlineAccounts_pay : System.Web.UI.Page
{
    private void getData(string number)
    {
        DataTable dt = new DataTable();
        SqlConnection connection = new SqlConnection("Data Source=xxxxxxxxxxxxxxxx");
        connection.Open();
        SqlCommand sqlCmd = new SqlCommand("SELECT * from tblInvoices WHERE InvoiceNumber = @number", connection);
        SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);

        sqlCmd.Parameters.AddWithValue("@number", Request.QueryString["number"]);
        sqlDa.Fill(dt);
        if (dt.Rows.Count > 0)
        {
            amount.Value = dt.Rows[0]["InvoiceAmount"].ToString();
            item_name.Value = dt.Rows[0]["InvoiceNumber"].ToString();
        }
        connection.Close();
    } 

    
   protected void Page_Load(object sender, EventArgs e)
    {

        getData(Request.QueryString["number"]); 

        
    }
   

}

Open in new window


<input type="hidden" name="cmd" value="_xclick" />
    <input type="hidden" name="business" value="onlinepay@mysite.com" />
    <input type="hidden" name="currency_code" value="GBP" />
    <input type="hidden" name="return" value="http://www.mysite.com/InvoicePaid.aspx" />
    <input type="hidden" name="no_note" value="1" />
    
    


    Invoice Number: 
    <input type="text" name="item_name" ID="item_name" runat="server" readonly="readonly" />
        <br />
    Total Amount:  
    <input type="text" name="amount" ID="amount" runat="server" sreadonly="readonly" />
    <br /><br />
        <asp:Button ID="PayNow" runat="server" Text="PAY NOW!" CausesValidation="False" 
            PostBackUrl="https://www.paypal.com/cgi-bin/webscr" />

Open in new window



Payal screenshot
0
Comment
Question by:jonpwatson5
  • 6
  • 5
11 Comments
 
LVL 18

Expert Comment

by:Ajay Sharma
ID: 35106486
The problem is that is the item_name and amount should be the Hidden fields in the form.
e.g.
<input type="hidden" name="item_name" value="<%Response.Write (val_item_name)%>">
<input type="hidden" name="amount" value="<%Response.Write (val_amount)%>">

To pass the values to these hidden fields you can modify your code behind like below:
public string val_amount;
public string val_item_name;

if (dt.Rows.Count > 0)
        {
            val_amount.Value = dt.Rows[0]["InvoiceAmount"].ToString();
            val_item_name.Value = dt.Rows[0]["InvoiceNumber"].ToString();
        }
0
 

Author Comment

by:jonpwatson5
ID: 35117422
I'm now getting build errors.

Error      1      'string' does not contain a definition for 'Value' and no extension method 'Value' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)      pay.aspx.cs      30      24

Error      2      'string' does not contain a definition for 'Value' and no extension method 'Value' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)      pay.aspx.cs      31      27      

Error      3      ; expected      pay.aspx      21      
Error      4      ; expected      pay.aspx      22      


pay.aspx.cs

val_amount.Value = dt.Rows[0]["InvoiceAmount"].ToString();
val_item_name.Value = dt.Rows[0]["InvoiceNumber"].ToString();


'Value' is causing the error.



pay.aspx

<input type="hidden" name="item_name" value=" <% response.write (val_item_name) %>" >
<input type="hidden" name="amount" value="<%Response.Write (val_amount)%>" >


expected ; on these 2 lines?
0
 
LVL 18

Expert Comment

by:Ajay Sharma
ID: 35119609
sorry, it was a typo error, remove the value property as belows:

val_amount = dt.Rows[0]["InvoiceAmount"].ToString();
val_item_name = dt.Rows[0]["InvoiceNumber"].ToString();
0
 

Author Comment

by:jonpwatson5
ID: 35121572
Thanks.

That solved that bit, Been trying to get the front page to work as well but still getting the build erorrs with the ; parts?????
0
 
LVL 18

Expert Comment

by:Ajay Sharma
ID: 35121615
Any line numbers mentioned for errors ??
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:jonpwatson5
ID: 35121637
pay.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/OnlineAccounts/Site.master" AutoEventWireup="true" CodeFile="pay.aspx.cs" Inherits="OnlineAccounts_pay" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
    <p>
        Welcome to our e-payment service.</p>
    <p>
        For your security and safety, card payments are handled by our partner Paypal.<br />
        Please review the details below and click &#39;PAY NOW&#39; to proceed.</p>
    <p>
        Invoice Number:<asp:TextBox ID="txtInvoiceNumber" runat="server"></asp:TextBox>
    </p>
    <p>
        Invoice Amount:<asp:TextBox ID="txtInvoiceAmount" runat="server"></asp:TextBox>
    </p>
    <p>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="business" value="onlinepay@mysite.com" />
<input type="hidden" name="currency_code" value="GBP" />
<input type="hidden" name="return" value="http://www.mysite.com/InvoicePaid.aspx" />
<input type="hidden" name="no_note" value="1" />
<input type="hidden" name="item_name" value=" <% response.write (val_item_name) %>" >
<input type="hidden" name="amount" value="<%Response.Write (val_amount)%>" >
<asp:Button ID="btnPayNow" runat="server" Text="PAY NOW" 
            PostBackUrl="https://www.paypal.com/cgi-bin/webscr" />
    </p>
</asp:Content>

Open in new window


pay.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class OnlineAccounts_pay : System.Web.UI.Page
{

    public string val_amount;
    public string val_item_name;

    protected void Page_Load(object sender, EventArgs e)
    {
        getData(Request.QueryString["number"]);
    }

    protected void getData(string number)
    {
        DataTable dt = new DataTable();
        SqlConnection connection = new SqlConnection("Data Source=localhost;Initial Catalog=databasename;User ID=myuser;Password=mypassword");
        connection.Open();
        SqlCommand sqlCmd = new SqlCommand("SELECT * from tblInvoices WHERE InvoiceNumber = @number", connection);
        SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);
        sqlCmd.Parameters.AddWithValue("@number", Request.QueryString["number"]);
        sqlDa.Fill(dt);
        if (dt.Rows.Count > 0)
        {
            val_amount = dt.Rows[0]["InvoiceAmount"].ToString();
            val_item_name = dt.Rows[0]["InvoiceNumber"].ToString();

            txtInvoiceAmount.Text = dt.Rows[0]["InvoiceAmount"].ToString();
            txtInvoiceNumber.Text = dt.Rows[0]["InvoiceNumber"].ToString();

           

            

        }

    }
}

Open in new window


Errors:

Warning      1      Validation (XHTML 1.0 Transitional): Empty elements such as 'input' must end with />.      \OnlineAccounts\pay.aspx      24      2
Warning      2      Validation (XHTML 1.0 Transitional): Empty elements such as 'input' must end with />.      \OnlineAccounts\pay.aspx      25      2
Error      3      ; expected      OnlineAccounts\pay.aspx      24      
Error      4      ; expected      OnlineAccounts\pay.aspx      25      
0
 
LVL 18

Expert Comment

by:Ajay Sharma
ID: 35121659
Replace line number 24's text in ASPX as belows:
<input type="hidden" name="item_name" value=" <% response.write (val_item_name) %>" />

Replace line number 25's text in ASPX as belows:
<input type="hidden" name="amount" value="<%Response.Write (val_amount)%>" />
0
 

Author Comment

by:jonpwatson5
ID: 35121665
Error      1      ; expected      \OnlineAccounts\pay.aspx      24      
Error      2      ; expected      \OnlineAccounts\pay.aspx      25      
0
 
LVL 18

Accepted Solution

by:
Ajay Sharma earned 500 total points
ID: 35121740
Replace line number 24's text in ASPX as belows:
<input type="hidden" name="item_name" value=" <% Response.Write (val_item_name); %>" />

Replace line number 25's text in ASPX as belows:
<input type="hidden" name="amount" value="<%Response.Write (val_amount); %>" />
0
 

Author Comment

by:jonpwatson5
ID: 35121758
Brilliant, thats now working. Really appreciate the help :)
0
 
LVL 18

Expert Comment

by:Ajay Sharma
ID: 35121791
I am glad it's working now.

Alternative to the Response.Write, you can modify the code as:

<input type="hidden" name="amount" value="<%= val_amount %>" />
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now