Initially you must provide for an IWForm to be created for the content returned from the PayPal server, which must correlate with your PayPal auto return URL defined in your paypal merchant account. This can be done in your ServerController.OnConfig event eg...
- Code: Select all
{instantiate content handler for PayPal auto-return URL as setup in PayPal merchant account}
with THandlers.Add(EmptyStr, 'transaction.html', TContentForm.Create(TformPDT_TX)) do
CanStartSession := False;
... the TformPDT_TX.OnCreate event will need code similar to the following in order to manage the PDT information. An instance of TIdHTTP and TIdSSLIOHandlerSocketOpenSSL (to handle the secure protocol) will be required ...
- Code: Select all
procedure TformPDT_TX.IWAppFormCreate(Sender: TObject);
var
S, R: TStringList;
M: TStream;
begin
if (WebApplication.Request.QueryFields.IndexOfName('tx') > -1) then begin
R := TStringList.Create;
try
S := TStringList.Create;
M := TMemoryStream.Create;
try
S.Add('cmd=_notify-synch');
S.Add('tx=' + WebApplication.Request.QueryFields.Values['tx']);
S.Add('at=' + 'Your PayPal PDT ID');
IdHTTP.IOHandler := IdSSLIOHandlerSocketOpenSSL1;
IdHTTP.Request.ContentType := 'application/x-www-form-urlencoded';
IdHTTP.Post('https://www.sandbox.paypal.com/cgi-bin/webscr', S, M); // sandbox for testing only, remove for live transactions
M.Position := 0;
S.LoadFromStream(M);
R.AddStrings(S);
finally
FreeAndNil(S);
FreeAndNil(M);
end;
if (idHTTP.ResponseCode = 200) and (R[0] = 'SUCCESS') then begin
// display as required
lablTXNID.Caption := R.Values['txn_id'];
IWCGJQLabel2.Caption := Format('Item: %s', [AnsiReplaceStr(R.Values['item_name1'], '+', ' ')]);
// and whatever else you want to display
end else
WebApplication.ShowMessage('PayPal Payment Data Transfer failed, please check your PayPal Account to verify transaction has been completed.');
finally
FreeAndNil(R);
end;
end else
WebApplication.ShowMessage('Unable to obtain transaction information from PayPal.');
end;
... basically that's it. Does anyone want to write a listener to handle PayPal's IPN

cheers
Pete B.