-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathFigoSession.java
More file actions
1523 lines (1419 loc) · 60.7 KB
/
FigoSession.java
File metadata and controls
1523 lines (1419 loc) · 60.7 KB
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
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// Copyright (c) 2013 figo GmbH
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
package me.figo;
import java.io.IOException;
import java.lang.reflect.Type;
import java.net.HttpURLConnection;
import java.net.URLEncoder;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import me.figo.internal.ModifyStandingOrderRequest;
import me.figo.internal.SetupAccountRequest;
import me.figo.internal.SubmitPaymentRequest;
import me.figo.internal.SyncTokenRequest;
import me.figo.internal.TaskResponseType;
import me.figo.internal.TaskStatusRequest;
import me.figo.internal.TaskStatusResponse;
import me.figo.internal.TaskTokenResponse;
import me.figo.internal.VisitedRequest;
import me.figo.models.Account;
import me.figo.models.AccountBalance;
import me.figo.models.Bank;
import me.figo.models.BankLoginSettings;
import me.figo.models.CatalogBank.CatalogBanksResponse;
import me.figo.models.Notification;
import me.figo.models.Payment;
import me.figo.models.PaymentContainer;
import me.figo.models.PaymentProposal;
import me.figo.models.PaymentProposal.PaymentProposalResponse;
import me.figo.models.Security;
import me.figo.models.Service;
import me.figo.models.ServiceLoginSettings;
import me.figo.models.StandingOrder;
import me.figo.models.Transaction;
import me.figo.models.User;
/**
* Main entry point to the data access-part of the figo connect java library.
* Here you can retrieve all the data the user granted your app access to.
*
*
*/
public class FigoSession extends FigoApi {
public enum PendingTransactions {
INCLUDED,
EXCLUDED
}
public enum FieldVisited {
VISITED,
NOT_VISITED
}
/**
* Creates a FigoSession instance
*
* @param accessToken
* the access token to bind this session to a user
*/
public FigoSession(String accessToken) {
this(accessToken, 10000);
}
/**
* Creates a FigoSession instance
*
* @param accessToken
* the access token to bind this session to a user
* @param timeout
* the timeout used for queries
*/
public FigoSession(String accessToken, int timeout) {
super("Bearer " + accessToken, timeout);
}
/**
* Creates a FigoSession instance
*
* @param accessToken
* the access token to bind this session to a user
* @param timeout
* the timeout used for queries
* @param apiEndpoint
* which endpoint to use (customize for different figo deployment)
*/
public FigoSession(String accessToken, int timeout, String apiEndpoint) {
super(apiEndpoint, "Bearer " + accessToken, timeout);
}
/**
* Get the current figo Account
*
* @return User for the current figo Account
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public User getUser() throws FigoException, IOException {
return this.queryApi("/rest/user", null, "GET", User.class);
}
/**
* Modify figo Account
*
* @param user
* modified user object to be saved
* @return User object for the updated figo Account
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public User updateUser(User user) throws FigoException, IOException {
return this.queryApi("/rest/user", user, "PUT", User.class);
}
/**
* Delete figo Account
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public void removeUser() throws FigoException, IOException {
this.queryApi("/rest/user", null, "DELETE", null);
}
/**
* Returns a list of all supported credit cards and payment services for a country
* @param countryCode
* @return List of Services
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public List<Service> getSupportedServices(String countryCode) throws FigoException, IOException {
Service.ServiceResponse response = this.queryApi("/rest/catalog/services/" + countryCode, null, "GET", Service.ServiceResponse.class);
return response == null ? null : response.getServices();
}
/**
* Returns a list of all supported credit cards and payment services for all countries
* @return List of Services
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public List<Service> getSupportedServices() throws FigoException, IOException {
Service.ServiceResponse response = this.queryApi("/rest/catalog/services", null, "GET",
Service.ServiceResponse.class);
return response == null ? null : response.getServices();
}
/**
* Returns the login settings for a specified banking or payment service
* @param countryCode
* @param bankCode
* @return LoginSettings
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public BankLoginSettings getLoginSettings(String countryCode, String bankCode) throws FigoException, IOException {
return this.queryApi("/rest/catalog/banks/" + countryCode + "/" + bankCode, null, "GET", BankLoginSettings.class);
}
public ServiceLoginSettings getLoginSettingsForService(String countryCode, String serviceName) throws IOException, FigoException {
return this.queryApi("/rest/catalog/services/" + countryCode + "/" + serviceName, null, "GET", ServiceLoginSettings.class);
}
/**
* Returns banks catalog by country
* @param countryCode ISO 3166-1
* @return CatalogBanksResponse containing a list of banks for that country
* @throws FigoException
* @throws IOException
*/
public CatalogBanksResponse getCatalogBanks(String countryCode) throws FigoException, IOException {
return this.queryApi("/rest/catalog/banks/" + countryCode, null, "GET", CatalogBanksResponse.class);
}
@Deprecated
/**
* Returns a TaskToken for a new account creation task
* @param bankCode
* @param countryCode
* @param loginName
* @param pin
* @return
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public TaskTokenResponse setupNewAccount(String bankCode, String countryCode, String loginName, String pin) throws FigoException, IOException {
return this.queryApi("/rest/accounts", new SetupAccountRequest(bankCode, countryCode, loginName, pin), "POST", TaskTokenResponse.class);
}
/**
* Returns a TaskToken for a new account creation task
* @param bankCode
* @param countryCode
* @param loginName
* @param pin
* @param syncTasks
* @return
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public TaskTokenResponse setupNewAccount(String bankCode, String countryCode, String loginName, String pin, List<String> syncTasks) throws FigoException, IOException {
return this.queryApi("/rest/accounts", new SetupAccountRequest(bankCode, countryCode, loginName, pin, syncTasks), "POST", TaskTokenResponse.class);
}
/**
*
* @param bankCode
* @param countryCode
* @param syncTasks
* @param savePin
* @param disable_first_sync
* @return
* @throws FigoException
* @throws IOException
*/
public TaskTokenResponse setupNewAccount(String bankCode, String countryCode, String loginName, String pin, List<String> syncTasks, boolean savePin, boolean disable_first_sync) throws FigoException, IOException {
List<String> credentials = Arrays.asList(loginName, pin);
return this.queryApi("/rest/accounts", new SetupAccountRequest(bankCode, countryCode, credentials, syncTasks, savePin, disable_first_sync), "POST", TaskTokenResponse.class);
}
@Deprecated
/**
* Returns a TaskToken for a new account creation task
* @param bankCode
* @param countryCode
* @param loginName
* @param pin
* @return
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public TaskTokenResponse setupNewAccount(String bankCode, String countryCode, List<String> credentials) throws FigoException, IOException {
return this.queryApi("/rest/accounts", new SetupAccountRequest(bankCode, countryCode, credentials, null), "POST", TaskTokenResponse.class);
}
/**
* Returns a TaskToken for a new account creation task
* @param bankCode
* @param countryCode
* @param credentials
* @return
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public TaskTokenResponse setupNewAccount(String bankCode, String countryCode, List<String> credentials, List<String> syncTasks) throws FigoException, IOException {
return this.queryApi("/rest/accounts", new SetupAccountRequest(bankCode, countryCode, credentials, syncTasks), "POST", TaskTokenResponse.class);
}
/**
*
* @param bankCode
* @param countryCode
* @param credentials
* @param syncTasks
* @param savePin
* @param disable_first_sync
* @return
* @throws FigoException
* @throws IOException
*/
public TaskTokenResponse setupNewAccount(String bankCode, String countryCode, List<String> credentials, List<String> syncTasks, boolean savePin, boolean disable_first_sync) throws FigoException, IOException {
return this.queryApi("/rest/accounts", new SetupAccountRequest(bankCode, countryCode, credentials, syncTasks, savePin, disable_first_sync), "POST", TaskTokenResponse.class);
}
/**
*
* @param bankCode
* @param countryCode
* @param encryptedCredentials
* @param syncTasks
* @param savePin
* @param disable_first_sync
* @return
* @throws FigoException
* @throws IOException
*/
public TaskTokenResponse setupNewAccount(String bankCode, String countryCode, String encryptedCredentials, List<String> syncTasks, boolean savePin, boolean disable_first_sync) throws FigoException, IOException {
return this.queryApi("/rest/accounts", new SetupAccountRequest(bankCode, countryCode, encryptedCredentials, syncTasks, savePin, disable_first_sync), "POST", TaskTokenResponse.class);
}
@Deprecated
/**
* Setups an account an starts the initial syncronization directly
* @param bankCode
* @param countryCode
* @param loginName
* @param pin
* @return TaskStatusResponse
*
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException, InterruptedException
*/
public TaskStatusResponse setupAndSyncAccount(String bankCode, String countryCode, String loginName, String pin) throws FigoException, IOException, FigoPinException, InterruptedException {
return this.setupAndSyncAccount(bankCode, countryCode, loginName, pin, null);
}
/**
* Setups an account an starts the initial syncronization directly
* @param bankCode
* @param countryCode
* @param loginName
* @param pin
* @return TaskStatusResponse
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException, FigoPinException, InterruptedException
*/
public TaskStatusResponse setupAndSyncAccount(String bankCode, String countryCode, String loginName, String pin, List<String>syncTasks) throws FigoException, IOException, FigoPinException, InterruptedException {
TaskTokenResponse tokenResponse = this.setupNewAccount(bankCode, countryCode, loginName, pin, syncTasks);
TaskStatusResponse taskStatus = this.getTaskState(tokenResponse);
while(!taskStatus.isEnded() && !taskStatus.isErroneous() && !taskStatus.isWaitingForPin() && !taskStatus.isWaitingForResponse()) {
taskStatus = this.getTaskState(tokenResponse);
Thread.sleep(1000);
}
if(taskStatus.isWaitingForPin() && !taskStatus.isEnded()) {
throw new FigoPinException(bankCode, countryCode, loginName, pin, tokenResponse);
}
else if(taskStatus.isErroneous() && taskStatus.isEnded()){
throw new FigoException("", taskStatus.getMessage());
}
return taskStatus;
}
/**
* Exception handler for a wrong pin. Starts a new task for account creation with a new pin
* @param exception
* FigoPinException which provides info about the account which should be created
* @param newPin
* new PIN
* @return
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException, FigoPinException, InterruptedException
*/
public TaskStatusResponse setupAndSyncAccount(FigoPinException exception, String newPin) throws FigoException, IOException, FigoPinException, InterruptedException {
return this.setupAndSyncAccount(exception.getBankCode(), exception.getCountryCode(), exception.getLoginName(), newPin);
}
/**
* All accounts the user has granted your app access to
*
* @return List of Accounts
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public List<Account> getAccounts() throws FigoException, IOException {
Account.AccountsResponse response = this.queryApi("/rest/accounts", null, "GET", Account.AccountsResponse.class);
return response == null ? null : response.getAccounts();
}
/**
* Returns the account with the specified ID
*
* @param accountId
* figo ID of the account to be retrieved
* @return Account or Null
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public Account getAccount(String accountId) throws FigoException, IOException {
return this.queryApi("/rest/accounts/" + accountId, null, "GET", Account.class);
}
/**
* Modify an account
*
* @param account
* the modified account to be saved
* @return Account object for the updated account returned by server
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public Account updateAccount(Account account) throws FigoException, IOException {
return this.queryApi("/rest/accounts/" + account.getAccountId(), account, "PUT", Account.class);
}
/**
* Remove an account
*
* @param accountId
* ID of the account to be removed
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public void removeAccount(String accountId) throws FigoException, IOException {
this.queryApi("/rest/accounts/" + accountId, null, "DELETE", null);
}
/**
* Remove an account
*
* @param account
* Account to be removed
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public void removeAccount(Account account) throws FigoException, IOException {
removeAccount(account.getAccountId());
}
/**
* Returns the balance details of the account with he specified ID
*
* @param accountId
* figo ID of the account to be retrieved
* @return AccountBalance or Null
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public AccountBalance getAccountBalance(String accountId) throws FigoException, IOException {
return this.queryApi("/rest/accounts/" + accountId + "/balance", null, "GET", AccountBalance.class);
}
/**
* Returns the balance details of the supplied account
*
* @param account
* account whose balance should be retrieved
* @return AccountBalance or Null
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public AccountBalance getAccountBalance(Account account) throws FigoException, IOException {
return getAccountBalance(account.getAccountId());
}
/**
* Modify balance or account limits
*
* @param accountId
* ID of the account to be modified
* @param accountBalance
* modified AccountBalance object to be saved
* @return AccountBalance object for the updated account as returned by the server
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public AccountBalance updateAccountBalance(String accountId, AccountBalance accountBalance) throws FigoException, IOException {
return this.queryApi("/rest/accounts/" + accountId + "/balance", accountBalance, "PUT", AccountBalance.class);
}
/**
* Modify balance or account limits
*
* @param account
* account to be modified
* @param accountBalance
* modified AccountBalance object to be saved
* @return AccountBalance object for the updated account as returned by the server
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public AccountBalance updateAccountBalance(Account account, AccountBalance accountBalance) throws FigoException, IOException {
return updateAccountBalance(account.getAccountId(), accountBalance);
}
/**
* All transactions on all account of the user
*
* @return List of Transaction objects
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public List<Transaction> getTransactions() throws FigoException, IOException {
return getTransactions((String) null);
}
/**
* Retrieve all transactions on a specific account of the user
*
* @param accountId
* the ID of the account for which to retrieve the transactions
* @return List of Transactions
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public List<Transaction> getTransactions(String accountId) throws FigoException, IOException {
return this.getTransactions(accountId, null, null, null, null);
}
/**
* Retrieve all transactions on a specific account of the user
*
* @param account
* the account for which to retrieve the transactions
* @return List of Transactions
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public List<Transaction> getTransactions(Account account) throws FigoException, IOException {
return this.getTransactions(account, null, null, null, null);
}
/**
* Get an array of Transaction objects, one for each transaction of the user matching the criteria. Provide null values to not use the option.
*
* @param account
* account for which to list the transactions
* @param since
* this parameter can either be a transaction ID or a date
* @param count
* limit the number of returned transactions
* @param offset
* which offset into the result set should be used to determine the first transaction to return (useful in combination with count)
* @param include_pending
* this flag indicates whether pending transactions should be included in the response; pending transactions are always included as a complete
* set, regardless of the `since` parameter
* @return an array of Transaction objects
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public List<Transaction> getTransactions(Account account, String since, Integer count, Integer offset, PendingTransactions include_pending) throws FigoException, IOException {
return getTransactions(account == null ? null : account.getAccountId(), since, count, offset, include_pending);
}
/**
* Get an array of Transaction objects, one for each transaction of the user matching the criteria. Provide null values to not use the option.
*
* @param accountId
* ID of the account for which to list the transactions
* @param since
* this parameter can either be a transaction ID or a date
* @param count
* limit the number of returned transactions
* @param offset
* which offset into the result set should be used to determine the first transaction to return (useful in combination with count)
* @param include_pending
* this flag indicates whether pending transactions should be included in the response; pending transactions are always included as a complete
* set, regardless of the `since` parameter
* @return an array of Transaction objects
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public List<Transaction> getTransactions(String accountId, String since, Integer count, Integer offset, PendingTransactions include_pending) throws FigoException, IOException {
String path = "";
if (accountId == null) {
path += "/rest/transactions?";
} else {
path += "/rest/accounts/" + accountId + "/transactions?";
}
if (since != null) {
path += "since=" + URLEncoder.encode(since, "ISO-8859-1") + "&";
}
if (count != null) {
path += "count=" + count + "&";
}
if (offset != null) {
path += "offset=" + offset + "&";
}
if (include_pending != null) {
path += "include_pending=" + (include_pending == PendingTransactions.INCLUDED ? "1" : "0");
}
Transaction.TransactionsResponse response = this.queryApi(path, null, "GET", Transaction.TransactionsResponse.class);
return response == null ? Collections.<Transaction>emptyList() : response.getTransactions();
}
/**
* Retrieve a specific transaction by ID
*
* @param accountId
* ID of the account on which the transaction occurred
* @param transactionId
* the figo ID of the specific transaction
* @return Transaction or null
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public Transaction getTransaction(String accountId, String transactionId) throws FigoException, IOException {
return this.queryApi("/rest/accounts/" + accountId + "/transactions/" + transactionId, null, "GET", Transaction.class);
}
/**
* Modifies the visited field of a specific transaction
* @param transaction
* transaction which will be modified
* @param visited
* new value for the visited field
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public void modifyTransaction(Transaction transaction, FieldVisited visited) throws FigoException, IOException {
this.queryApi("/rest/accounts/" + transaction.getAccountId() + "/transactions/" + transaction.getTransactionId(), new VisitedRequest(visited == FieldVisited.VISITED), "PUT", null);
}
/**
* Modifies the visited field of all transactions of the current user
* @param visited
* new value for the visited field
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public void modifyTransactions(FieldVisited visited) throws FigoException, IOException {
this.queryApi("/rest/transactions", new VisitedRequest(visited == FieldVisited.VISITED), "PUT", null);
}
/**
* Modifies the visited field of all transactions of a specific account
* @param account
* account which owns the transactions
* @param visited
* new value for the visited field
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public void modifyTransactions(Account account, FieldVisited visited) throws FigoException, IOException {
this.queryApi("/rest/accounts/" + account.getAccountId() + "/transactions", new VisitedRequest(visited == FieldVisited.VISITED), "PUT", null);
}
/**
* Modifies the visited field of all transactions of a specific account
* @param accountId
* Id of the account which owns the transactions
* @param visited
* new value for the visited field
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public void modifyTransactions(String accountId, FieldVisited visited) throws FigoException, IOException {
this.queryApi("/rest/accounts/" + accountId + "/transactions", new VisitedRequest(visited == FieldVisited.VISITED), "PUT", null);
}
/**
* Removes a Transaction
* @param transaction
* transaction which will be removed
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public void removeTransaction(Transaction transaction) throws FigoException, IOException {
this.queryApi("/rest/accounts/" + transaction.getAccountId() + "/transactions/" + transaction.getTransactionId(), null, "DELETE", null);
}
/**
* Get an array of standing orders objects, one for each standing order of the user matching the criteria. Provide null values to not use the option.
*
* @param accountId
* ID of the account for which to list the standing orders
* @return an array of Standing Order objects
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public List<StandingOrder> getStandingOrders(String accountId) throws FigoException, IOException {
String path = "";
if (accountId == null) {
path += "/rest/standing_orders";
} else {
path += "/rest/accounts/" + accountId + "/standing_orders";
}
StandingOrder.StandingOrdersResponse response = this.queryApi(path, null, "GET", StandingOrder.StandingOrdersResponse.class);
return response == null ? Collections.<StandingOrder>emptyList() : response.getStandingOrders();
}
/**
* All standing orders on all accounts of the user
*
* @return List of Standing Order objects
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public List<StandingOrder> getStandingOrders() throws FigoException, IOException {
return getStandingOrders((String) null);
}
/**
* Retrieve a specific standing order by ID
*
* @param standingOrderId
* the figo ID of the specific standingOrder
* @return Standing Order or null
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public StandingOrder getStandingOrder(String standingOrderId) throws FigoException, IOException {
return this.queryApi("/rest/standing_orders/" + standingOrderId, null, "GET", StandingOrder.class);
}
/**
* Update a standing order, this creates a new payment which has to be submitted to update the existing
* standing order
* @param updatedStandingOrder standing order where values which should be updated are set
* @return a payment object which has to be submitted
* @throws IOException
* @throws FigoException
*/
public Payment modifyStandingOrder(StandingOrder updatedStandingOrder) throws IOException, FigoException {
String accountId = updatedStandingOrder.getAccountId();
ModifyStandingOrderRequest request = new ModifyStandingOrderRequest(updatedStandingOrder);
return this.queryApi("/rest/accounts/" + accountId + "/payments", request, "PUT", Payment.class);
}
/**
* Create a deletion task for a standing order
* @param standingOrder the standing order to delete
* @return a TaskToken for further processing
* @throws IOException
* @throws FigoException
*/
public TaskTokenResponse deleteStandingOrder(StandingOrder standingOrder) throws IOException, FigoException {
return this.queryApi("/rest/standing_orders/" + standingOrder.getStandingOrderId(), null, "DELETE", TaskTokenResponse.class);
}
/**
* Create a deletion task for a standing order
* @param standingOrderId the standing order id to delete
* @return a TaskToken for further processing
* @throws IOException
* @throws FigoException
*/
public TaskTokenResponse deleteStandingOrder(String standingOrderId) throws IOException, FigoException {
return this.queryApi("/rest/standing_orders/" + standingOrderId, null, "DELETE", TaskTokenResponse.class);
}
/**
* Retrieves a specific security
* @param accountId
* id of the security owning account
* @param securityId
* id of the security which will be retrieved
* @return Security or null
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public Security getSecurity(String accountId, String securityId) throws FigoException, IOException {
return this.queryApi("/rest/accounts/" + accountId + "/securities/" + securityId, null, "GET", Security.class);
}
/**
* Retrieves a specific security
* @param account
* owning account
* @param securityId
* id of the security which will be retrieved
* @return Security or null
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public Security getSecurity(Account account, String securityId) throws FigoException, IOException {
return this.queryApi("/rest/accounts/" + account.getAccountId() + "/securities/" + securityId, null, "GET", Security.class);
}
/**
* Retrieves all securities of the current user
* @return List of Securities or null
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public List<Security> getSecurities() throws FigoException, IOException {
Security.SecurityResponse response = this.queryApi("/rest/securities", null, "GET", Security.SecurityResponse.class);
return response == null ? Collections.<Security>emptyList() : response.getSecurities();
}
/**
* Retrieves all securities of a specific account
* @param account Security owning account
* @return List of Securities or null
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public List<Security> getSecurities(Account account) throws FigoException, IOException {
Security.SecurityResponse response = this.queryApi("/rest/accounts/" + account.getAccountId() + "/securities", null, "GET", Security.SecurityResponse.class);
return response == null ? Collections.<Security>emptyList() : response.getSecurities();
}
/**
* Retrieves all securities of a specific account
* @param accountId Security owning account id
* @return List of Securities or null
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public List<Security> getSecurities(String accountId) throws FigoException, IOException {
Security.SecurityResponse response = this.queryApi("/rest/accounts/" + accountId + "/securities", null, "GET", Security.SecurityResponse.class);
return response == null ? Collections.<Security>emptyList() : response.getSecurities();
}
/**
* Modifies the visited field of a specific security
* @param security
* security which will be modified
* @param visited
* new value for the visited field
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public void modifySecurity(Security security, FieldVisited visited) throws FigoException, IOException {
this.queryApi("/rest/accounts/" + security.getAccountId() + "/securities/" + security.getSecurityId(), new VisitedRequest(visited == FieldVisited.VISITED), "PUT", null);
}
/**
* Modifies the visited field of all securities of the current user
* @param visited
* new value for the visited field
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public void modifySecurities(FieldVisited visited) throws FigoException, IOException {
this.queryApi("/rest/securities", new VisitedRequest(visited == FieldVisited.VISITED), "PUT", null);
}
/**
* Modifies the visited field of all securities of a specific account
* @param account
* account which owns the securities
* @param visited
* new value for the visited field
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public void modifySecurities(Account account, FieldVisited visited) throws FigoException, IOException {
this.queryApi("/rest/accounts/" + account.getAccountId() + "/securities", new VisitedRequest(visited == FieldVisited.VISITED), "PUT", null);
}
/**
* Modifies the visited field of all securities of a specific account
* @param accountId
* Id of the account which owns the securities
* @param visited
* new value for the visited field
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public void modifySecurities(String accountId, FieldVisited visited) throws FigoException, IOException {
this.queryApi("/rest/accounts/" + accountId + "/securities", new VisitedRequest(visited == FieldVisited.VISITED), "PUT", null);
}
/**
* Get bank
*
* @param bankId
* ID of the bank to be retrieved
* @return Bank or null
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public Bank getBank(String bankId) throws FigoException, IOException {
return this.queryApi("/rest/banks/" + bankId, null, "GET", Bank.class);
}
/**
* Get Bank for account
*
* @param account
* Account for which to return the Bank
* @return Bank or Null
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public Bank getBank(Account account) throws FigoException, IOException {
return getBank(account.getBankId());
}
/**
* Modify a bank
*
* @param bank
* modified bank object to be saved
* @return Bank object for the updated bank
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public Bank updateBank(Bank bank) throws FigoException, IOException {
return this.queryApi("/rest/banks/" + bank.getBankId(), bank, "PUT", Bank.class);
}
/**
* Remove the stored PIN for a bank (if there was one)
*
* @param bankId
* ID of the bank whose pin should be removed
* @return
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public Bank removeBankPin(String bankId) throws FigoException, IOException {
Bank bankResponse = (Bank) this.queryApi("/rest/banks/" + bankId + "/remove_pin", null, "POST", null);
return bankResponse;
}
/**
* Remove the stored PIN for a bank (if there was one)
*
* @param bank
* bank whose pin should be removed
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public Bank removeBankPin(Bank bank) throws FigoException, IOException {
Bank bankResponse = (Bank) removeBankPin(bank.getBankId());
return bankResponse;
}
/**
* All notifications registered by this client for the user
*
* @return List of Notification objects
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public List<Notification> getNotifications() throws FigoException, IOException {
Notification.NotificationsResponse response = this.queryApi("/rest/notifications", null, "GET", Notification.NotificationsResponse.class);
return response == null ? Collections.<Notification>emptyList() : response.getNotifications();
}
/**
* Retrieve a specific notification by ID
*
* @param notificationId
* figo ID for the notification to be retrieved
* @return Notification or Null
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public Notification getNotification(String notificationId) throws FigoException, IOException {
return this.queryApi("/rest/notifications/" + notificationId, null, "GET", Notification.class);
}
/**
* Register a new notification on the server for the user
*
* @param notification
* Notification which should be registered
* @return the newly registered Notification
*
* @exception FigoException Base class for all figoExceptions
* @exception IOException IOException
*/
public Notification addNotification(Notification notification) throws FigoException, IOException {