Jump to content

Recommended Posts

Hi, i try to use paypals IPN (Instant Payment Notification)

I have a paypal express checkout button on my form and after a successfully payment paypal send me a confirmation.

Its works ok i also get success from paypal side (IPN was sent and the handshake was verified.)

 

The problem is that i can't get the request text that paypal send to me. I will use the request text on a memo in my session.

Have somebody any idea how to make this?

 

i use TIdHTTPServer, TIdHTTPand TIdSSLIOHandlerSocketOpenSSL places on the UniServerModule form with following settings

object IdHTTPServer1: TIdHTTPServer
    Active = True
    Bindings = <>
    DefaultPort = 82
    AutoStartSession = True
    OnCommandGet = IdHTTPServer1CommandGet
    Left = 60
    Top = 80
  end
  object http1: TIdHTTP
    IOHandler = OpenSSL
    AllowCookies = True
    ProxyParams.BasicAuthentication = False
    ProxyParams.ProxyPort = 0
    Request.ContentLength = -1
    Request.Accept = 'text/html, */*'
    Request.BasicAuthentication = False
    Request.UserAgent = 'Mozilla/3.0 (compatible; Indy Library)'
    HTTPOptions = []
    Left = 175
    Top = 80
  end
  object OpenSSL: TIdSSLIOHandlerSocketOpenSSL
    MaxLineAction = maException
    Port = 0
    DefaultPort = 0
    SSLOptions.Method = sslvSSLv23
    SSLOptions.Mode = sslmClient
    SSLOptions.VerifyMode = []
    SSLOptions.VerifyDepth = 0
    Left = 215
    Top = 140
  end

and the code i use is

procedure TUniServerModule.IdHTTPServer1CommandGet(AContext: TIdContext;
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
  strWrite : TStringList;
  strRead  : String;
begin
  strWrite := TStringList.Create;
  try
    strWrite.Add(ARequestInfo.FormParams+'&cmd=_notify-validate');
    IdHTTP1.Request.UserAgent := 'application/x-www-form-urlencoded';
    IdHTTP1.ReadTimeout := 0;
    IdHTTP1.IOHandler := OpenSSL;

    strRead := IdHTTP1.Post('https://www.paypal.com/cgi-bin/webscr', strWrite);   // If you are in live
    //strRead := IdHTTP1.Post('https://www.sandbox.paypal.com/cgi-bin/webscr', strWrite);  // If you are in sandbox

    TThread.Synchronize(nil,
      procedure
      begin
        MainForm.UniMemo1.Lines.LoadFromStream(ARequestInfo.PostStream); //not works :-)
        //or
        MainForm.UniMemo2.text := strRead;
        MainForm.UniMemo2.Lines.SaveToFile(Uniservermodule.FilesFolderPath + 'test.txt'); //not works :-)
      end);

  except
    on E: Exception do
    begin
      showmessage('Error encountered during POST: ' + E.Message);
    end;
  end;
  strWrite.Free;
end;

Any Suggestion on how to print out the ARequestInfo informations???

 

 

Thanks

 

 

Link to post
Share on other sites

Change you code:

TThread.Synchronize(nil,
      procedure
      begin
        MainForm.UniMemo1.Lines.LoadFromStream(ARequestInfo.PostStream); //not works :-)
        //or
        MainForm.UniMemo2.text := strRead;
        MainForm.UniMemo2.Lines.SaveToFile(Uniservermodule.FilesFolderPath + 'test.txt'); //not works :-)
      end);

to example

var  
  FS: TFileStream;   
--
  FS := TFileStream.Create(Uniservermodule.FilesFolderPath + 'test.txt', fmCreate)
  try
    FS.Seek(0, soFromEnd);  
    FS.Write(Pointer(ARequestInfo.PostStream)^,Length(ARequestInfo.PostStream));
  finally 
    FS.Free 
  end

Another detail, your call must be within an active session.

In this case you are trying to manipulate an object that is not in a session, it is only in ServerModule.
 
This here in the server module is not a good idea:
 
MainForm.UniMemo2.
 
tech-1.png

 

Link to post
Share on other sites

Thank you for you answer!

 

I have transfer everything into UniMainModule but this still no work

i cant get print out a file with the response info from paypal.

 

I have put the IdHTTPServer and other into mainmodule and just try to save into file.

I become an error of "Could not bind socket. Address and port are already in use”, then change idHTTPServer port to 0, but i cant take the response data.  :(  :(

 
i try the code bellow too
var  
  FS: TFileStream;   
--
  FS := TFileStream.Create(Uniservermodule.FilesFolderPath + 'test.txt', fmCreate)
  try
    FS.Seek(0, soFromEnd);  
    //FS.Write(Pointer(ARequestInfo.PostStream)^,Length(ARequestInfo.PostStream));  error in size
    FS.Write(Pointer(ARequestInfo.PostStream)^,FS.size); //i change this
  finally 
    FS.Free 
  end
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...