paypal masspay : Insufficient funds response

3.2k views Asked by At

I have created a Paypal mass pay application but it responds with an 'Insufficient funds' error.

Code is given below:

            <?php
            $environment = 'sandbox';   // or 'beta-sandbox' or 'live'

            function PPHttpPost($methodName_, $nvpStr_) {
                global $environment;


                $API_UserName = urlencode('myusername-facilitator_api1.gmail.com');
                $API_Password = urlencode('1363173069');
                $API_Signature = urlencode('AIocgW-6xeVUBXWE8pFoChIyO4ClAMlqzb9NjIHfm7tgCjquZayeYDUC');
                $API_Endpoint = "https://api-3t.paypal.com/nvp";
                if("sandbox" === $environment || "beta-sandbox" === $environment) {
                    $API_Endpoint = "https://api-3t.$environment.paypal.com/nvp";
                }
                $version = urlencode('51.0');

                // Set the curl parameters.
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
                curl_setopt($ch, CURLOPT_VERBOSE, 1);

                // Turn off the server and peer verification (TrustManager Concept).
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
                curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($ch, CURLOPT_POST, 1);

                // Set the API operation, version, and API signature in the request.
                $nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature$nvpStr_";
                //print_r($nvpreq);exit;
                // Set the request as a POST FIELD for curl.
                curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);

                // Get response from the server.
                $httpResponse = curl_exec($ch);

                if(!$httpResponse) {
                    exit("$methodName_ failed: ".curl_error($ch).'('.curl_errno($ch).')');
                }

                // Extract the response details.
                $httpResponseAr = explode("&", $httpResponse);

                $httpParsedResponseAr = array();
                foreach ($httpResponseAr as $i => $value) {
                    $tmpAr = explode("=", $value);
                    if(sizeof($tmpAr) > 1) {
                        $httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1];
                    }
                }

                if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) {
                    exit("Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint.");
                }

                return $httpParsedResponseAr;
            }

            // Set request-specific fields.
            $emailSubject =urlencode('example_email_subject');
            $receiverType = urlencode('EmailAddress');
            $currency = urlencode('USD');                           // or other currency ('GBP', 'EUR', 'JPY', 'CAD', 'AUD')

            // Add request-specific fields to the request string.
            $nvpStr="&EMAILSUBJECT=$emailSubject&RECEIVERTYPE=$receiverType&CURRENCYCODE=$currency";

            $receiversArray = array();

            for($i = 0; $i < 3; $i++) {
                $receiverData = array(  'receiverEmail' => "bhavin.radidya@gmailcom",
                                        'amount' => "10",
                                        'uniqueID' => "13",
                                        'note' => "test Payment");
                $receiversArray[$i] = $receiverData;
            }

            foreach($receiversArray as $i => $receiverData) {
                $receiverEmail = urlencode($receiverData['receiverEmail']);
                $amount = urlencode($receiverData['amount']);
                $uniqueID = urlencode($receiverData['uniqueID']);
                $note = urlencode($receiverData['note']);
                $nvpStr .= "&L_EMAIL$i=$receiverEmail&L_Amt$i=$amount&L_UNIQUEID$i=$uniqueID&L_NOTE$i=$note";
            }

            // Execute the API operation; see the PPHttpPost function above.
            $httpParsedResponseAr = PPHttpPost('MassPay', $nvpStr);

            if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) {
                exit('MassPay Completed Successfully: '.print_r($httpParsedResponseAr, true));
            } else  {
                exit('MassPay failed: ' . print_r($httpParsedResponseAr, true));
            }

I have configured all parameters properly, but it still returns this error response. Is there a settings I have to adjust on the PayPal account?

3

There are 3 answers

0
C. Ridley On

Another scenario that results in this issue, might be of help to somebody :

My sending account seems to only work with GBP for mass payments and I was sending in USD (must be the way it's set up). Funny because the same account can accept payment in USD using the REST API, which is why it took me a while to figure out.

1
Robert On

The account you're sending from (which is typically the same as the API caller) needs to have sufficient funds in balance in order to send a mass payment.

I see you're using the default 'facilitator' account; this one is typically only used for testing the REST API's.

Go ahead and create a test account via Applications > Sandbox accounts and give it a generous balance of $10k. That should sort it out.

1
Nirmalkumar On

I had the same issue as above. Here is how I solved the problem.

Step 1: Go the corresponding Sandbox account and check the funding tab for the account balance. (If you have 0 dollars, You can easily create a new user and allocate a sufficient amount as balance, say $10K)

Step 2: Switch the API credentials to the new user who has enough balance. Now make the API call again.

This API request also gave me insufficient funds because I added 10K SGD in my account and while making the API call I made 20USD transaction.

So check your currency and corresponding balance in that currency.