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

Add Ponto Connect resources #63

Merged
merged 51 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
be4519d
Make token requests work
Sep 13, 2024
3476a81
Add docs and tests for PontoConnect module
Sep 13, 2024
b4fd14e
Fix test env
Sep 13, 2024
d6476c7
Add Financial Institution resources
Sep 13, 2024
2a951f7
Fix financial institutions
Sep 13, 2024
e966f7c
Add account resources
Sep 16, 2024
2cb1909
Add documentation to Account.delete/2
Sep 16, 2024
2a60d12
Add synchronization resources
Sep 16, 2024
b9eb676
Fix token docs
Sep 16, 2024
addbdf8
Add transaction resources
Sep 16, 2024
67a04c7
Add Reauthorization Request resources
Sep 16, 2024
f66488b
Some cleanup
Sep 16, 2024
4e7848a
Add (bulk) payment resources
Sep 17, 2024
4bba77a
Add Payment Request resources
Sep 17, 2024
693397d
Update common docs
Sep 17, 2024
410da60
Cleanup
Sep 17, 2024
21c8814
Add Sandbox resources
Sep 17, 2024
30339b5
Add update to financial institution transaction
Sep 17, 2024
e204afa
Fix test api schema
Sep 18, 2024
233835d
Some more Cleanup
Sep 18, 2024
796b49d
Add Onboarding Details resources
Sep 18, 2024
85406d3
Add Payment Activation Request resources
Sep 18, 2024
f61411c
Add User Info resources
Sep 18, 2024
12e6f90
Add Usage resources
Sep 18, 2024
711d896
Add webhook resources
Sep 18, 2024
60c588c
Add Integration resources
Sep 18, 2024
07bd80a
Fix some params tests
Sep 18, 2024
6b0e21e
Add ponto resources to json deserializer
Sep 18, 2024
4c9775f
Move common_docs to module CommonDocs
Sep 18, 2024
0d1fb8d
Remove unused code
Sep 18, 2024
3320c5a
Remove PontoConnect module
Sep 18, 2024
227cfe6
Cleanup part 1
Sep 19, 2024
55fd10e
Cleanup part 2
Sep 19, 2024
d1e7748
Update onboarding details docs
Sep 19, 2024
dd993e2
Fix some docs
Sep 20, 2024
01f1137
Move token_argument_error_msg/2 to Exceptions module
Sep 20, 2024
3e7e30b
Add token struct as argument for Token.delete/1
Sep 24, 2024
dd23baf
Change delete attribute name to refresh_token for clarification
Sep 24, 2024
02e370f
Fix typo
Sep 24, 2024
4936402
Fix missing attribute token in delete
Sep 24, 2024
fddca6c
Fix test
Sep 24, 2024
23ef4a7
Only send necessary attributes for revoke token
Sep 24, 2024
faf8ea2
Fix FinancialInstitution.find_public/1
Sep 25, 2024
4b010bd
Fix a few more mistakes
Sep 27, 2024
bc4b062
Fix typos in webhooks
Sep 27, 2024
35413b5
Fix typos
Sep 30, 2024
af21674
Fix copy-paste error in key_mapping
Oct 1, 2024
525f596
Fix account key mappings
Oct 1, 2024
a2bd529
Fix typo
Oct 1, 2024
aa9ccbd
fix datatypes
Oct 1, 2024
3c0067f
Another key mapping
Oct 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
222 changes: 222 additions & 0 deletions lib/ibanity/api/ponto_connect/account.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
defmodule Ibanity.PontoConnect.Account do
@moduledoc """
[Account API wrapper](https://documentation.ibanity.com/ponto-connect/2/api#account)
"""

use Ibanity.Resource

alias Ibanity.PontoConnect

@api_schema_path ["ponto-connect", "accounts"]

defstruct [
:id,
:description,
:deprecated,
:product,
:reference,
:currency,
:subtype,
:available_balance,
:available_balance_changed_at,
:available_balance_reference_date,
:current_balance,
:current_balance_changed_at,
:current_balance_reference_date,
:holder_name,
:reference_type,
:authorization_expiration_expected_at,
:authorized_at,
:available_balance_variation_observed_at,
:current_balance_variation_observed_at,
:internal_reference,
:availability,
:latest_synchronization,
:synchronized_at
]

@doc """
[List accounts](https://documentation.ibanity.com/ponto-connect/2/api#list-accounts)

Takes a `Ibanity.PontoConnect.Token`, or a `Ibanity.Request` with set `:token` as argument.

## Examples

iex> Ibanity.PontoConnect.Account.list(token)
{:ok, %Ibanity.Collection{
items: [%Ibanity.PontoConnect.Account{}]
}}

iex> token |> Ibanity.Request.token() |> Ibanity.PontoConnect.Accounts.list()
{:ok, %Ibanity.Collection{
items: [%Ibanity.PontoConnect.Account{}]
}}

iex> invalid_token |> Ibanity.PontoConnect.Account.list()
{:error,
[
%{
"code" => "invalidAccessToken",
"detail" => "Your access token is invalid.",
"meta" => %{"requestId" => "00077F000001D3A87F0000011F4066E43AFD1900051"}
}
]}

"""
def list(%Request{token: token} = request_or_token)
when not is_nil(token) do
request_or_token
|> Request.id(:id, "")
|> Client.execute(:get, @api_schema_path, __MODULE__)
end

def list(%PontoConnect.Token{} = request_or_token) do
request_or_token
|> Request.token()
|> list()
end

def list(other) do
raise ArgumentError,
message: PontoConnect.Exceptions.token_argument_error_msg("Accounts", other)
end

@doc """
[Find Account by id](https://documentation.ibanity.com/ponto-connect/2/api#get-account)

Takes a `Ibanity.PontoConnect.Token`, or a `Ibanity.Request` with set `:token` as first argument, and a Account
ID as second argument.

## Examples

With token

iex> Ibanity.PontoConnect.Account.find(token, "953934eb-229a-4fd2-8675-07794078cc7d")
{:ok, %Ibanity.PontoConnect.Account{id: "953934eb-229a-4fd2-8675-07794078cc7d"}}

With request

iex> token
...> |> Ibanity.Request.token()
...> |> Ibanity.Request.application(:my_application)
...> |> Ibanity.PontoConnect.Account.find("953934eb-229a-4fd2-8675-07794078cc7d")
{:ok, %Ibanity.PontoConnect.Account{id: "953934eb-229a-4fd2-8675-07794078cc7d"}}

Error

iex> Ibanity.PontoConnect.Account.find(token, "does-not-exist")
{:error,
[
%{
"code" => "resourceNotFound",
"detail" => "The requested resource was not found.",
"meta" => %{
"requestId" => "00077F00000184847F0000011F4066E44223327005A",
"resource" => "account"
}
}
]}
"""
def find(%Request{token: token} = request_or_token, id)
when not is_nil(token) do
request_or_token
|> Request.id(id)
|> Client.execute(:get, @api_schema_path, __MODULE__)
end

def find(%PontoConnect.Token{} = request_or_token, id) do
request_or_token
|> Request.token()
|> find(id)
end

def find(other, _id) do
raise ArgumentError,
message: PontoConnect.Exceptions.token_argument_error_msg("Account", other)
end

@doc """
[Revoke Account by id](https://documentation.ibanity.com/ponto-connect/2/api#revoke-account)

## Examples

With token

iex> Ibanity.PontoConnect.Account.delete(token, "953934eb-229a-4fd2-8675-07794078cc7d")
{:ok, %Ibanity.PontoConnect.Account{id: "953934eb-229a-4fd2-8675-07794078cc7d"}}

With request

iex> token
...> |> Ibanity.Request.token()
...> |> Ibanity.Request.application(:my_application)
...> |> Ibanity.PontoConnect.Account.delete("953934eb-229a-4fd2-8675-07794078cc7d")
{:ok, %Ibanity.PontoConnect.Account{id: "953934eb-229a-4fd2-8675-07794078cc7d"}}

Error

iex> Ibanity.PontoConnect.Account.delete(token, "does-not-exist")
{:error,
[
%{
"code" => "resourceNotFound",
"detail" => "The requested resource was not found.",
"meta" => %{
"requestId" => "00077F00000184847F0000011F4066E44223327005A",
"resource" => "account"
}
}
]}
"""
def delete(%Request{token: token} = request_or_token, id)
when not is_nil(token) do
formatted_ids = PontoConnect.RequestUtils.format_ids(%{id: id})

request_or_token
|> Request.ids(formatted_ids)
|> Client.execute(:delete, @api_schema_path, __MODULE__)
end

def delete(%PontoConnect.Token{} = request_or_token, id) do
request_or_token
|> Request.token()
|> delete(id)
end

def delete(other, _id) do
raise ArgumentError,
message: PontoConnect.Exceptions.token_argument_error_msg("Account", other)
end

@doc false
def key_mapping do
[
id: {~w(id), :string},
description: {~w(attributes description), :string},
deprecated: {~w(attributes deprecated), :boolean},
product: {~w(attributes product), :string},
reference: {~w(attributes reference), :string},
currency: {~w(attributes currency), :string},
subtype: {~w(attributes subtype), :string},
available_balance: {~w(attributes availableBalance), :number},
available_balance_changed_at: {~w(attributes availableBalanceChangedAt), :datetime},
available_balance_reference_date: {~w(attributes availableBalanceReferenceDate), :datetime},
current_balance: {~w(attributes currentBalance), :number},
current_balance_changed_at: {~w(attributes currentBalanceChangedAt), :datetime},
current_balance_reference_date: {~w(attributes currentBalanceReferenceDate), :datetime},
holder_name: {~w(attributes holderName), :string},
reference_type: {~w(attributes referenceType), :string},
authorization_expiration_expected_at:
{~w(attributes authorizationExpirationExpectedAt), :datetime},
authorized_at: {~w(attributes authorizedAt), :datetime},
available_balance_variation_observed_at:
{~w(attributes availableBalanceVariationObservedAt), :datetime},
current_balance_variation_observed_at:
{~w(attributes currentBalanceVariationObservedAt), :datetime},
internal_reference: {~w(attributes internalReference), :string},
avilability: {~w(meta availability), :string},
latest_synchronization: {~w(meta latestSynchronization), :map},
synchronized_at: {~w(meta synchronizedAt), :datetime}
]
end
end
Loading
Loading