Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 11th, 2005, 12:05 AM
Authorized User
 
Join Date: Dec 2004
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ALEX_GRIM
Default problems comunicating with paypal server

here's how it works:
1: someone makes an order/subscription through your site's account,

2: paypal send the details to a page on your server which will handle the results,

3: your page must get the querystring names & values and send them straight back to paypal, so paypal can evaluate the values to see if they really came from paypal to beging with,and that they were not altered,

4: paypal then sends back a response, if response = validated then You.DoYourThing else response = "invalid" then You.DoYourOtherThing

my problem is that i don't think i'm actually getting all the querystring names and values with my script and sending them back to paypal sucsessfully. So THAT'S why i'm here, to see if you guys can tell me if my script looks like that's what it's supposed to be doing, recieving querystring info, and sending it straight back in the same format.
i am very new to all programming, so i BARELY understood what i did so far, so i wouldn't doubt that it's wrong, but i can't see where, and paypal doesn't give many vb.net examples, most are php, cold fusion, c#(which is what i based MY script off of (the C# example)), and perl.
they gave a vb.net example, but i don't really understand how to use it, because i'm always working with aspx pages,a nd i THINK it's a service module example, actually, you tell me, here it is:
Code:
ASP.Net/VB


Imports System.Net
Imports System.IO
Imports System.Text

Public Class IPNHandler
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()>Private Sub InitializeComponent()

End Sub

'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim strFormValues As String = Request.Form.ToString()
Dim strNewValue, strResponse

' Create the request back
Dim req As HttpWebRequest = CType(WebRequest.Create("https://www.paypal.com/cgi-bin/webscr"), _
HttpWebRequest)

' Set values for the request back
req.Method = "POST"
req.ContentType = "application/x-www-form-urlencoded"
strNewValue = strFormValues + "&cmd=_notify-validate"
req.ContentLength = strNewValue.Length

' Write the request back IPN strings
Dim stOut As StreamWriter = New StreamWriter(req.GetRequestStream(), _
Encoding.ASCII)
stOut.Write(strNewValue)
stOut.Close()
and here's the C# i based MINE off of:
Code:
ASP.Net/C#


/// <summary>
/// Verifies the IPN message from PayPal
/// </summary>
/// <remarks>
/// Add code under Create the IpnTransaction to process your IPN
/// </remarks>
public class IpnHandler : System.Web.UI.Page
{

private void Page_Load(object sender, System.EventArgs e)
{
string strFormValues = Request.Form.ToString();
string strNewValue;
string strResponse;
// Create the request back
HttpWebRequest req = (HttpWebRequest) WebRequest.Create("https://www.paypal.com/cgi-bin/webscr");

// Set values for the request back
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
strNewValue = strFormValues + "&cmd=_notify-validate";
req.ContentLength = strNewValue.Length;
// Write the request back IPN strings
StreamWriter stOut = new StreamWriter (req.GetRequestStream(), System.Text.Encoding.ASCII);
stOut.Write(strNewValue);
stOut.Close();

// Do the request to PayPal and get the response
StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream());
strResponse = stIn.ReadToEnd();
stIn.Close();

// Confirm whether the IPN was VERIFIED or INVALID. If INVALID, just ignore the IPN
if (strResponse == "VERIFIED")
{
// Create the IpnTransaction

}
}
}
ANY help at all is apreciated, even if you could just tell me if those two example were supposed to be .asmx files, but i'd be grateful as well if someone could tell me wht is wrong with my script. by the way, i AM getting a final response from paypal, but it's "invalid".
here's MY script:

<%@ Import namespace="System.NET" %>
<%@ Import namespace="System.data" %>
<%@ Import namespace="System.IO" %>
<%@ Import namespace="System.data.OLEDB" %>
<SCRIPT RUNAT=SERVER LANGUAGE="VB">

        Sub Page_Load(Sender As Object, E As EventArgs)


DIM SUBSCRIPTIONVALUES AS STRING = REQUEST.FORM.TOSTRING()


DIM REQ AS HTTPWEBREQUEST = CType(WebRequest.Create("https://www.sandbox.paypal.com/cgi-bin/webscr"), HttpWebRequest)
DIM CHECKSUBSCRIPTION AS STRING = SUBSCRIPTIONVALUES & "&cmd=_notify-validate"

REQ.METHOD = "POST"
REQ.CONTENTTYPE = "APPLICATION/X-WWW-FORM-URLENCODED"
REQ.CONTENTLENGTH = CHECKSUBSCRIPTION.LENGTH

DIM SENDVERIFY AS STREAMWRITER = NEW STREAMWRITER(REQ.GETREQUESTSTREAM(),SYSTEM.TEXT.EN CODING.ASCII)
SENDVERIFY.WRITE(CHECKSUBSCRIPTION)
SENDVERIFY.CLOSE()


DIM RETURNINFO AS STREAMREADER = NEW STREAMREADER(REQ.GETRESPONSE().GETRESPONSESTREAM() )

DIM VERIFYRESPONSE AS STRING = RETURNINFO.READTOEND()
RETURNINFO.CLOSE()
Response.Write(VERIFYRESPONSE & "<BR>" & SUBSCRIPTIONVALUES & "<br>" & REQUEST.QUERYSTRING("at") & REQUEST.QUERYSTRING("reciever_email") & REQUEST.QUERYSTRING("tx") & "<Br>" )

END SUB
</SCRIPT>

thanks: ALEX GRIM

---------------------------
A Black sheep moves easy in the darkness.
[email protected]
WWW.GRIMMUSIC.COM
__________________
---------------------------
A Black sheep moves easy in the darkness.
[email protected]
WWW.GRIMMUSIC.COM
 
Old May 11th, 2005, 01:37 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anubhav.kumar
Default

hi dear,

i think the problematic line is

Dim strFormValues As String = Request.Form.ToString()

There is no such method in Request.form. Moreover tostring method returns the description of the object not the contents as far as my understanding goes about .Net Classes.

My Suggestion is:
You should enumerate the data send by the request by iterating through the Form.Items collection and form your own query string
and then append "&cmd=_notify-validate" in the end of it.
I am not sure that it will work but try it anyways.

Cheers

Anubhav Kumar
 
Old May 14th, 2005, 04:04 PM
Authorized User
 
Join Date: Dec 2004
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ALEX_GRIM
Default

Ok, i obviously have to iterate through to querystring key/value pairs and store them in an array, then use a foreach statement to build a new querystring to post back then append the "cmd=notify_validate" querystring parameter, but what i'm not sure how to do it iterate through the querystring to begin with.
for example, would it look something like this?:

{begin my code}
dim A as array
dim S as string
dim N as integer
dim MyQueryString as string
for each S in request querystring(N)
A.add(S)
next

for each S in A
MyQueryString &= S
next

MyQueryString &= "&cmd=notify_validate"

{end my code}

i know this ISN'T what i need to do, but i also know that it's CLOSE.
so can you tell me how to get each querystring so that i can use them to build another?
thanks in advance for your time.

---------------------------
A Black sheep moves easy in the darkness.
[email protected]
WWW.GRIMMUSIC.COM
 
Old May 14th, 2005, 09:04 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You can get the complete raw querystring by the server variable "QUERY_STRING". Just grab that and add on whatever you need.

-Peter
 
Old June 1st, 2005, 11:21 AM
Registered User
 
Join Date: Jun 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Alex,

I'm a newbie to paypal linking with asp.net. I am trying to collect user info from my site and send it off to the paypal server when the user clicks the 'CHECK OUT' button. However when i use the code below i dont get transferred to the paypal page rather I keep seeing the same page (with the checkout button). I read some other place that webforms only post back to themselves and not to other pages. Can u pls lemme know how you did this. Will appreciate help.

'============================
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim postData As String
        Dim encoding = New System.Text.ASCIIEncoding
        Dim data As Byte()
        Dim newStream As Stream

        postData = "cmd=_ext-enter"
        postData += "&redirect_cmd=_xclick"
        postData += "&[email protected]"
        postData += "&item_name=baseball bat"

        data = encoding.GetBytes(postData)

        Dim myRequest As System.Net.HttpWebRequest = WebRequest.Create("https://www.paypal.com/cgi-bin/webscr")
        myRequest.Method = "post"
        myRequest.ContentType = "application/x-www-form-urlencoded"
        myRequest.ContentLength = data.Length

        newStream = myRequest.GetRequestStream
        newStream.Write(data, 0, data.Length)
        newStream.Close()

    End Sub
'============================

Thanks,
Syes


 
Old June 1st, 2005, 02:25 PM
Authorized User
 
Join Date: Dec 2004
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ALEX_GRIM
Default

Well, you must specify the other page's url in the "post" parameter of the "form" tag.

eg: <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">

and this must be on the page with the pay button, and the button must be within form tags........
eg:

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="notify_url" value="HTTP%3A//WWW.MEMBERS.GRIMMUSIC.COM/PAIDup.ASPX">
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/x-click-but20.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
<input type="hidden" name="encrypted" value="-----BEGIN">
</form>

does this help ya?

if not........ go here:
http://paypal.forums.liveworld.com/index.jspa

---------------------------
A Black sheep moves easy in the darkness.
[email protected]
WWW.GRIMMUSIC.COM
 
Old June 1st, 2005, 02:34 PM
Authorized User
 
Join Date: Dec 2004
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ALEX_GRIM
Default

it looks like what you are trying to build with your script is an IPN or PDT handler script, if so, ignore my last post, because i thought you were asking for help with posting the INITIAL info to paypal via a "pay" or "subscribe" button.
so if you need help with your IPN or PDT script, you're in the same boat as me.
GOOD LUCK!!! lol

---------------------------
A Black sheep moves easy in the darkness.
[email protected]
WWW.GRIMMUSIC.COM
 
Old June 1st, 2005, 04:19 PM
Registered User
 
Join Date: Jun 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Alex,

Thx for the response. Your suggestion seems to apply to regular asp. I tried adding 'action' to the form tag in my aspx page but no success. btw, I am simply trying to send the buyer's shipping address and price info to the paypal page using asp.net. IPN is somewhere down the road for me. I can do that using a query string and response.redirect command but that is of course not secure. I would like to use a simple post method in asp.net.

Also when I send it using the regular ASP, the shipping address fields get populated fine. However the shipping address can be modified by the buyer which is not good because I've calculated the total based on the shipping address the user entered on my page, and now I will get a shipping address in my paypal account that is different from what I have in my local database. How do i set the shipping address in paypal so that paypal receives the address but does not allow modification of it?

Thanks,
Raza



 
Old June 1st, 2005, 06:20 PM
Authorized User
 
Join Date: Dec 2004
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ALEX_GRIM
Default

i wouldn't know that one, i'm new to PayPal's buissness class, so i don't know all thier options.

---------------------------
A Black sheep moves easy in the darkness.
[email protected]
WWW.GRIMMUSIC.COM





Similar Threads
Thread Thread Starter Forum Replies Last Post
paypal and asp ocabrera70 Classic ASP Professional 3 September 25th, 2014 06:30 AM
PayPal Integration takwirira ASP.NET 2.0 Basics 0 May 12th, 2008 05:44 AM
PayPal - IPN Shabequl PHP How-To 1 September 26th, 2007 05:15 PM
paypal ? anshul Pro PHP 1 November 24th, 2004 01:19 AM
Beginning E-Commerce ASP.NET PayPal problems mluirette All Other Wrox Books 0 December 18th, 2003 03:35 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.