TomorrowIdeas/plaid-sdk-php

sync requires handling the cursor

Opened this issue · 1 comments

Is there any sample code to handle the initial sync or updates with enough to require handling the updated cursor?

I found some code example here:
#70

But it doesn't seem to work or uses things I'm unsure how to load?

Here's some of my code.

Application code to sync the transactions and update the model w/ latest cursor

$transactionResponse = $this->plaid->syncTransactions($accessToken, $cursor);

PlaidTransaction::create([
    'plaid_access_token_id' => $accessTokenId,
    'raw' => $transactionResponse,
]);

$newTransactions = property_exists($transactionResponse, 'added') ? $transactionResponse->added : [];
$updatedTransactions = property_exists($transactionResponse, 'updated') ? $transactionResponse->updated : [];
$removedTransactions = property_exists($transactionResponse, 'removed') ? $transactionResponse->removed : [];

Log::debug('PlaidManager::syncTransactions() - Syncing transactions', [
    'accessTokenId' => $accessTokenId,
    'userId' => $userId,
    'newTransactions' => $newTransactions,
    'updatedTransactions' => $updatedTransactions,
    'removedTransactions' => $removedTransactions,
    'hasMore' => $transactionResponse->has_more,
]);

if ($transactionResponse->has_more) {
    $plaidAccessToken->cursor = $transactionResponse->item->next_cursor;
}

Wrapper around this SDK

public function syncTransactions(
    string $accessToken, 
    ?string $cursor = null,
    int $count = 500,
) {
        $options = [
            'include_original_description' => true,
        ];

        return $this->client->transactions->sync(
            $accessToken, 
            $cursor, 
            $count, 
            $options
        );
}