Paypal SetExpressCheckout Soap

时间:2012-04-16 10:10:00

标签: java web-services paypal

当我尝试setExpressCheckout时,我得到ack =成功但没有令牌返回。

paypal api的版本是87.0 这里是wsdl链接:https://www.sandbox.paypal.com/wsdl/PayPalSvc.wsdl

这里命令我在axis2-1.6.1中使用来生成java代码

-uri https://www.sandbox.paypal.com/wsdl/PayPalSvc.wsd -p com.paypal.soap 

这里是使用axis2 https://docs.google.com/open?id=0B97cB4uxjmztbGgxRER6VjBWcWc

生成的java代码的链接

这里是SetExpressCheckout的代码

    PaymentDetailsType paymentDetails = new PaymentDetailsType();
    BasicAmountType orderTotal = new BasicAmountType();
    orderTotal.setCurrencyID(CurrencyCodeType.USD);
    orderTotal.setString("10.00");
    paymentDetails.setOrderTotal(orderTotal);
    paymentDetails.setPaymentAction(PaymentActionCodeType.Sale);

    SetExpressCheckoutRequestDetailsType requestDetailsType = new SetExpressCheckoutRequestDetailsType();
    requestDetailsType.setCancelURL(buyer.getCancelUrl());
    requestDetailsType.setReturnURL(buyer.getReturnUrl());
    requestDetailsType.setPaymentDetails(new PaymentDetailsType[]{paymentDetails});

    SetExpressCheckoutRequestType requestType = new SetExpressCheckoutRequestType();
    requestType.setVersion("87.0");
    requestType.setSetExpressCheckoutRequestDetails(requestDetailsType);

    SetExpressCheckoutReq req = new SetExpressCheckoutReq();
    req.setSetExpressCheckoutRequest(requestType);

    RequesterCredentials requesterCredentials = new RequesterCredentials();
    CustomSecurityHeaderType customSecurityHeaderType = new CustomSecurityHeaderType();

    UserIdPasswordType userIdPasswordType = new UserIdPasswordType();
    userIdPasswordType.setUsername("<username>");
    userIdPasswordType.setPassword("<pass>");
    userIdPasswordType.setSignature("<signature>");
    customSecurityHeaderType.setCredentials(userIdPasswordType);
    requesterCredentials.setRequesterCredentials(customSecurityHeaderType);

    String endPoint = null;
    endPoint = "https://api-3t.sandbox.paypal.com/2.0/";  //sandbox API Signature   
    PayPalAPIInterfaceServiceStub stub = new PayPalAPIInterfaceServiceStub(endPoint);
    stub._getServiceClient().getOptions().setProperty(HTTPConstants.CHUNKED, false);
    SetExpressCheckoutResponse setExpressCheckout = stub.setExpressCheckout(req, requesterCredentials);

    SetExpressCheckoutResponseType checkoutResponse = setExpressCheckout.getSetExpressCheckoutResponse();
    Calendar timestamp = checkoutResponse.getTimestamp();
    String strdate = null;
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
    if (timestamp != null) {
        strdate = sdf.format(timestamp.getTime());
    }
    System.out.println("Date:" + strdate);
    System.out.println("CorrelationID:" + checkoutResponse.getCorrelationID());
    System.out.println("ack :" + checkoutResponse.getAck());
    if (checkoutResponse.getErrors() != null && checkoutResponse.getErrors().length > 0) {
        PayPalAPIInterfaceServiceStub.ErrorType[] errors = checkoutResponse.getErrors();
        for (int i = 0; i < errors.length; i++) {
            System.out.println(errors[i].getErrorCode());
            System.out.println(errors[i].getLongMessage());

        }
    }
    System.out.println("token:" + checkoutResponse.getToken());

这是我得到的结果

Date:17/04/2012 12:33:38
CorrelationID:a7c9fe7283bd
ack :Success
token:null

我如何获得成功但令牌为空? paypal的联系人说已经为CorrelationID生成了一个EC令牌:a7c9fe7283bd。

提前感谢。

3 个答案:

答案 0 :(得分:1)

我必须使用setExpressCheckoutResponse.getExtraElement()。getText()来获取令牌。为什么setExpressCheckoutResponse.getToken()返回null?

答案 1 :(得分:0)

如果您查看提到的wsdl文件,在开始时您会注意到以下内容:

<wsdl:definitions
     ns:version="89.0"
     xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
     xmlns:xs="http://www.w3.org/2001/XMLSchema"
     xmlns="http://schemas.xmlsoap.org/wsdl/" 
     ... >

这意味着应该使用的API版本是89.0 - 不记得在PayPal API文档中指定的位置,但这肯定是在那里提到的。

如果您仍然遇到此问题,请告诉我,因为我最近设法使用Java中的SOAP设置了PayPal Express Checkout并且可以提供帮助。

答案 2 :(得分:0)

我刚遇到这个问题并找到答案(这是针对C#,我不确定它是否适用于Java):

https://www.x.com/developers/paypal/forums/soap/paypal-api-aa-and-net-wcf-undeserialized-fields

查看生成的Web服务代码(Reference.cs)并找到AbstractResponseType。最后一个属性是Any()。更改属性以匹配此属性(忽略属性):

    [System.Xml.Serialization.XmlIgnoreAttribute()]
    public System.Xml.XmlElement Any {
        get {
            return this.anyField;
        }
        set {
            this.anyField = value;
        }
    }

在此之后,重新编译并再次测试,您现在应该正确接收Token属性。

如果您重新生成Web服务代码,此更改当然会被替换,您将不得不重新执行此操作,除非PayPal修复此问题。顺便说一下,我的WSDL版本号目前是98.0。

加里戴维斯