Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Submit Credit Card Transaction to PayPalSubmits 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.
Dim req As New Chilkat.HttpRequest() Dim http As New Chilkat.Http() Dim success As Boolean ' Any string unlocks the component for the 1st 30-days. success = http.UnlockComponent("Anything for 30-day trial") If (success <> true) Then MsgBox(http.LastErrorText) Exit Sub End If ' These are obviously not real credentials... Dim username As String username = "seller_1999999893_biz_api1.chilkatsoft.com" Dim password As String password = "1992299958" Dim signature As String signature = "ALgNZbbbUgjlBaRnvTKJg8-C6AGpAepaaa1rysDXe1OnF7pJcaccccmN" Dim version As String 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. Dim domain As String Dim port As Long Dim ssl As Boolean domain = "api-3t.sandbox.paypal.com" port = 443 ssl = true Dim resp As Chilkat.HttpResponse ' 120-second non-activity timeout. http.ReadTimeout = 15 resp = http.SynchronousRequest(domain,port,ssl,req) If (resp Is Nothing ) Then TextBox1.Text = TextBox1.Text & http.LastErrorText & vbCrLf Else ' 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... Dim fakeUrl As String fakeUrl = "http://www.test.com/abc.asp?" & resp.BodyStr ' We're only using this request object to parse the NVP-formatted response body. Dim req2 As New Chilkat.HttpRequest() req2.SetFromUrl(fakeUrl) ' The ACK param can have these values: ' Successful responses: ' Success ' SuccessWithWarning ' Error responses: ' Failure ' FailureWithWarning ' Warning TextBox1.Text = TextBox1.Text & "ACK: " & req2.GetParam("ACK") & vbCrLf ' Assuming success, we'll have these params: TextBox1.Text = TextBox1.Text & "AMT: " & req2.GetParam("AMT") & vbCrLf TextBox1.Text = TextBox1.Text & "CURRENCYCODE: " _ & req2.GetParam("CURRENCYCODE") & vbCrLf TextBox1.Text = TextBox1.Text & "AVSCODE: " _ & req2.GetParam("AVSCODE") & vbCrLf TextBox1.Text = TextBox1.Text & "CVV2MATCH: " _ & req2.GetParam("CVV2MATCH") & vbCrLf TextBox1.Text = TextBox1.Text & "TRANSACTIONID: " _ & req2.GetParam("TRANSACTIONID") & vbCrLf TextBox1.Text = TextBox1.Text & "TIMESTAMP: " _ & req2.GetParam("TIMESTAMP") & vbCrLf TextBox1.Text = TextBox1.Text & "CORRELATIONID: " _ & req2.GetParam("CORRELATIONID") & vbCrLf TextBox1.Text = TextBox1.Text & "VERSION: " _ & req2.GetParam("VERSION") & vbCrLf TextBox1.Text = TextBox1.Text & "BUILD: " _ & req2.GetParam("BUILD") & vbCrLf ' On failure, some of the above params will be set, but these ' params will also be present: TextBox1.Text = TextBox1.Text & "L_ERRORCODE0: " _ & req2.GetParam("L_ERRORCODE0") & vbCrLf TextBox1.Text = TextBox1.Text & "L_SHORTMESSAGE0: " _ & req2.GetParam("L_SHORTMESSAGE0") & vbCrLf TextBox1.Text = TextBox1.Text & "L_LONGMESSAGE0: " _ & req2.GetParam("L_LONGMESSAGE0") & vbCrLf TextBox1.Text = TextBox1.Text & "L_SEVERITYCODE0: " _ & req2.GetParam("L_SEVERITYCODE0") & vbCrLf End If |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2007 Chilkat Software, Inc. All Rights Reserved.