/ ** * @Author bcoffman * who gratefully Acknowledges the initial control @ r a s. * * Java refundtransaction
import java.net.URL; 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 refundTransaction {public static void main (string [] args) throws exception {if (args.length <1) {system.out.println ("Usage: java refundtransaction
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 ("REFUND_VERSION", (String) A.VAL ("V" )));} Client.RunrefundTransaction (Argv [0], MEMO, CFG);} public refundTransAction ()}
Public static void usage () {system.out.println ("Usage: java
public void runRefundTransaction (String txn_id, String memo, SimpleConfigFile cfg) throws Exception {// First, we load the config file, and build a request object ... String url = cfg.val ( "url"); System.out. println ( "connecting to /" " url " / ": testing RefundTransaction (/" " txn_id " / ")"); // PpapiPortType binding = null; 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"; E.PrintStackTrace (); // throw axisfault .makefault (e); return;}}}} refundTransactionRequestType Request = New REFUNDTRANSACTIONREQUESTTYPE ();
Request.setversion (CFG.VAL ("REFUND_VERSION")); // a bug in axis 1.1 causes this to fail. String refund_type = cfg.val ("refund_is"); if (refund_type.length ()! = 0) Request .sefundType (eblbasecomponents.apis.ebay.refundpurposeTypecodtype.fromstring (refund_type));
String amount = new string (cfg.val ("refund_amount"); string currencyid = new string (cfg.val ("refund_currency_code");
IF (Amount.length ()! = 0) {CorecomponentTypes.apis.ebay.basicamountType AmountType = New CoreComponenttypes.apis.ebay.basicamountType (Amount); Request.setAmount (AmountType);
if (currencyID.length () = 0!) amountType.setCurrencyID (eBLBaseComponents.apis.ebay.CurrencyCodeType.fromString (currencyID));} if (memo == null) {memo = cfg.val ( "refund_memo");} if (memo.length () = 0!) request.setMemo (memo); // String curr_name = new String (cfg.val ( "refund_currency_code")); request.setTransactionID (new eBLBaseComponents.apis.ebay.TransactionId (txn_id ));
_RefundtransactionReq _req = new _refundTransactionReq (); _REQ.seRefundTransactionRequest (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: EBLBASECMOMPONENTS");
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 PrintRefundReq (Request);
// This actually does the transaction ... // RefundTransactionResponse resp = null; RefundTransactionResponseType resp = null; try {resp = binding.refundTransaction (_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); //e.printstacktrace (); return;}
// process the response ... PrintRefundres (resp);
}
public void printRefundReq (RefundTransactionRequestType req) {System.out.println (); System.out.println ( "RefundTransaction Request ---------"); System.out.println ( "transactionID:" req. GetTransactionId (). Tostring ()); if (Req.getRefundType ()! = null) System.Out.println ("REFUNDTYPE:" Req.getRefundType (). Tostring ()); if (Req.getamount ()! = NULL) {system.out.println ("Amount:" Req.getamount (). toString ()); if (req.getamount (). getcurrencyid ()! = null) System.out.println ("currency: Req.getamount (). getcurrencyid (). TOSTRING ());} if (Req.getMemo ()! = null) System.out.Println ("Memo:" Req.getMemo (). Tostring ()) ; If (req.getversion ()! = Null) System.out.println ("Version:" Req.getversion (). TOSTRING ());}
// public void printRefundRes (RefundTransactionResponse res) {public void printRefundRes (RefundTransactionResponseType res) {// Process the response ... System.out.println (); System.out.println ( "RefundTransaction Response ------- - "); System.out.println (" Ack: " res. geneTack (). TOSTRING ()); System.out.Println (" TimeStamp: " res.getTimeStamp (). GetTime ()); if (Res. GetcorRelationId ()! = null) System.out.println ("CorrelationID:" res. max ()); if (res. max ()! = null) System.out.println (" Version: " res. Getversion (). TOSTRING ()); if (res.getbuild ()! = Null) System.out.println (" build: " res. GetBuild (). Tostring ());