1

I've set up the Paypal Payout SDK With Composer.

Paypal assured me that the Payouts-Feature is enabled for my account. I've created a new Live Rest-App and used the Client-ID and the Client-Secret in the PayPalClient Class:

<?php
namespace PaypalPayoutsSDK\Payouts;
use PaypalPayoutsSDK\Core\PayPalHttpClient;
use PaypalPayoutsSDK\Core\ProductionEnvironment;
class PayPalClient {
    public static function client() {
        return new PayPalHttpClient(self::environment());
    }
    public static function environment() {
        $clientId = getenv("CLIENT_ID") ?: "my-client-id";
        $clientSecret = getenv("CLIENT_SECRET") ?: "my-client-secret";
        return new ProductionEnvironment($clientId, $clientSecret);
    }
}
?>

Now I want to make a simple transaction. I've used the samples included with the PayPal Payout SDK an created a payout using the PayPalClient mentionned above:

<?php
require __DIR__ . '/vendor/autoload.php';
use PaypalPayoutsSDK\Payouts\PayPalClient;
use PaypalPayoutsSDK\Payouts\PayoutsPostRequest;
$request = new PayoutsPostRequest();
$body= json_decode(
            '{
                "sender_batch_header":
                {
                  "email_subject": "SDK payouts test txn"
                },
                "items": [
                {
                  "recipient_type": "EMAIL",
                  "receiver": "myname@gmail.com",
                  "note": "Your 4$ payout",
                  "sender_item_id": "Test_txn_12",
                  "amount":
                  {
                    "currency": "USD",
                    "value": "4.00"
                  }
                }]
              }',             
            true);
$request->body = $body;
$client = PayPalClient::client();
$response = $client->execute($request);
?>

However when I execute the file I get the following errors:

Fatal error: Uncaught PayPalHttp\HttpException: {"name":"AUTHORIZATION_ERROR","message":"Authorization error occurred.","debug_id":"d3c2fe720217b","information_link":"https://developer.paypal.com/docs/api/payments.payouts-batch/#errors","links":[]} in /hermes/bosnaweb27a/b1507/dom.mydomain/mydomain/payment/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpClient.php:215 Stack trace: #0 /hermes/bosnaweb27a/b1507/dom.mydomain/mydomain/payment/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpClient.php(100): PayPalHttp\HttpClient->parseResponse(Object(PayPalHttp\Curl)) #1 /hermes/bosnaweb27a/b1507/dom.mydomain/mydomain/payment/payuser.php(37): PayPalHttp\HttpClient->execute(Object(PaypalPayoutsSDK\Payouts\PayoutsPostRequest)) #2 {main} thrown in /hermes/bosnaweb27a/b1507/dom.mydomain/mydomain/payment/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpClient.php on line 215  

The error seems to occur with the HTTPClient. I've already provided the Technical Assistant of Paypal with the same information but he didn't seem to know anything.

What could be the problem here. I'm sure the Client-ID and the Client-Secret are correct, I've already tried to do it with a new REST-APP. Perhaps there's something wrong with my code? Or am I just missing something?

Miger
  • 1,175
  • 1
  • 12
  • 33
  • Maybe for sanity sake, try directly setting the clientId and clientSecret, instead of having it assign from a possible getenv result. `return new ProductionEnvironment('put-id-directly-here', 'put-secret-here');` Other than that, it looks like it should work. – IncredibleHat Jun 09 '20 at 13:59
  • this has no effect, I still get the same "AUTHORIZATION_ERROR" as before. – Miger Jun 09 '20 at 14:25
  • Bugger. Well this is a conundrum then, because all the code is 'working' so to speak, to get to the point where it attempts a connection, and then fails on authorization. So the only real items that can cause it are: A) you have the wrong credentials entered (but you have already checked that multiple times), or B) the account isnt setup for payouts (but paypal claims it is... or maybe they LIE!). Wish I had more to offer. Our payouts system is on the prior SDK, so the code is different, but it all hinges on clientId/secret too. – IncredibleHat Jun 09 '20 at 14:29
  • Are you using the rest app's Live ClientID and Secret, not sandbox? Is the permission for Payouts checked within that rest app? – Preston PHX Jun 09 '20 at 16:46
  • Apparently it was the verification (linking my bank account) that was missing. The tech support of paypal didn't seem to notice at first. – Miger Jun 12 '20 at 18:51

1 Answers1

2

Your PayPal account will need to be 'Verified' in order to send Payouts. Try adding and confirming a Bank account, or contact PayPal for other possibilities.

Preston PHX
  • 27,642
  • 4
  • 24
  • 44
  • I have to mark this as the correct answer. It was not apparent from PayPal's documentation that the "verification" juts meant to link my bank account. It was never mentioned like that. So if anyone has the same issue linking your bank account should solve the problem. – Miger Jun 12 '20 at 18:53