Sample code for 30+ languages & platforms
PHP Requires Chilkat v11.0.0+

PayPal: Find disputes awaiting a seller response

See more PayPal Examples

Scan cases updated in the past 30 days and page through the results. Show each case waiting on the seller and its response deadline when PayPal includes one in the summary.

PayPal documentation

Chilkat PHP Downloads

PHP
<?php

use Chilkat2\DateTime;
use Chilkat2\Http;
use Chilkat2\HttpResponse;
use Chilkat2\JsonObject;

// See Unlock Chilkat before making requests.
// For the merchant's internal backoffice application. Load the sandbox token
// from the merchant's credential store. Keep it out of publicly distributed apps.
// See Get a PayPal access token.
$http = new Http();
$http->AuthToken = 'SANDBOX_ACCESS_TOKEN';
$resp = new HttpResponse();
$since = new DateTime();
$since->SetFromCurrentSystemTime();
$since->AddDays(-30);
$query = new JsonObject();
$query->UpdateString('update_time_after', $since->GetAsTimestamp(false));
$query->UpdateInt('page_size', 50);
$page = 1;
$more = true;
while ($more) {
    $query->UpdateInt('page', $page);
    try {
        $http->HttpParams('GET', 'https://api-m.sandbox.paypal.com/v1/customer/disputes', $query, $resp);
    } catch (\Chilkat2\Exception $e) {
        echo 'No HTTP response: ', $e->getMessage(), "\n";
        exit;
    }

    if (($resp->StatusCode < 200) || ($resp->StatusCode >= 300)) {
        $errorInfo = new JsonObject();
        $errorInfo->Load($resp->BodyStr);
        echo 'HTTP ', $resp->StatusCode, ' ', $errorInfo->StringOf('name'), ' ', $errorInfo->StringOf('details[0].issue'), "\n";
        echo 'PayPal debug ID: ', $errorInfo->StringOf('debug_id'), "\n";
        exit;
    }

    $result = new JsonObject();
    try {
        $result->Load($resp->BodyStr);
    } catch (\Chilkat2\Exception $e) {
        echo 'Expected a JSON response; HTTP ', $resp->StatusCode, "\n";
        exit;
    }

    $i = 0;
    while ($i < $result->SizeOfArray('items')) {
        $result->I = $i;
        if ($result->StringOfEquals('items[i].status', 'WAITING_FOR_SELLER_RESPONSE', true)) {
            echo $result->StringOf('items[i].dispute_id'), '  ', $result->StringOf('items[i].reason'), "\n";
            if ($result->HasMember('items[i].seller_response_due_date')) {
                echo 'Respond by ', $result->StringOf('items[i].seller_response_due_date'), "\n";
            }
        }

        $i = $i + 1;
    }

    $hasNext = false;
    $linkIndex = 0;
    while ($linkIndex < $result->SizeOfArray('links')) {
        $result->I = $linkIndex;
        if ($result->StringOfEquals('links[i].rel', 'next', true)) {
            $hasNext = true;
        }

        $linkIndex = $linkIndex + 1;
    }

    $more = $hasNext;
    $page = $page + 1;
}