This repository was archived by the owner on Dec 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_demo.go
More file actions
77 lines (67 loc) · 2.02 KB
/
client_demo.go
File metadata and controls
77 lines (67 loc) · 2.02 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
package main
import (
"context"
"fmt"
"os"
"github.com/screwyprof/form3api"
)
const defaultBaseURL = "http://localhost:8080/v1"
func main() {
// create client instance
c := form3api.NewClient(nil, defaultBaseURL)
accountID := "51646a03-a52e-4e51-b405-cf2b8078c1a8"
// create an account
createdAccount, err := c.CreateAccount(context.Background(), form3api.CreateAccount{
AccountData: form3api.AccountData{
ID: accountID,
OrganisationID: "eb0bd6f5-c3f5-44b2-b677-acd23cdde73c",
Type: "accounts",
Attributes: &form3api.AccountAttributes{
AccountNumber: "10000004",
BankID: "400302",
BankIDCode: "GBDSC",
Country: "GB",
Currency: "GBP",
CustomerID: "234",
IBAN: "GB28NWBK40030212764204",
BIC: "NWBKGB42",
ConfirmationOfPayee: &form3api.ConfirmationOfPayee{
AccountClassification: "Personal",
},
},
},
})
failOnError(err)
fmt.Println("Account Created:")
printAccount(createdAccount)
// fetch an account
fetchedAccount, err := c.FetchAccount(context.Background(), form3api.FetchAccount{AccountID: accountID})
failOnError(err)
fmt.Println("Account Fetched:")
printAccount(fetchedAccount)
// Output:
// Account Created:
// Account ID: 51646a03-a52e-4e51-b405-cf2b8078c1a8
// Organisation ID: eb0bd6f5-c3f5-44b2-b677-acd23cdde73c
// Account Number: 10000004
// IBAN: GB28NWBK40030212764204
//
// Account Fetched:
// Account ID: 51646a03-a52e-4e51-b405-cf2b8078c1a8
// Organisation ID: eb0bd6f5-c3f5-44b2-b677-acd23cdde73c
// Account Number: 10000004
// IBAN: GB28NWBK40030212764204
}
func printAccount(acc *form3api.Account) {
fmt.Printf("Account ID: %s\n", acc.AccountData.ID)
fmt.Printf("Organisation ID: %s\n", acc.AccountData.OrganisationID)
fmt.Printf("Account Number: %s\n", acc.AccountData.Attributes.AccountNumber)
fmt.Printf("IBAN: %s\n", acc.AccountData.Attributes.IBAN)
fmt.Println()
}
func failOnError(err error) {
if err != nil {
fmt.Printf("An error occurred: %v\n", err)
os.Exit(1)
}
}