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. import com.chilkatsoft.*; public class ChilkatExample { static { try { System.loadLibrary("chilkat"); } catch (UnsatisfiedLinkError e) { System.err.println("Native code library failed to load.\n" + e); System.exit(1); } } public static void main(String argv[]) { CkHttpRequest req = new CkHttpRequest(); CkHttp http = new CkHttp(); boolean success; // Any string unlocks the component for the 1st 30-days. success = http.UnlockComponent("Anything for 30-day trial"); if (success != true) { System.out.println(http.lastErrorText()); return; } // These are obviously not real credentials... String username; username = "seller_1999999893_biz_api1.chilkatsoft.com"; String password; password = "1992299958"; String signature; signature = "ALgNZbbbUgjlBaRnvTKJg8-C6AGpAepaaa1rysDXe1OnF7pJcaccccmN"; String version; 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.put_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. String domain; int port; boolean ssl; domain = "api-3t.sandbox.paypal.com"; port = (int) 443; ssl = true; CkHttpResponse resp; // 120-second non-activity timeout. http.put_ReadTimeout(15); resp = http.SynchronousRequest(domain,port,ssl,req); if (resp == null ) { System.out.println(http.lastErrorText()); } 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... String fakeUrl; fakeUrl = "http://www.test.com/abc.asp?" + resp.bodyStr(); // We're only using this request object to parse the NVP-formatted response body. CkHttpRequest req2 = new CkHttpRequest(); req2.SetFromUrl(fakeUrl); // The ACK param can have these values: // Successful responses: // Success // SuccessWithWarning // Error responses: // Failure // FailureWithWarning // Warning System.out.println("ACK: " + req2.getParam("ACK")); // Assuming success, we'll have these params: System.out.println("AMT: " + req2.getParam("AMT")); System.out.println("CURRENCYCODE: " + req2.getParam("CURRENCYCODE")); System.out.println("AVSCODE: " + req2.getParam("AVSCODE")); System.out.println("CVV2MATCH: " + req2.getParam("CVV2MATCH")); System.out.println("TRANSACTIONID: " + req2.getParam("TRANSACTIONID")); System.out.println("TIMESTAMP: " + req2.getParam("TIMESTAMP")); System.out.println("CORRELATIONID: " + req2.getParam("CORRELATIONID")); System.out.println("VERSION: " + req2.getParam("VERSION")); System.out.println("BUILD: " + req2.getParam("BUILD")); // On failure, some of the above params will be set, but these // params will also be present: System.out.println("L_ERRORCODE0: " + req2.getParam("L_ERRORCODE0")); System.out.println("L_SHORTMESSAGE0: " + req2.getParam("L_SHORTMESSAGE0")); System.out.println("L_LONGMESSAGE0: " + req2.getParam("L_LONGMESSAGE0")); System.out.println("L_SEVERITYCODE0: " + req2.getParam("L_SEVERITYCODE0")); } } } |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2008 Chilkat Software, Inc. All Rights Reserved.