Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync requires handling the cursor #84

Open
risner opened this issue Feb 1, 2024 · 1 comment
Open

sync requires handling the cursor #84

risner opened this issue Feb 1, 2024 · 1 comment

Comments

@risner
Copy link

risner commented Feb 1, 2024

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?

@kgdiem
Copy link

kgdiem commented Feb 1, 2024

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
        );
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants