我正在使用自适应支付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代码是success,但是当我打印退款信息对象的退款状态时,它显示的是NO_API_ACCESS_TO_RECEIVER。我已经从主账户的paypal面板给api调用者权限了。
是不是我身边少了什么?请帮帮我!
如果你只是从Primary(你自己)退款给发送者,并且你想要全额退款,那么你不需要指定任何接收者。否则,我将需要某种类型的PayKey或Correlation ID来查找我这边的请求。
我自己知道答案了。与大家分享
从错误的位置读取paypal SDK客户端属性文件。
为了避免这类问题,我们应该在AdaptivePayments的构造函数中设置属性。
下面是更多说明的代码:
有一个会话bean PropertyBean,它有函数getPayPalProperties(),它从属性文件中读取所有paypal属性。
Properties properties = propertyBeanLocal.getPayPalProperties();
AdaptivePayments adaptivePayments = new AdaptivePayments(properties);
而不是这样做
refundRequest.setRequestEnvelope(ClientInfoUtil.getMyAppRequestEnvelope());
。
RequestEnvelope requestEnvelope = new RequestEnvelope();
requestEnvelope.setErrorLanguage("en_us");
refundRequest.setRequestEnvelope(requestEnvelope);