GetTransactionDetails

import PayPalAPI.api.ebay.*;
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 eBLBaseComponents.apis.ebay.*;
import com.paypal.api.client.*;


/**
 * @author bcoffman
 * taken from RefundTransaction
 *
 * java GetTransactionDetails <transaction_id>
 *
 */


public class GetTransactionDetails
{
    public static void main(String[] args) throws Exception
    {
        if (args.length < 1)
        {
                System.out.println("Usage: java GetTransactionDetails <TXN-ID>");
                return;
        }
     //
     GetTransactionDetails client = new GetTransactionDetails();
     client.testGetTransactionDetails(args[0]);
    }
   
   
    public GetTransactionDetails()
    {
    }
   
   
    public void testGetTransactionDetails(String txn_id) throws Exception
    {
        SimpleConfigFile cfg = new SimpleConfigFile("client_config.nvp");
String url = cfg.val("url");
        System.out.println("connecting to /""+url+"/": testing GetTransactionDetails(/""+txn_id+"/")");
        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;
        }

        _GetTransactionDetailsReq _req = new _GetTransactionDetailsReq();
        GetTransactionDetailsRequestType request = new GetTransactionDetailsRequestType();
        _req.setGetTransactionDetailsRequest(request);
        request.setVersion(cfg.val("getDetails_version"));
   
        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","8080");
            }
        }
 eBLBaseComponents.apis.ebay.TransactionId txnID = new eBLBaseComponents.apis.ebay.TransactionId(txn_id);
        request.setTransactionID(txnID);

  // 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 reuqest object
 printGetTxnDetailsReq(request); 

        // This actually does the transaction ...
        GetTransactionDetailsResponseType resp = null;
 try {
  resp = binding.getTransactionDetails(_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;
 }

        // Now we process the output.
 printGetTxnDetailsRes(resp);
    }

    void printGetTxnDetailsReq (GetTransactionDetailsRequestType req) {
        System.out.println();
        System.out.println("************  GetTransactionDetails Request ***********");
 System.out.println("transactionID:      " + req.getTransactionID().toString());
 System.out.println("Version:       " + req.getVersion().toString());
    }

   void printGetTxnDetailsRes (GetTransactionDetailsResponseType res) {

 System.out.println();
        System.out.println("************  GetTransactionDetails response ***********");
 if (res.getBuild() != null)
            System.out.println("build:      " + res.getBuild().toString());
 if (res.getVersion() != null)
            System.out.println("version:    " + res.getVersion().toString());
        if (res.getCorrelationID()!=null) {
     System.out.println("corr ID:    " + res.getCorrelationID().toString());
 }

        if (res.getTimestamp()!=null) {
     System.out.println("Timestamp:  " + res.getTimestamp().getTime());
 }

        System.out.println();
        System.out.println("Ack:        " + res.getAck().toString());

        eBLBaseComponents.apis.ebay.ErrorType err[] = res.getErrors();
        if (err != null) {
            for (int i=0; i<err.length; i++) {
         System.out.println();
         System.out.println("Error Code: " + err[i].getErrorCode());
         System.out.println("Short mssg: " + err[i].getShortMessage());
         System.out.println("Long messg: " + err[i].getLongMessage());
         System.out.println("Severity:   " + err[i].getSeverityCode());
            }
        }

        System.out.println();
        org.apache.axis.message.MessageElement msg[] = res.get_any();
        if (msg != null) {
            for (int i=0; i<msg.length; i++) {
         System.out.println();
         System.out.println("  Encoding: " + msg[i].getEncodingStyle());
         System.out.println("     QName: " + msg[i].getQName().toString());
         System.out.println("      Name: " + msg[i].getName());
         System.out.println("     Value: " + msg[i].getValue());
            }
        }

        System.out.println();
 /*
        org.apache.axis.description.TypeDesc typeDesc = res.getTypeDesc();
        org.apache.axis.description.FieldDesc f[] = typeDesc.getFields();
        if (f != null) {
            for (int i=0; i<f.length; i++) {
         System.out.println("field name: " + f[i].getFieldName());
            }
        }
        org.apache.axis.description.FieldDesc pmt = typeDesc.getFieldByName("paymentTransaction");
        if (pmt == null) {
            System.out.println(" * NO PAYMENT INFORMATION * ");
            return;
        }
        System.out.println("xml  name:  " + pmt.getXmlName());
        System.out.println("xml  type : " + pmt.getXmlType());
        System.out.println();
 */
        display_payment_info(res);
   }
   
    void display_payment_info(GetTransactionDetailsResponseType resp) {

 PrintResults display = new PrintResults();

        System.out.println();

        eBLBaseComponents.apis.ebay.PaymentTransactionType pt = resp.getPaymentTransactionDetails();
        if (pt == null) {
            System.out.println(" * no Payment Transaction Information * ");
            return;
        }

        eBLBaseComponents.apis.ebay.PaymentInfoType pi = pt.getPaymentInfo();
        if (pi == null) {
            System.out.println(" * no Payment Information * ");
        } else {
     System.out.println(" ************  Payment Info");
     display.printPaymentInfo(pi);
 }

        eBLBaseComponents.apis.ebay.PayerInfoType pr = pt.getPayerInfo();
        if (pr == null) {
            System.out.println(" * no Payer Information * ");
        } else {
     System.out.println(" ************  Payer Info");
     display.printPayerInfoType(pr);
 }

        eBLBaseComponents.apis.ebay.ReceiverInfoType ri = pt.getReceiverInfo();
        if (ri == null) {
            System.out.println(" * no Receiver Information * ");
        } else {
     System.out.println(" ************  Receiver Info");
     display.printReceiverInfo(ri);
 }

        eBLBaseComponents.apis.ebay.PaymentItemInfoType ii = pt.getPaymentItemInfo();
        if (ii == null) {
            System.out.println(" * no Payment Item Information * ");
        } else {
     System.out.println(" *************  Payment ItemInfo");
     display.printPaymentItemInfo(ii);
 }
    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章