Skip to content

Commit

Permalink
Adding support for recurring transactions endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
brentscheffler committed Jul 7, 2022
1 parent 60a59c5 commit 6aa0476
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ Methods:
* `list(string $access_token, DateTime $start_date, DateTime $end_date, array $options = []): object`
* `refresh(string $access_token): object`
* `sync(string $access_token, ?string $cursor = null, ?int $count = null, array $options = []): object`
* `recurring(string $access_token, array $account_ids, array $options = []): object`

Example:
```php
Expand Down
27 changes: 26 additions & 1 deletion src/Resources/Transactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function sync(string $access_token, ?string $cursor = null, ?int $count =
{
$params = [
"access_token" => $access_token,
"options" => (object) $options,
"options" => (object) $options
];

if( $cursor ) {
Expand All @@ -88,4 +88,29 @@ public function sync(string $access_token, ?string $cursor = null, ?int $count =
$this->paramsWithClientCredentials($params)
);
}

/**
* Get all recurring transactions (deposit and debit.)
*
* @see https://plaid.com/docs/api/products/transactions/#transactionsrecurringget
*
* @param string $access_token
* @param array<string> $account_ids
* @param array<string,mixed> $options
* @return object
*/
public function recurring(string $access_token, array $account_ids, array $options = []): object
{
$params = [
"access_token" => $access_token,
"account_ids" => $account_ids,
"options" => (object) $options
];

return $this->sendRequest(
"post",
"transactions/recurring/get",
$this->paramsWithClientCredentials($params)
);
}
}
39 changes: 29 additions & 10 deletions tests/TransactionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public function test_refresh_transactions(): void
public function test_sync_transactions_minimal(): void
{
$response = $this->getPlaidClient()->transactions->sync(
"access_token"
);
"access_token"
);

$this->assertEquals("POST", $response->method);
$this->assertEquals("2020-09-14", $response->version);
Expand All @@ -63,9 +63,9 @@ public function test_sync_transactions_minimal(): void
public function test_sync_transactions_cursor_only(): void
{
$response = $this->getPlaidClient()->transactions->sync(
"access_token",
"last_cursor_123",
);
"access_token",
"last_cursor_123",
);

$this->assertEquals("POST", $response->method);
$this->assertEquals("2020-09-14", $response->version);
Expand All @@ -81,11 +81,11 @@ public function test_sync_transactions_cursor_only(): void
public function test_sync_transactions_all_params(): void
{
$response = $this->getPlaidClient()->transactions->sync(
"access_token",
"last_cursor_123",
100,
["include_personal_finance_category" => true],
);
"access_token",
"last_cursor_123",
100,
["include_personal_finance_category" => true],
);

$this->assertEquals("POST", $response->method);
$this->assertEquals("2020-09-14", $response->version);
Expand All @@ -98,4 +98,23 @@ public function test_sync_transactions_all_params(): void
$this->assertEquals(100, $response->params->count);
$this->assertEquals((object) ["include_personal_finance_category" => true], $response->params->options);
}

public function test_recurring_transactions(): void
{
$response = $this->getPlaidClient()->transactions->recurring(
"access_token",
["acct_123", "acct_456"],
["option1" => "value1"],
);

$this->assertEquals("POST", $response->method);
$this->assertEquals("2020-09-14", $response->version);
$this->assertEquals("application/json", $response->content);
$this->assertEquals("/transactions/recurring/get", $response->path);
$this->assertEquals("client_id", $response->params->client_id);
$this->assertEquals("secret", $response->params->secret);
$this->assertEquals("access_token", $response->params->access_token);
$this->assertEquals(["acct_123", "acct_456"], $response->params->account_ids);
$this->assertEquals((object) ["option1" => "value1"], $response->params->options);
}
}

0 comments on commit 6aa0476

Please sign in to comment.