Solved

Values passing to paypal from C#

Posted on 2011-03-10
11
1,058 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
Industry Leaders: 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 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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
AJAX ModalPopupExtender will Not Hide in Asp.net 1 38
Need help with a query 14 39
Build a string of emails from a gridview 2 18
c#, datatable, aspx 4 23
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

733 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