【问题标题】:Paypal SetExpressCheckout SoapPaypal SetExpressCheckout 肥皂
【发布时间】:2012-04-27 16:03:33
【问题描述】:

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

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:a7c9fe7283bd 生成了一个 EC 令牌。

提前致谢。

【问题讨论】:

    标签: java web-services paypal


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      如果您查看提到的 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,并且可以提供帮助。

      【讨论】:

        【解决方案3】:

        我刚刚遇到这个问题并找到了答案(这是针对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。

        加里·戴维斯

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-04-12
          • 2012-09-09
          • 1970-01-01
          • 1970-01-01
          • 2013-06-16
          • 1970-01-01
          • 2011-02-10
          • 2011-01-14
          相关资源
          最近更新 更多