Solved

Values passing to paypal from C#

Posted on 2011-03-10
11
1,023 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SSRS ReportViewer report timeout 7 99
Tool Box 2 31
Filename to be appended with DateTimeof Download 3 40
What .NET URL re-routing tool did I use? 2 31
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
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.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
A short film showing how OnPage and Connectwise integration works.

948 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

20 Experts available now in Live!

Get 1:1 Help Now