0

I`m using PayPal.AdaptivePayments sdk for chained payment and refund process of chained payment.

Using following methods: for payment : pay() method for refund : refund() method as per sdk.

When try to refund with payKey then getting response with status: "NO_API_ACCESS_TO_RECEIVER"

Currently I`m sandbox account on development.

I have also followed paypal developer api/sdk docs but still getting same problem.

So please help me to refund process with status of "Refunded".

I have already review post related to this on stack-overflow but I didn`t proper solution in any post.

https://devtools-paypal.com/guide/ap_chained_payment?interactive=ON&env=sandbox

 private void Refund(HttpContext contextHttp)
    {
        NameValueCollection parameters = contextHttp.Request.Params;

        RefundRequest request = new RefundRequest(new RequestEnvelope("en_US"));

        // Set optional parameters
        if(parameters["receiverEmail"].Length > 0) 
        {
            //(Required) Amount to be paid to the receiver
            string[] amt = contextHttp.Request.Form.GetValues("receiverAmount");

            // Maximum length: 127 characters
            string[] receiverEmail = contextHttp.Request.Form.GetValues("receiverEmail");

            //Telephone country code 
            string[] phoneCountry = contextHttp.Request.Form.GetValues("phoneCountry");


            string[] phoneNumber = contextHttp.Request.Form.GetValues("phoneNumber");

            //Telephone extension
            string[] phoneExtn = contextHttp.Request.Form.GetValues("phoneExtn");


            string[] primaryReceiver = contextHttp.Request.Form.GetValues("primaryReceiver");

            string[] invoiceId = contextHttp.Request.Form.GetValues("invoiceId");

            string[] paymentType = contextHttp.Request.Form.GetValues("paymentType");
            //(Optional) The transaction subtype for the payment. 
            string[] paymentSubType = contextHttp.Request.Form.GetValues("paymentSubType");

            List<Receiver> receivers = new List<Receiver>();
            for(int i=0; i<amt.Length; i++) {
                Receiver r = new Receiver(Convert.ToDecimal(amt[i]));
                r.email = receiverEmail[i];
                r.primary = Convert.ToBoolean(primaryReceiver[i]);
                if(invoiceId[i] != string.Empty) {
                    r.invoiceId = invoiceId[i];
                }
                if(paymentType[i] != string.Empty) {
                    r.paymentType = paymentType[i];
                }
                if(paymentSubType[i] != string.Empty) {
                    r.paymentSubType = paymentSubType[i];
                }
                if(phoneCountry[i] != string.Empty && phoneNumber[i] != string.Empty) {
                    r.phone = new PhoneNumberType(phoneCountry[i], phoneNumber[i]);
                    if(phoneExtn[i] != string.Empty) {
                        r.phone.extension = phoneExtn[i];
                    }
                }
                receivers.Add(r);
            }
            request.receiverList = new ReceiverList(receivers);
        }

        if(parameters["currencyCode"] != string.Empty) {
            request.currencyCode = parameters["currencyCode"];
        }

        if(parameters["payKey"] != string.Empty) {
            request.payKey = parameters["payKey"];
        }

        if(parameters["transactionId"] != string.Empty) {
            request.transactionId = parameters["transactionId"];
        }

        if(parameters["trackingId"] != string.Empty) {
            request.trackingId = parameters["trackingId"];
        }            

        AdaptivePaymentsService service = null;
        RefundResponse response = null;
        try
        {
            Dictionary<string, string> configurationMap = Configuration.GetAcctAndConfig();
            service = new AdaptivePaymentsService(configurationMap);
            response = service.Refund(request);
        }
        catch (System.Exception e)
        {
            contextHttp.Response.Write(e.Message);
            return;
        }

        Dictionary<string, string> responseValues = new Dictionary<string, string>();

       // string redirectUrl = null;

        string redirectUrl = null;

        if (!(response.responseEnvelope.ack == AckCode.FAILURE) &&
            !(response.responseEnvelope.ack == AckCode.FAILUREWITHWARNING))
        {
            responseValues.Add("Currency code", response.currencyCode);
            int idx = 1;
            foreach (RefundInfo refund in response.refundInfoList.refundInfo)
            {
                //Receiver's email address.Maximum length: 127 characters
                responseValues.Add("Refund receiver " + idx, refund.receiver.email);
                // Amount to be refunded to the receiver.
                responseValues.Add("Refund amount " + idx, refund.receiver.amount.ToString());

                responseValues.Add("Refund status " + idx, refund.refundStatus);


                responseValues.Add("Acknowledgement", response.responseEnvelope.ack.ToString());
            }
        }
        Display(contextHttp, "Refund", responseValues, service.getLastRequest(), service.getLastResponse(), response.error, redirectUrl);
    }
Ram Khumana
  • 844
  • 6
  • 14

0 Answers0