Delphi Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

Delphi Examples

Bounced Mail
Character Encoding
Digital Certificates
Digital Signatures
Email
FTP
HTML-to-XML
HTTP
IMAP
Encryption
MHT / HTML Email
RSA Encryption
S/MIME
Socket
Spider
String
Tar
Upload
XML
XMP
Zip Compression

More Examples...
Byte Array
Email Object
POP3
SMTP
RSS
Atom
Self-Extractor

Unreleased...
Service
PPMD
Deflate
Bzip2
LZW
Bz2
DH Key Exchange
DSA
Icon

Type Conversion

 

Article: Understanding COM References in Delphi

Submit Credit Card Transaction to PayPal

Submits a credit card transaction to PayPal. The response parameters are displayed for both success and error responses.

This example communicates directly with PayPal's Payflow servers via HTTPS.

Download Chilkat HTTP ActiveX

uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls,
    CHILKATHTTPLib_TLB,
    OleCtrls;

...

procedure TForm1.Button1Click(Sender: TObject);
var
req: TChilkatHttpRequest;
http: TChilkatHttp;
success: Integer;
username: String;
password: String;
signature: String;
version: String;
domain: String;
port: Integer;
ssl: Integer;
resp: IChilkatHttpResponse;
fakeUrl: String;
req2: TChilkatHttpRequest;

begin
req := TChilkatHttpRequest.Create(Self);
http := TChilkatHttp.Create(Self);

//  Any string unlocks the component for the 1st 30-days.
success := http.UnlockComponent('Anything for 30-day trial');
if (success <> 1) then
  begin
    ShowMessage(http.LastErrorText);

  end;

//  These are obviously not real credentials...
username := 'seller_1999999893_biz_api1.chilkatsoft.com';
password := '1992299958';
signature := 'ALgNZbbbUgjlBaRnvTKJg8-C6AGpAepaaa1rysDXe1OnF7pJcaccccmN';
version := '3.2';

//  The PayPal NVP sandbox server for API Signature Security is:
//  https://api-3t.sandbox.paypal.com/nvp

//  Build an HTTPS POST Request:
req.UsePost();
req.Path := '/nvp';

//  The content-type should be text/namevalue
req.AddHeader('content-type','text/namevalue');

req.AddParam('METHOD','doDirectPayment');
req.AddParam('PAYMENTACTION','Sale');
req.AddParam('AMT','1.00');
req.AddParam('IPADDRESS','37.174.133.150');
//  Visa, Discover, Mastercard, or Amex
req.AddParam('CREDITCARDTYPE','Visa');
req.AddParam('ACCT','4397920706128982');
//  expiration date should be formatted MMYYYY
req.AddParam('EXPDATE','022010');
req.AddParam('CVV2','382');
req.AddParam('FIRSTNAME','Test');
req.AddParam('LASTNAME','User');
req.AddParam('STREET','1 Main St');
req.AddParam('CITY','San Jose');
req.AddParam('STATE','CA');
req.AddParam('ZIP','95131');
req.AddParam('COUNTRYCODE','US');
req.AddParam('CURRENCYCODE','USD');

//  Credentials and version:
req.AddParam('VERSION',version);
req.AddParam('USER',username);
req.AddParam('PWD',password);
req.AddParam('SIGNATURE',signature);

//  Send the HTTPS POST and get the response.  Note: This is a blocking call.
//  The method does not return until the full HTTP response is received.

domain := 'api-3t.sandbox.paypal.com';
port := 443;
ssl := 1;

//  120-second non-activity timeout.
http.ReadTimeout := 15;

resp := http.SynchronousRequest(domain,port,ssl,req.DefaultInterface);
if (resp = nil ) then
  begin
    Memo1.Lines.Add(http.LastErrorText);
  end
else
  begin

    //  The response body is in NVP format -- which is nothing more than URL-encoded name/value pairs.
    //  One easy way to parse it is to use the HttpRequest
    //  object in an unorthodox way.
    //  We'll create a fake URL that contains the name/value pairs
    //  found in the body of the response.
    //  Then we'll load it into a temporary HTTP request object.
    //  The HTTP request object does the parsing for us, and we
    //  can look at the params...

    fakeUrl := 'http://www.test.com/abc.asp?' + resp.BodyStr;

    //  We're only using this request object to parse the NVP-formatted response body.
    req2 := TChilkatHttpRequest.Create(Self);
    req2.SetFromUrl(fakeUrl);

    //  The ACK param can have these values:
    //  Successful responses:
    //  Success
    //  SuccessWithWarning
    //  Error responses:
    //  Failure
    //  FailureWithWarning
    //  Warning
    Memo1.Lines.Add('ACK: ' + req2.GetParam('ACK'));

    //  Assuming success, we'll have these params:
    Memo1.Lines.Add('AMT: ' + req2.GetParam('AMT'));
    Memo1.Lines.Add('CURRENCYCODE: ' + req2.GetParam('CURRENCYCODE'));
    Memo1.Lines.Add('AVSCODE: ' + req2.GetParam('AVSCODE'));
    Memo1.Lines.Add('CVV2MATCH: ' + req2.GetParam('CVV2MATCH'));
    Memo1.Lines.Add('TRANSACTIONID: ' + req2.GetParam('TRANSACTIONID'));
    Memo1.Lines.Add('TIMESTAMP: ' + req2.GetParam('TIMESTAMP'));
    Memo1.Lines.Add('CORRELATIONID: ' + req2.GetParam('CORRELATIONID'));
    Memo1.Lines.Add('VERSION: ' + req2.GetParam('VERSION'));
    Memo1.Lines.Add('BUILD: ' + req2.GetParam('BUILD'));

    //  On failure, some of the above params will be set, but these
    //  params will also be present:
    Memo1.Lines.Add('L_ERRORCODE0: ' + req2.GetParam('L_ERRORCODE0'));
    Memo1.Lines.Add('L_SHORTMESSAGE0: ' + req2.GetParam('L_SHORTMESSAGE0'));
    Memo1.Lines.Add('L_LONGMESSAGE0: ' + req2.GetParam('L_LONGMESSAGE0'));
    Memo1.Lines.Add('L_SEVERITYCODE0: ' + req2.GetParam('L_SEVERITYCODE0'));

  end;
end;

 

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2007 Chilkat Software, Inc. All Rights Reserved.

Mail Component · .NET Email Component · XML Parser