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

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

source /start-libeufin.sh
echo -n "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
echo DONE

# x-libeufin-bank connection.
echo -n 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
# echoing the password to STDIN, as that is a "prompt" option.
libeufin-cli connections new-xlibeufinbank-connection \
  --bank-url "http://localhost:5000/demobanks/default/access-api" \
  --username sandbox-user \
  --password foo \
  xlibeufinbankconn
echo DONE
echo -n Connecting the x-libeufin-bank connection...
libeufin-cli connections connect xlibeufinbankconn
echo DONE
# Importing the bank account under a local name at Nexus.
echo -n 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
echo DONE

# EBICS connection.
## Sandbox side.
export LIBEUFIN_SANDBOX_USERNAME=admin
echo -n "Create EBICS host at Sandbox..."
libeufin-cli sandbox \
  --sandbox-url http://localhost:5000 \
  ebicshost create --host-id wwwebics
echo OK
echo -n "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
echo OK
## Nexus side.
export LIBEUFIN_NEXUS_USERNAME=test-user
export LIBEUFIN_NEXUS_PASSWORD=x
export LIBEUFIN_NEXUS_URL=http://localhost:5001
echo -n 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
echo DONE
echo -n Setup EBICS keying...
libeufin-cli connections connect ebicsconn > /dev/null
echo OK
echo -n Download bank account name from Sandbox...
libeufin-cli connections download-bank-accounts ebicsconn
echo OK
echo -n 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 OK

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

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

# 1, set artificial time for the transaction at $PAST.
echo "UPDATE bankaccounttransactions SET date='$FIRST_JAN_2020' WHERE subject='task5'" | psql -q -d libeufincheck

# 2, retrieve the transaction via Nexus, for both connections.
# This should get only ONE transaction.
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

libeufin-cli \
  accounts \
    transactions \
      bar-at-nexus

echo "DELETE FROM nexusbanktransactions" | psql -d libeufincheck
echo "DELETE FROM nexusbankmessages" | psql -d libeufincheck

libeufin-cli \
  accounts \
    fetch-transactions \
      --level=statement \
      --range-type=time-range \
      --start=$END_DEC_2019 \
      --end=$MID_JAN_2020 \
      foo-at-nexus # x-libeufin-bank

libeufin-cli \
  accounts \
    transactions \
      foo-at-nexus

bash