diff --git a/README.md b/README.md index c5731c5..aa6c9c9 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/Resources/Transactions.php b/src/Resources/Transactions.php index 08c73ad..fa49db8 100644 --- a/src/Resources/Transactions.php +++ b/src/Resources/Transactions.php @@ -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 ) { @@ -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 $account_ids + * @param array $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) + ); + } } diff --git a/tests/TransactionsTest.php b/tests/TransactionsTest.php index c8a8470..7f850dd 100644 --- a/tests/TransactionsTest.php +++ b/tests/TransactionsTest.php @@ -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); @@ -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); @@ -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); @@ -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); + } }