PHP code example of paypal / paypal-payouts-sdk

1. Go to this page and download the library: Download paypal/paypal-payouts-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

paypal / paypal-payouts-sdk example snippets



use PaypalPayoutsSDK\Core\PayPalHttpClient;
use PaypalPayoutsSDK\Core\SandboxEnvironment;
// Creating an environment
$clientId = "<<PAYPAL-CLIENT-ID>>";
$clientSecret = "<<PAYPAL-CLIENT-SECRET>>";

$environment = new SandboxEnvironment($clientId, $clientSecret);
$client = new PayPalHttpClient($environment);

use PaypalPayoutsSDK\Payouts\PayoutsPostRequest;
$request = new PayoutsPostRequest();
$body= json_decode(
            '{
                "sender_batch_header":
                {
                  "email_subject": "SDK payouts test txn"
                },
                "items": [
                {
                  "recipient_type": "EMAIL",
                  "receiver": "[email protected]",
                  "note": "Your 1$ payout",
                  "sender_item_id": "Test_txn_12",
                  "amount":
                  {
                    "currency": "USD",
                    "value": "1.00"
                  }
                }]
              }',             
            true);
$request->body = $body;
$client = PayPalClient::client();
$response = $client->execute($request);
print "Status Code: {$response->statusCode}\n";
print "Status: {$response->result->batch_header->batch_status}\n";
print "Batch ID: {$response->result->batch_header->payout_batch_id}\n";
print "Links:\n";
foreach($response->result->links as $link)
 {
   print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n";
 }
echo json_encode($response->result, JSON_PRETTY_PRINT), "\n";
        

 $request = new PayoutsGetRequest($batchId);
 $response = $client->execute($request);
 echo json_encode($response->result, JSON_PRETTY_PRINT), "\n";

 try{
    $request = new PayoutsGetRequest(null);
    $response = $client->execute($request);
    echo json_encode($response->result, JSON_PRETTY_PRINT), "\n";
  } catch(HttpException $e){
    echo $e->getMessage()
    var_dump(json_decode($e->getMessage()));

  }