2

I want to use paypal as a payment process in my application.

At paypal they have shown many ways as using REST API, classic api, and also using SOAP API.

I am trying to use SOAP client by following way.

1.I am trying to create a SOAP web service client using paypal's provided wsdl file. But it's giving me error while creating client as ' unable to retieve that url',though it creates client files.

2.Created object for proxyClass, as proxy class contains all required methods like getAuthDetails,setExpressCheckout,setEndPoint etc.

3.So these method contains parameters like DetailLevelCodeType[]detailLevel,MessageElement[]_any. so what will be the value for it ?

4.As per my understanding if I am performing any operation on payapal, it should ask me first authentication parameters like username,secret, token, password of my account. When it comes to paypal using rest api, I am aware about getting access token by providing user credentials.

So in soap web service client how to get that first? I didin't get any method available here for that. 

But I have got one way to perform authorization from this link. security credentials .

So I followed these steps, now I have my username,password.

In next topic they are explaining , your SOAP client must set the Username, Password elements to pass an API username/password combination in the SOAP request header.

So I am trying in this way to add username,password in request header reference.

This process includes marshalling.

//packages used so far

import javax.xml.ws.Binding;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.handler.Handler;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.Marshaller;
import javax.xml.rpc.ServiceException;
import javax.xml.soap.SOAPHeader;




    public static void main(String[] args) {
        // TODO Auto-generated method stub


        PayPalAPIAAInterfaceProxy proxy=new PayPalAPIAAInterfaceProxy();

    //  proxy.setEndpoint("");

        // following class is generated by wsdl2java utility Service class
        final PayPalAPIInterfaceService payPalService = new PayPalAPIInterfaceServiceLocator();
        PayPalAPIAAInterface expressCheckoutPort;
        try {
            expressCheckoutPort = payPalService.getPayPalAPIAA();
            final Binding binding = ((BindingProvider) expressCheckoutPort).getBinding();
            List<Handler> handlersList = new ArrayList<Handler>();

            // now, adding instance of Handler to handlersList which should do our job:
            // creating header instance
            final CustomSecurityHeaderType headerObj = new CustomSecurityHeaderType();
            final UserIdPasswordType credentials = new UserIdPasswordType();
            credentials.setUsername("username");
            credentials.setPassword("password");
            credentials.setSignature("signature");
            headerObj.setCredentials(credentials);


            // bookmark #1 - please read explanation after code
            final ObjectFactory objectFactory = new ObjectFactory();
            // creating JAXBElement from headerObj
            final JAXBElement<CustomSecurityHeaderType> requesterCredentials = objectFactory.createRequesterCredentials(headerObj);

            handlersList.add(new SOAPHandler<SOAPMessageContext>() {
                @Override
                public boolean handleMessage(final SOAPMessageContext context) {        
                    try {
                        // checking whether handled message is outbound one as per Martin Strauss answer
                        final Boolean outbound = (Boolean) context.get("javax.xml.ws.handler.message.outbound");
                        if (outbound != null && outbound) {
                            // obtaining marshaller which should marshal instance to xml
                            final Marshaller marshaller = JAXBContext.newInstance(CustomSecurityHeaderType.class).createMarshaller();
                            // adding header because otherwise it's null
                            final SOAPHeader soapHeader = context.getMessage().getSOAPPart().getEnvelope().addHeader();
                            // marshalling instance (appending) to SOAP header's xml node
                            marshaller.marshal(requesterCredentials, soapHeader);
                        }
                    } catch (final Exception e) {
                        throw new RuntimeException(e);
                    }
                    return true;
                }

                // ... default implementations of other methods go here

            });

            // as per Jean-Bernard Pellerin's comment setting handlerChain list here, after all handlers were added to list
            binding.setHandlerChain(handlersList);


        } catch (ServiceException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }




    }

But I observed a file is missing named ObjectFactory .

I have included Merchant api sdk's jar file also. And in my web service client this file is not present.

So can anybody guide me in this context that why file is not getting created when creating client from wsdl file ?

I have also tried to create web service client using wsdl to java plugin, but it is giving me error as

wsdlexception faultcode other_error ,it's also saying FileNotFoundException

, unable to find https://www.paypalobjects.com/wsdl/PayPalSvc.wsdl/eBLBaseComponents.xsd

Community
  • 1
  • 1
Java
  • 2,451
  • 10
  • 48
  • 85
  • Has anybody used paypal with only using web service SOAP client? As I observed I am getting this error because of jar files conflicts. Number of files like `SetExpressCheckoutResponseType`,`SetExpressCheckoutRequestDetailsType` and many more exist in `payment-base.jar` and in client created using soap (from wsdl). – Java Jan 20 '14 at 15:47
  • So can anybody used paypal using only SOAP web service client i.e generated from provided wsdl files by paypal.? – Java Jan 20 '14 at 15:54
  • Is there anyone who has worked on paypal integration using soap client? – Java Jan 27 '14 at 14:34
  • My suggestion is best way is through REST API Try this Link: [https://devtools-paypal.com/guide/pay_paypal](https://devtools-paypal.com/guide/pay_paypal) Hope this Helps you – Raj Jan 17 '14 at 12:20
  • I have tried with this REST API, the sample code given here works, that's good, but I want to perform one time payment process and then concurrent billing(I think it will be done using billing agreement) . So does rest api contains all these supported methods? – Java Jan 17 '14 at 13:12
  • Yes absolutely...!! it contains almost all required supported methods @Java – Raj Jan 17 '14 at 16:03

2 Answers2

1

Disclaimer: though I managed to use PayPal web services API around 2 years ago, it was kind of cumbersome to do, so I'll advise you to use REST API, since it looks like PayPal fails to keep web service API consistent.

However, I'll try to give you hints on how to use web service API from PayPal: It seems you are doing everything right, the problem is in PayPalSvc.wsdl file, because it references eBLBaseComponents.xsd file which should be located next to PayPalSvc.wsdl file. If you navigate to url in browser

https://www.paypalobjects.com/wsdl/eBLBaseComponents.xsd

you'll see that that file exists at that location.

Same goes for CoreComponentTypes.xsd and EnhancedDataTypes.xsd files which are also referenced by PayPalSvc.wsdl file.

Now, I quickly tried to use Apache CXFs wsdl2java utility to generate client classes and it gave me the same error you have. I don't know why those utilities are expecting those xsd files to be located in https://www.paypalobjects.com/wsdl/PayPalSvc.wsdl/ location.

So, what you can do to bypass this problem is to:

  1. Download PayPalSvc.wsdl, CoreComponentTypes.xsd, eBLBaseComponents.xsd and EnhancedDataTypes.xsd files to your computer
  2. Put them all into single folder on your computer
  3. Run the utility again pointing to the local PayPalSvc.wsdl file
  4. If file not found error is shown, try to find that file on the web, download it and try again
  5. In case of any problems - add comments, I (or somebody else) will try to help

Hope this helps...

Yuriy Nakonechnyy
  • 3,742
  • 4
  • 29
  • 41
  • thanks for reply.I have downloded wsdl and xsd to my local.Now I am trying to create web service client using axis generator plugin, but it's giving me error as `specified WSDL is invalid!, Please select a validated *.wsdl/*.xml file on previous page`. I am providing correct path for wsdl from local . – Java Jan 22 '14 at 04:47
  • Try `Apache CXF wsdl2java` utility command: `wsdl2java -client /PayPalSvc.wdsl` – Yuriy Nakonechnyy Jan 22 '14 at 10:56
  • I tried with `Apache CXF wsdl2java` also , but still giving error for xsd. – Java Jan 23 '14 at 08:40
  • I want to perform concurrent billing process on paypal, so I am trying to use soap client sdk, but I am getting `unable to create soap connection `I am following this blog.`http://www.integratingstuff.com/2010/07/17/paypal-express-checkout-with-java/` – Java Jan 23 '14 at 12:02
  • Could you please post full stack trace of exception? I didn't work with PayPal soap client SDK – Yuriy Nakonechnyy Jan 23 '14 at 15:53
  • please find full stack trace of exception here `http://stackoverflow.com/questions/21285263/unable-to-establish-soap-connection-while-using-paypal-api` – Java Jan 23 '14 at 16:23
0

PayPal provides libs for Java which makes the integration a lot easier for you.

http://repo1.maven.org/maven2/com/paypal/sdk/

I used merchantsdk and paypal-core for my express-checkout integration.

Till
  • 994
  • 5
  • 18