?
Solved

Values passing to paypal from C#

Posted on 2011-03-10
11
Medium Priority
?
1,090 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 

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 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses
Course of the Month13 days, 17 hours left to enroll

801 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