summaryrefslogtreecommitdiff
path: root/nlnet/task5/date-range/start.sh
blob: c61cfee60a40d06e53d3e4bf3cd9940e1a3702ed (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
#!/bin/bash

# This script shows how Nexus can request histories from
# a particular time frame.  Such request must succeed via
# two connection types: EBICS and x-libeufin-bank.  EBICS
# ensures the fetching of fiat payments made to the regional
# currency authority, whereas x-libeufin-bank does it for
# the regional currency circuit.  Note: the time-framed
# request is exceptional: it's used only after a complaint
# from a user where they didn't get their funds as expected.

set -eu

service postgresql start
sudo -u postgres createuser -s root
createdb libeufincheck

echo -n Launching and confirguring LibEuFin..
source /start-libeufin.sh &> /dev/null
# Register the Sandbox account.
export LIBEUFIN_SANDBOX_USERNAME=sandbox-user
export LIBEUFIN_SANDBOX_PASSWORD=foo
libeufin-cli \
  sandbox --sandbox-url http://localhost:5000/ \
  demobank \
  register
# x-libeufin-bank connection.
#  Creating the x-libeufin-bank connection at Nexus.
export LIBEUFIN_NEXUS_USERNAME=test-user
export LIBEUFIN_NEXUS_PASSWORD=x
export LIBEUFIN_NEXUS_URL=http://localhost:5001
libeufin-cli connections new-xlibeufinbank-connection \
  --bank-url "http://localhost:5000/demobanks/default/access-api" \
  --username sandbox-user \
  --password foo \
  xlibeufinbankconn
#  Connecting the x-libeufin-bank connection...
libeufin-cli connections connect xlibeufinbankconn
# Importing the bank account under a local name at Nexus.
#  Importing the x-libeufin-bank account locally..
libeufin-cli connections import-bank-account \
  --offered-account-id sandbox-user \
  --nexus-bank-account-id foo-at-nexus xlibeufinbankconn

# EBICS connection.
## Sandbox side.
export LIBEUFIN_SANDBOX_USERNAME=admin
#  "Create EBICS host at Sandbox..."
libeufin-cli sandbox \
  --sandbox-url http://localhost:5000 \
  ebicshost create --host-id wwwebics
# Create nlnet EBICS subscriber at Sandbox
libeufin-cli sandbox \
  --sandbox-url http://localhost:5000 \
  demobank new-ebicssubscriber --host-id wwwebics \
  --user-id nlnet --partner-id nlnet \
  --bank-account sandbox-user # that's a username _and_ a bank account name
## Nexus side.
export LIBEUFIN_NEXUS_USERNAME=test-user
export LIBEUFIN_NEXUS_PASSWORD=x
export LIBEUFIN_NEXUS_URL=http://localhost:5001
# Creating the EBICS connection at Nexus...
libeufin-cli connections new-ebics-connection \
  --ebics-url "http://localhost:5000/ebicsweb" \
  --host-id wwwebics \
  --partner-id nlnet \
  --ebics-user-id nlnet \
  ebicsconn
# Setup EBICS keying...
libeufin-cli connections connect ebicsconn > /dev/null
# Download bank account name from Sandbox...
libeufin-cli connections download-bank-accounts ebicsconn
# Importing bank account info into Nexus...
libeufin-cli connections import-bank-account \
  --offered-account-id sandbox-user \
  --nexus-bank-account-id bar-at-nexus ebicsconn
echo DONE

FIRST_JAN_2020="1577833200000" # in milliseconds
END_DEC_2019="2019-12-30"
MID_JAN_2020="2020-01-15"

echo Make sample transaction..
# 0, setup and start services.
libeufin-sandbox make-transaction \
  --credit-account=admin \
  --debit-account=sandbox-user MANA:2 \
  "task5" # subject.
echo DONE

echo -n Articifially set the transaction date to $FIRST_JAN_2020..
# 1, set artificial time for the transaction at January, 1st 2020.
echo "UPDATE bankaccounttransactions SET date='$FIRST_JAN_2020' WHERE subject='task5'" | psql -q -d libeufincheck
echo DONE

# 2, retrieve the transaction via Nexus, for both
# connections and by asking for a (narrow) time frame
# that includes the 2020-01-01 payment.

echo -n Nexus: syncing banking records for the time frame $END_DEC_2019-$MID_JAN_2020 via EBICS..
# Fetch time-framed payments via EBICS.
libeufin-cli \
  accounts \
    fetch-transactions \
      --level=report \
      --range-type=time-range \
      --start=$END_DEC_2019 \
      --end=$MID_JAN_2020 \
      bar-at-nexus > /dev/null # EBICS
echo DONE

echo Showing the synced data..
# Now checks if Nexus ingested and shows the
# expected payment.
libeufin-cli \
  accounts \
    transactions \
      bar-at-nexus
echo DONE

echo Resetting the Nexus database..
# Bring the database state so that Nexus does not hold any payment.
echo "DELETE FROM nexusbanktransactions" | psql -d libeufincheck
echo "DELETE FROM nexusbankmessages" | psql -d libeufincheck
echo DONE

echo Checking that no payment data appears after the reset..
# Double-checking that the future steps start
# without the previous transactions.
libeufin-cli \
  accounts \
    transactions \
      foo-at-nexus # FIXME: put a 204 No Content check?
echo DONE

# Fetch time-framed payments via x-libeufin-bank.
echo Nexus: syncing banking records for the time frame ${END_DEC_2019}_${MID_JAN_2020} via x-libeufin-bank..
libeufin-cli \
  accounts \
    fetch-transactions \
      --level=statement \
      --range-type=time-range \
      --start=$END_DEC_2019 \
      --end=$MID_JAN_2020 \
      foo-at-nexus
echo DONE

# As in the previous case, now Nexus should show
# the 2020-01-01 the payment.
echo Showing the synced data..
libeufin-cli \
  accounts \
    transactions \
      foo-at-nexus # FIXME: put a 200 OK check?
echo DONE