Hardik4560
Hardik4560

Reputation: 3220

Paypal refund api gives error NO API ACCESS TO RECEIVER

I am using pre-approvals and delayed chained payment from adaptive payment api.

My test business account from which api is used is also the primary receiver account.

I get a paykey generated after using the preapproval to initiate the delayed payment. The money is received accurately in the primary receiver. My application now has a scenario where the money has to be refunded from primary receiver back to the purchaser. When tyring to execute this refund with the paykey and specifying the receiver and also settings the primary receiver flag, I receive an error NO_API_ACCESS_TO_RECEIVER.

This is blocking my app release and is a serious trouble. Could you please unblock me at earliest.

This is my code:

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;
        }

In the above code snippet the ACk code returned is success, but when I print the refund status of the RefundInfo object, it says NO_API_ACCESS_TO_RECEIVER. I have already given the permission to the api caller from the paypal panel of the primary account.

Is there something that is missing from my side? Please help me out!

Upvotes: 2

Views: 828

Answers (2)

Hardik4560
Hardik4560

Reputation: 3220

Got the answer myself. Sharing with you all

It was reading the paypal SDK client property file from Wrong location.

To avoid such kind of problems we should set the properties in the constructor of AdaptivePayments.

Below is the code for more illustration:

There is a session bean PropertyBean which has function getPayPalProperties() which reads all paypal properties from a property file.

Properties properties = propertyBeanLocal.getPayPalProperties();

AdaptivePayments adaptivePayments = new AdaptivePayments(properties);

And Instead of doing this

refundRequest.setRequestEnvelope(ClientInfoUtil.getMyAppRequestEnvelope());

do this.

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

Upvotes: 1

PP_MTS_Chad
PP_MTS_Chad

Reputation: 7319

If your just refunding from the Primary (yourself) back to the sender and you want to do a full refund, then you shouldn't need to specify any receivers. Otherwise I would need some type of PayKey or Correlation ID to look up the request on my side.

Upvotes: 1

Related Questions