summaryrefslogtreecommitdiff
path: root/libeufin/api-nexus.rst
blob: d58b43bdb0de30009f41504fba862afe28ab67e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
Nexus API
###########

.. contents:: Table of Contents

HTTP API
========

Authentication
--------------

Currently every request made to nexus must be authenticated using the *HTTP
basic auth* mechanism.

Other authentication mechanisms (e.g. OpenID Connect) might
be supported in the future.

User Management
---------------

.. http:get:: {nexusBase}/user

  Get information about the current user (based on the authentication information
  in this request).

  **Response:**

  .. ts:def:: GetUserResponse

     interface UserResponse {

       // User name
       username: string;

       // Is it a superuser?
       superuser: boolean;
     }

.. http:post:: {nexusBase}/users

  Create a new user.  Only a superuser can call this API.

  **Request:**

  The body is a `User` object.

  **Response:**

  :status 409 Conflict: Username is not available.

  **Details:**

  .. ts:def:: User

     interface User {

       // User name
       username: string;

       // Initial password
       password: string;
     }


.. http:get:: {nexusBase}/users

  Return list of users.

Bank Accounts
-------------

The LibEuFin maintains a copy of the bank account transaction history and balance information,
manages payment initiations of the account and tracks the of payment initiations.

.. http:get:: {nexusBase}/bank-accounts
  
  **Response:**

  A list of `BankAccount` objects
  that belong to the requester.

  .. ts:def:: BankAccount
     
     interface BankAccount {
       // mnemonic name identifying this bank account.
       nexusBankAccountId: string; 
       // IBAN
       iban: string;
       // BIC
       bic: string;
       // Legal subject owning the account.
       ownerName: string;
     }

.. http:post:: {nexusBase}/bank-accounts/{acctid}/payment-initiations/{pmtid}/submit

  Ask nexus to submit one prepare payment at the bank.

  :status 404 Not Found: the unique identifier **or**
    the bank connection could not be found in the system


.. http:get:: {nexus}/bank-accounts/{my-acct}/payment-initiations/{uuid}
   
   Ask the status of payment ``$uuid``.

   **Response:**

   .. ts:def:: PaymentStatus

      interface PaymentStatus {

        // Payment unique identifier
        uuid: string;

        // True for submitted payments
        submitted: boolean;

        // Creditor IBAN
        creditorIban: string;

        // Creditor BIC
        creditorBic: string;

        // Creditor legal name
        creditorName: string;

        // Amount
        amount: string;

        // Subject
        subject: string;

        // Date of submission (in dashed form YYYY-MM-DD)
        submissionDate: string;

        // Date of preparation (in dashed form YYYY-MM-DD)
        preparationDate: string;
      }

.. http:get:: {nexusBase}/bank-accounts/{my-acct}/payment-initiations

  Ask nexus the list of initiated payments.  At this stage of the API,
  **all** is returned: submitted and non submitted payments.

  **Response**

  .. ts:def:: InitiatedPayments

     interface InitiatedPayments {
       
       // list of all the initiated payments' UID.
       initiatedPayments: PaymentStatus[];
     }


.. http:post:: {nexusBase}/bank-accounts/{my-acct}/payment-initiations
  
  Ask nexus to prepare instructions for a new payment.
  Note that ``my-acct`` is the bank account that will be
  **debited** after this operation.

  **Request:**

  .. ts:def:: PreparedPaymentRequest

     interface PreparedPaymentRequest {
       // IBAN that will receive the payment.
       iban: string;
       // BIC hosting the IBAN.
       bic: string;
       // Legal subject that will receive the payment.
       name: string;
       // payment subject. 
       subject: string;
       // amount, in the format CURRENCY:XX.YY
       amount: string
     }

  **Response:**

  .. ts:def:: PreparedPaymentResponse
     
     interface PreparedPaymentResponse {

       // Opaque identifier to be communicated when
       // the user wants to submit the payment to the
       // bank.
       uuid: string;
     }

.. http:post:: {nexusBase}/bank-accounts/{acctid}/fetch-transactions

  Nexus will download bank transactions using the given connection.

  **Request:**

  .. ts:def:: CollectedTransaction

     interface CollectedTransaction {
       // Optional field to specify the bank connection to
       // use for such operation.
       bankConnection?: string;
       // dashed date (YYYY-MM-DD) of the earliest payment
       // in the result. Optional, defaults to "earliest
       // possible" date.
       start: string;
       // dashed date (YYYY-MM-DD) of the earliest payment
       // in the result. Optional, defaults to "latest
       // possible" date.
       end: string;
     }

.. http:get:: {nexusBase}/bank-accounts/{acctid}/transactions

  Shows which transactions are stored locally at nexus.

  **Query parameters:**

  * **start** start (dashed YYYY-MM-DD) date of desired payments.
    Optional, defaults to "earliest possible" date
  * **end** end (dashed YYYY-MM-DD) date of desired payments.
    Optional, defaults to "earliest possible" date


  **Response:** A list of `Transaction` objects.

  .. ts:def:: Transaction

     interface Transaction {
       // local bank account involved in the transaction.
       account: string;

       // counterpart IBAN
       counterpartIban: string;

       // counterpart BIC
       counterpartBic: string;

       // counterpart holder name
       counterpartName: string;

       // amount, in the format [-]CURRENCY:XX.YY,
       // where the minus sign as prefix indicates
       // a debit for the user's bank account.
       amount: string;

       // Dashed date YYYY-MM(01-12)-DD(01-31) of the transaction.
       date: string;

       // Payment subject.
       subject: string;
     }


Bank Connections
----------------

Bank connections connect the local LibEuFin bank account
to the real bank.

.. http:post:: <nexus>/bank-connections
  
  Activate a new bank connection for the requesting user.

  **Request:**

  .. ts:def:: BankConnectionRestoreRequest

     interface BankConnectionRestoreRequest {

       source: "new" | "backup";

       name: string;

       // Restore a previous connection.  Take precedence
       // over the 'new' field.
       backup?: BankConnectionBackup;

       passphrase?: string;
       
       // Data to create a fresh bank connection without
       // restoring any backup.
       data?: BankConnectionNew;
     }


  .. ts:def:: BankConnectionNew

     interface BankConnectionNew {

       // This type is strictly dependent on
       // the connection being created.  For Ebics,
       // it will contain the required fields (as strings):
       // 'ebicsURL', 'userID', 'partnerID', 'hostID', and
       // the optional 'systemID'.
  
       // Other connection types, like 'local' (used for testing
       // purposes skipping any interaction with the bank service)
       // and 'fints' are all work in progress!

     }


  .. ts:def:: BankConnectionBackup
     
     interface BankConnectionBackup {

       // The information needed in this type depend entirely
       // on which connectionis being restored.

     }

  **Response:**

  :status 409 Conflict: The ``name`` field exists already for
    the requesting user.

.. http:post:: {nexusBase}/bank-connections/delete-connection

  **Request:**

  .. ts:def:: BankConnectionDeletion
      
      interface BankConnectionDeletion {
        // label of the bank connection to delete
        bankConnectionId: string;
      }

.. http:get:: {nexusBase}/bank-connections

   List available bank connections.


.. http:get:: {nexusBase}/bank-connections/{connId}

   Get information about one bank connection.

   .. ts:def:: BankConnectionInfo
      
      interface BankConnectionInfo {
         bankConnectionId: string;

         bankConnectionType: string;

         // Is this bank connection ready, or
         // are we waiting for the bank to activate
         // the connection?
         ready: boolean;

         // Did the user review the bank's keys?
         bankKeysReviewed: boolean;
      }


.. http:post:: {nexusBase}/bank-connections/{connId}/connect

   Initialize the connection by talking to the bank.

.. http:post:: {nexusBase}/bank-connections/{connId}/export-backup

   Make a passphrase-encrypted backup of this connection.

.. http:post:: {nexusBase}/bank-connections/{connId}/fetch-accounts

   Update accounts that are accessible via this bank connection.

.. http:get:: {nexusBase}/bank-connections/{connId}/accounts

   List the bank accounts that this bank connection provides access to.

  .. ts:def:: OfferedBankAccount

     interface OfferedBankAccount {

       // Unique identifier for the offered account
       offeredAccountId: string;

       // IBAN of the offered account
       iban: string;

       // BIC of the account's financial institution
       bic: string;

       // Account owner name
       ownerName: string;

       // If the account has been imported,
       // this field contains the ID of the
       // Nexus bank account associated with it.
       nexusBankAccountId: string | null;
     }

.. http:post:: {nexusBase}/bank-connections/{connId}/import-account

  Import a bank account provided by the connection into the Nexus.

  If no Nexus bank account with the ID ``nexusBankAccountId`` exists,
  a new one will be created, and it will have ``connId`` as the
  default bank connection.

  If an existing Nexus bank account with the same ID already exists,
  this connection will be added as an available connection for it.
  This only succeeds if the bank account has the same IBAN.

  .. ts:def:: ImportBankAccount

     interface ImportBankAccount {

       // Identifier for the bank account, as returned by /accounts
       // of the bank connection.
       offeredAccountId: string;

       // Nexus-local identifier for the bank account.
       nexusBankAccountId: string;
     }

Facades
-------

.. http:get:: <nexus>/facades

  List available facades.  

.. http:post:: {nexus}/facades

  Create a new facade; it requires a `FacadeInfo` as the request's body.

.. http:get:: {nexus}/facades/${fcid}

  Get details about a facade.

  .. ts:def:: FacadeInfo
     
     interface FacadeInfo {
        // Name of the facade, same as the "fcid" parameter.
        name: string;

        // Type of the facade.
        // For example, "taler-wire-gateway".
        type: string;

        // Name of the user that created the facade.
        // Whenever the facade accesses a resource it is allowed to
        // access, the creator must *also* have access to that resource.
        creator: string;

        // Bank accounts that the facade has read/write
        // access to.
        bankAccountsRead: string[];
        bankAccountsWrite: string[];

        // Bank connections that the facade has read/write
        // access to.
        bankConnectionsRead: string[];
        bankConnectionsWrite: string[];

        // Facade-specific configuration details.
        config: any;
     }


Bank Connection Protocols
-------------------------

.. http:get:: {nexus}/bank-connection-protocols

   List supported bank connection protocols.

.. http:post:: {nexus}/bank-connection-protocols/ebics/test-host

   Check if the nexus can talk to an EBICS host.
   This doesn't create a new connection in the database,
   and is useful during setup when the user hasn't entered
   the full details for the connection yet.

   .. ts:def:: EbicsHostTestRequest
      
      interface EbicsHostTestRequest {
        ebicsBaseUrl: string;
        ebicsHostId: string;
      }


EBICS-specific APIs
-------------------

The following endpoints are only available for EBICS bank connections.
They are namespaced under the ``/ebics/`` sub-resource.

.. http:post:: {nexusBase}/bank-connections/{connection-name}/ebics/download/{msg}

  .. warning::

    Use with care.  Typically only necessary for testing and debugging.

  Perform an EBICS download transaction of type ``msg``.
  This request will not affect any bank account or other state
  in the nexus database.  It will just make a request to the bank
  and return the answer.

.. http:post:: {nexusBase}/bank-connections/{connection-name}/ebics/upload/{msg}

  .. warning::

    Use with care.  Typically only necessary for testing and debugging.
  
  Perform an EBICS upload transaction of type ``msg``.
  This request will not affect any bank account or other state
  in the nexus database.  It will just make a request to the bank
  and return the answer.


The taler-wire-gateway facade
-----------------------------

The ``taler-wire-gateway`` facade has the following configuration:


.. ts:def:: TalerWireGatewayFacadeConfig
   
   interface TalerWireGatewayFacadeConfig {
     // Bank account and connection that is
     // abstracted over.
     bankAccount: string;
     bankConnection: string;

     // Corresponds to whether we trust C52, C53 or C54 (SEPA ICT)
     // for incoming transfers.
     reserveTransferLevel: "statement" | "report" | "notification";

     // Time between incremental requests
     intervalIncremental: string;

     // FIXME:  maybe more scheduling parameters?
   }