2013-04-15 41 views
2

我正在使用預先批准和從適應性支付API延遲鏈接付款。貝寶退款API給錯誤沒有API訪問接收器

我使用api的測試業務帳戶也是主要的接收方帳戶。

使用預先批准啓動延遲付款後,我得到一個paykey。錢在主接收器中準確接收。我的應用程序現在有一種情況,必須將資金從主接收方退還給購買方。當使用paykey執行此退款並指定接收方並設置主接收方標誌時,我收到錯誤NO_API_ACCESS_TO_RECEIVER。

這是阻止我的應用程序發佈,是一個嚴重的麻煩。你能否儘早解鎖我。

這是我的代碼:

RefundRequest refundRequest = new RefundRequest(); 
    refundRequest.setPayKey(payKey); 
    refundRequest.setCurrencyCode(KeyConstants.CURRENCY_USD_CODE); 
    refundRequest.setRequestEnvelope(ClientInfoUtil.getMyAppRequestEnvelope()); 

    ReceiverList receiverList = new ReceiverList(); 
    Receiver receiver = new Receiver(); 
    receiver.setEmail(businessAccountPaypalEmail); 
    receiver.setPrimary(true); 

    double truncatedAmount = NumberUtil.getDoubleTruncate(amount, KeyConstants.TWO_DECIMAL_FORMAT); 
    BigDecimal trunBigDecimal = new BigDecimal(truncatedAmount); 
    receiver.setAmount(trunBigDecimal.setScale(2, RoundingMode.HALF_UP)); 

    receiverList.getReceiver().add(receiver); 

    refundRequest.setReceiverList(receiverList); 

    try { 
     AdaptivePayments adaptivePayments = new AdaptivePayments(); 
     RefundResponse refundResponse = adaptivePayments.refund(refundRequest); 
     ResponseEnvelope responseEnvelope = refundResponse.getResponseEnvelope(); 
     AckCode ackCode = responseEnvelope.getAck(); 
     if(ackCode == AckCode.SUCCESS || ackCode == AckCode.SUCCESS_WITH_WARNING){ 
      Logger.getLogger(PayPalSessionBean.class.getName()).log(Level.INFO, "Refund success for the pay key {0} and messsage {1}", 
        new Object[]{payKey}); 
      System.out.println("Ack code is " + ackCode); 
      RefundInfoList refundInfoList = refundResponse.getRefundInfoList(); 
      List<RefundInfo> refundInfos = refundInfoList.getRefundInfo(); 
      for (Iterator iterator = refundInfos.iterator(); iterator 
        .hasNext();) { 
       RefundInfo refundInfo = (RefundInfo) iterator.next(); 

       System.out.println(refundInfo.getReceiver().getEmail() + "\t" + refundInfo.getRefundTransactionStatus() + "\t" + 
         refundInfo.getRefundGrossAmount() + '\t' + refundInfo.getRefundStatus() + '\t'); 

       ErrorList errorList = refundInfo.getErrorList(); 
       List<ErrorData> errs = errorList.getError(); 
       for (Iterator iterator2 = errs.iterator(); iterator2 
         .hasNext();) { 
        ErrorData errorData = (ErrorData) iterator2.next(); 
        System.out.println(errorData.getMessage()); 
       } 
      } 
      return true; 
     } 

在上面的代碼片斷返回的ACK碼是成功的,但是當我打印RefundInfo對象的退款狀態,它說NO_API_ACCESS_TO_RECEIVER。 我已經從主賬戶的paypal面板授予了api調用者的權限。

有沒有從我身邊丟失的東西?請幫助我!

回答

1

自己得到答案。與大家分享

它正在從錯誤位置讀取paypal SDK客戶端屬性文件。

爲了避免這樣的問題,我們應該在AdaptivePayments的構造函數中設置屬性。

下面是更圖示的代碼:

有一個會話bean PropertyBean具有功能getPayPalProperties(),其讀取從屬性文件中的所有貝寶屬性。

Properties properties = propertyBeanLocal.getPayPalProperties(); 

AdaptivePayments adaptivePayments = new AdaptivePayments(properties); 

而不是做這個

refundRequest.setRequestEnvelope(ClientInfoUtil.getMyAppRequestEnvelope()); 

做到這一點和。

RequestEnvelope requestEnvelope = new RequestEnvelope(); 
requestEnvelope.setErrorLanguage("en_us"); 
refundRequest.setRequestEnvelope(requestEnvelope); 
1

如果您只是從小學(您自己)退還給寄件人並且想要全額退款,那麼您不需要指定任何收件人。否則,我需要某種類型的PayKey或Correlation ID來查找我的請求。