/ ** * @Author Dhan * * java transactions * * /
import java.net.URL; import java.text.DateFormat; import org.apache.axis.message.SOAPHeaderElement; import org.apache.axis.message.PrefixedQName; import org.apache.axis.message.MessageElement; import org. Apache.axis.axisfault; import org.apache.axis.client. *; import java.io. *; import java.util. *; import com.paypal.api.client. *; // paypal library, see the src directory.import eBLBaseComponents.apis.ebay *;. // eBay Business Logic definition, from eBL_ * wsdl.import PayPalAPI.api.ebay *;. // Based on PayPalSvc.wsdl.import CoreComponentTypes.apis.ebay *.;
public class TransactionSearch {public static void main (String [] args) throws Exception {TransactionSearch client = new TransactionSearch (); ReadArgs a = new ReadArgs ( "h: su: sp: sk: sw: sv: s", args); IF (! a.ok ()) USAGE (); hashtable h = a.hash (); string [] argv = a.Args (); if (argv.Length! = 0) {system.out.println (" USAGE: Java TransactionSearch [Options] "); Return;}
SimpleConfigfile CFG = New SimpleConfigfile ("Client_config.nvp");
IF (A.Contain)) {cfg.set ("URL", (String) A.VAL ("H"));} IF (A.Contains ("U")) {cfg.set "User_name", (String) A. Val ("U"));} if (A.Contains ("P")) {cfg.set ("User_Passwd", (String) A.VAL ("P")) } IF (A.Contains ("K")) {cfg.set ("CERT_FILE", (String) A.VAL ("K"));} IF (A.Contain)) {CFG. SET ("CERT_PASSWORD", (String) A.Val ("W"));} if (A.Contain)) {cfg.set ("TS_VERSION", (String) A.VAL ("V" ))));} Client.RuntiaSactionSearch (CFG);
Public static void usage () {system.out.println ("Usage: java
PayPalAPIInterface binding = null; try {binding = new PayPalAPIInterfaceServiceLocator () getPayPalAPI (new URL (url));. ((PayPalAPISoapBindingStub) binding) .setTimeout (60000);} catch (Exception e) {org.apache.axis.AxisFault afe = NULL; if (e instanceof org.apache.axis.axisfault) {Afe = (org.apache.axis.axisfault) E;} String Note = Afe.GetFaultString (); System.out.println ("got axisfault exception" Note.toString ()); E.PrintStackTrace (); // throw axisfault.makefault (e); return;}
// start composing the request object TransactionSearchRequestType request = new TransactionSearchRequestType (); String startDate = cfg.val ( "ts_start_date"); String endDate = cfg.val ( "ts_end_date"); String payerEmail = cfg.val ( "ts_payer_email") ; String receiverEmail = cfg.val ( "ts_receiver_email"); String transactionClass = cfg.val ( "ts_transaction_Class"); String amount = cfg.val ( "ts_amount"); String currencyCode = cfg.val ( "ts_currency_code"); String status = cfg.val ( "ts_status"); PersonNameType payername = new PersonNameType (); String salutation = cfg.val ( "ts_payer_salutation"); String firstname = cfg.val ( "ts_payer_firstName"); String middlename = cfg.val ( "ts_payer_middleName"); String lastname = cfg.val! ( "ts_payer_lastName"); String suffix = cfg.val ( "ts_payer_suffix"); if (salutation.length () = 0) payername.setSalutation (new eBLBaseComponents.apis.ebay . SalutationType (SaLutation)); if (firstname.length ()! = 0) PayerName.SetFirstName (new eblbasecomponents.apis.ebay.nam eType (firstname));! if (middlename.length () = 0) payername.setMiddleName (new eBLBaseComponents.apis.ebay.NameType (middlename));! if (lastname.length () = 0) payername.setLastName (new eBLBaseComponents.apis.ebay.NameType (lastname)); if (suffix.length () = 0) payername.setSuffix (new eBLBaseComponents.apis.ebay.SuffixType (suffix));!! / * if (payername = null) request .SETPAYERNAME (PAYERNAME); * / if (Startdate.Length ()! = 0) {java.util.calendar StartDate = Calendar.GetInstance (); startdate.date (new java.util.date (startdate);
Request.setStartDate (startdate);} if (enddate.Length ()! = 0) {java.util.calendar enddate = calendar.getInstance (); enddate. setttime (new java.util.date (enddate)); request. setEndDate (enddate);} if (payerEmail.length () = 0!) request.setPayer (new eBLBaseComponents.apis.ebay.EmailAddressType (payerEmail)); if (! receiverEmail.length () = 0) request.setReceiver (new eBLBaseComponents.apis.ebay.EmailAddressType (receiverEmail)); String receiptID = cfg.val ( "ts_receipt_ID"); if (receiptID.length ()! = 0) request.setReceiptID (receiptID); String txnID = cfg.val ( " ts_transaction_ID ");! if (txnID.length () = 0) {TransactionId tid = new TransactionId (txnID); request.setTransactionID (tid);} String itemnumber = cfg.val (" ts_auction_ItemNumber "); if (itemnumber.length ! () = 0) request.setAuctionItemNumber (itemnumber); if (transactionClass.length ()! = 0) request.setTransactionClass (eBLBaseComponents.apis.ebay.PaymentTransactionClassCodeType.fromString (transactionCla SS));
// String currencyID = cfg.val ( "mp_currency_code"); if (! Amount.length () = 0) {CoreComponentTypes.apis.ebay.BasicAmountType amountType = new CoreComponentTypes.apis.ebay.BasicAmountType (amount); request.setAmount (amountType);} if (currencyCode.length () = 0!) request.setCurrencyCode (eBLBaseComponents.apis.ebay.CurrencyCodeType.fromString (currencyCode)); if (! status.length () = 0) request.setStatus (eBLBaseComponents .apis.ebay.paymentTransactionStatusCodettype.fromstring (status));
//amountType.setCurrencyID(eBLBaseComponents.apis.ebay.CurrencyCodeType.fromString(currencyID)); request.setVersion (cfg.val ( "ts_version")); // A bug in axis 1.1 causes this to fail _TransactionSearchReq _req = new. _TransactionSearchReq (); if (request == null) {system.out.println ("No Search critiria being defined !!!!"); return;} _req.settransactionsearchRequest (request);
// use proxy settings if set in config file ... if (cfg.val ("proxy_host")! = Null) {system.SetProperty ("http.proxyhost", cfg.val ("proxy_host")); if ( cfg.val ("proxy_host")! = null) {System.SetProperty ("http.proxyport", cfg.val ("proxy_port");} else {system.setProperty ("http.proxyport", "80") }}
// Insert ebl security ... PrefixedQName pqn = new PrefixedQName ( "urn: ebay: api: PayPalAPI", "RequesterCredentials", ""); SOAPHeaderElement eblSecurity = new SOAPHeaderElement (pqn); eblSecurity.setMustUnderstand (true);
MessageElement Credentials = New MessageElement ("Credentials", "EBL", "URN: eBay: Apis: eblbasecomponents);
MessageElement username = new MessageElement ( "", "ebl: Username"); MessageElement password = new MessageElement ( "", "ebl: Password"); MessageElement subject = new MessageElement ( "", "ebl: Subject"); username. setObjectValue (cfg.val ( "user_name")); credentials.addChild (username); password.setObjectValue (cfg.val ( "user_passwd")); credentials.addChild (password); subject.setObjectValue (cfg.val ( "user_subject ")); Credentials.addchild (Subject); EBLSecurity.addchild (Credentials); org.apache.axis.client.stub s = (stub) binding; s.setheader (EBLSecurity); // Below Allows SSL Connections ... Org.apache.axis.Axisproperties.SetProperty ("Axis.SocketSecureFactory", "com.paypal.api.client.sslfactory);
// Print The Request Object PrintSetTransactionSearchReq (Request);
// This actually does the transaction ... TransactionSearchResponseType resp = null; try {resp = binding.transactionSearch (_req);} catch (Exception e) {org.apache.axis.AxisFault afe = null; if (e instanceof org. Apache.axis.axisfault) {Afe = (org.apache.axis.axisfault) E;} String Note = Afe.dumptostring (); System.out.Println ("Failed on Transaction:" Note.toTString ()); //e.printstacktrace (); return;
// process the response ... printTransactionSearchres (resp);
}
Public void PrintSetTransactionSearchreq (TransactionsRequestType Req) {PrintResults Display = New PrintResults ();
System.out.println (); system.out.println ("************ transactions"); if (Req.getStartDate) )! = null) System.out.println ("Start Date:" Req.getStartDate (). getTime ()); if (req.geetenddate ()! = null) System.out.println ("end Date:" Req.getenddate (). getTime ()); if (Req.getPayer ()! = null) System.out.println ("Payer Email:" Req.getPayer ()); if (Req.getReceiver ()! = null) System.out.println ("Receiver Email:" Req.getReceiver ()); if (Req.GetReceiptId ()! = null) System.Out.Println ("Receipt ID:" Req.getRecEcEIPTID () ); If (req.gettransaction)! = Null) System.out.println ("Transaction ID:" Req.getTransactionId ()); if (Req.GetauctionItemNumber ()! = Null) System.out.println (" AUCTION ITEMNUMNUMNUMNUMBER ()); if (Req.getTransActionClass ()! = Null) System.Ost.Println ("TransactionClass:" Req.getTransActionClass (). Tostring ()); if (Req.Getamount ()! = NULL) System.Out.println ("Amount:" Req.getamount (). Tostring () "" Req.getamount (). getCurrencyId (). Tostring ()); if (Req.getCurrencycode ()! = NULL) System.out.println ("currency code:" req.getcurrencycode (). TOSTRING ()); if (Req.getStatus ()! = null) System.Out.println ("status:" Req.getStatus ()); If (req.getpayername ()! = Null) {system.out.println ("Payer Name:"); Display.PrintPersonNameType (Req.getPayername ());}}
Public void printTransactionSearchres (transactions ") {system.out.println (); system.out.println (" *********** Transaction search response ********** " ); System.out.println ("Ack:" res. geneTack (). TOSTRING ()); System.out.Println ("TimeStamp:" Res. GetTimeStamp (). GetTime ()); if (res. get CorrelationId ()! = null) System.out.Println ("CorrelationID:" res. max ()); if (res. max ()! = null) System.out.println ("Version:" res.getversion (). TOSTRING ()); if (res. max)! = null) System.out.Println ("build:" res. GetBuild (). Tostring ());
PrintResults Display = New PrintResults ();
eBLBaseComponents.apis.ebay.PaymentTransactionSearchResultType [] paymentResult = res.getPaymentTransactions (); if (paymentResult = null!) {for (int j = 0; j EBLBASECMOMPONENTS.APIS.EBAY.ERRORTYPE ERR [] = res. geneRrors (); for (int i = 0; err! = null && i