merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

test_merchant_order_autocleanup.sh (9349B)


      1 #!/usr/bin/env bash
      2 # This file is in the public domain.
      3 
      4 set -eu
      5 
      6 . setup.sh
      7 
      8 
      9 # Replace with 0 for nexus...
     10 USE_FAKEBANK=1
     11 if [ 1 = "$USE_FAKEBANK" ]
     12 then
     13     ACCOUNT="exchange-account-2"
     14     WIRE_METHOD="x-taler-bank"
     15     BANK_FLAGS="-f -d $WIRE_METHOD -u $ACCOUNT"
     16     BANK_URL="http://localhost:8082/"
     17 else
     18     ACCOUNT="exchange-account-1"
     19     WIRE_METHOD="iban"
     20     BANK_FLAGS="-ns -d $WIRE_METHOD -u $ACCOUNT"
     21     BANK_URL="http://localhost:18082/"
     22     echo -n "Testing for libeufin-bank"
     23     libeufin-bank --help >/dev/null </dev/null || exit_skip " MISSING"
     24     echo " FOUND"
     25 
     26 fi
     27 
     28 echo -n "Testing for taler-harness"
     29 taler-harness --help >/dev/null </dev/null || exit_skip " MISSING"
     30 echo " FOUND"
     31 
     32 # Launch exchange, merchant and bank.
     33 setup -c "test_template.conf" \
     34       -r "merchant-exchange-default" \
     35       -em \
     36       $BANK_FLAGS
     37 LAST_RESPONSE=$(mktemp -p "${TMPDIR:-/tmp}" test_response.conf-XXXXXX)
     38 CONF="test_template.conf.edited"
     39 WALLET_DB=$(mktemp -p "${TMPDIR:-/tmp}" test_wallet.json-XXXXXX)
     40 EXCHANGE_URL="http://localhost:8081/"
     41 
     42 
     43 echo -n "First, prepare wallet with coins..."
     44 rm -f "$WALLET_DB"
     45 taler-wallet-cli \
     46     --no-throttle \
     47     --wallet-db="$WALLET_DB" \
     48     api \
     49     --expect-success 'withdrawTestBalance' \
     50   "$(jq -n '
     51     {
     52         amount: "TESTKUDOS:99",
     53         corebankApiBaseUrl: $BANK_URL,
     54         exchangeBaseUrl: $EXCHANGE_URL
     55     }' \
     56     --arg BANK_URL "${BANK_URL}" \
     57     --arg EXCHANGE_URL "$EXCHANGE_URL"
     58   )" 2>wallet-withdraw-1.err >wallet-withdraw-1.out
     59 echo -n "."
     60 if [ 1 = "$USE_FAKEBANK" ]
     61 then
     62     # Fakebank is instant...
     63     sleep 0
     64 else
     65     sleep 10
     66     # NOTE: once libeufin can do long-polling, we should
     67     # be able to reduce the delay here and run wirewatch
     68     # always in the background via setup
     69 fi
     70 echo -n "."
     71 taler-exchange-wirewatch \
     72     -L "INFO" \
     73     -c "$CONF" \
     74     -t \
     75     &> taler-exchange-wirewatch.out
     76 echo -n "."
     77 
     78 timeout 60 taler-wallet-cli \
     79     --wallet-db="$WALLET_DB" \
     80     run-until-done \
     81     2>wallet-withdraw-finish-1.err \
     82     >wallet-withdraw-finish-1.out
     83 echo " OK"
     84 
     85 #
     86 # CREATE INSTANCE FOR TESTING
     87 #
     88 
     89 echo -n "Configuring merchant instance ..."
     90 if [ 1 = "$USE_FAKEBANK" ]
     91 then
     92     FORTYTHREE="payto://x-taler-bank/localhost/fortythree?receiver-name=fortythree"
     93 else
     94     FORTYTHREE=$(get_payto_uri fortythree x)
     95 fi
     96 
     97 STATUS=$(curl -H "Content-Type: application/json" -X POST \
     98     "http://localhost:9966/management/instances" \
     99     -d '{"auth":{"method":"token","password":"super_secret"},"id":"admin","name":"default","user_type":"business","address":{},"jurisdiction":{},"use_stefan":true,"default_wire_transfer_delay":{"d_us" : 50000000},"default_pay_delay":{"d_us": 60000000}}' \
    100     -w "%{http_code}" -s -o /dev/null)
    101 
    102 if [ "$STATUS" != "204" ]
    103 then
    104     exit_fail "Expected 204, instance created. got: $STATUS"
    105 fi
    106 ADMIN_TOKEN=$(merchant_login admin super_secret)
    107 
    108 STATUS=$(curl -H "Content-Type: application/json" -X POST \
    109     -H "Authorization: Bearer $ADMIN_TOKEN" \
    110     http://localhost:9966/private/accounts \
    111     -d '{"payto_uri":"'"$FORTYTHREE"'"}' \
    112     -w "%{http_code}" -s -o /dev/null)
    113 
    114 if [ "$STATUS" != "200" ]
    115 then
    116     exit_fail "Expected '200 OK' response. Got instead $STATUS"
    117 fi
    118 
    119 NOW=$(date +%s)
    120 IN_TEN_SECS=$(( NOW + 10 ))
    121 
    122 echo -n "Creating order to be claimed..."
    123 STATUS=$(curl 'http://localhost:9966/private/orders' \
    124     -H "Authorization: Bearer $ADMIN_TOKEN" \
    125     -d '{"order":{"amount":"TESTKUDOS:1","summary":"payme","pay_deadline": {"t_s":'"$IN_TEN_SECS"'}}}' \
    126     -w "%{http_code}" -s -o "$LAST_RESPONSE")
    127 
    128 if [ "$STATUS" != "200" ]
    129 then
    130     cat "$LAST_RESPONSE"
    131     exit_fail "Expected 200 ok, order created. got: $STATUS"
    132 fi
    133 
    134 ORDER_ID=$(jq -e -r .order_id < "$LAST_RESPONSE")
    135 TOKEN=$(jq -e -r .token < "$LAST_RESPONSE")
    136 
    137 STATUS=$(curl "http://localhost:9966/private/orders/${ORDER_ID}" \
    138     -H "Authorization: Bearer $ADMIN_TOKEN" \
    139     -w "%{http_code}" -s -o "$LAST_RESPONSE")
    140 
    141 if [ "$STATUS" != "200" ]
    142 then
    143     cat "$LAST_RESPONSE"
    144     exit_fail "Expected 200 ok, getting order info before claming it. got: $STATUS"
    145 fi
    146 
    147 PAY_URL=$(jq -e -r .taler_pay_uri < "$LAST_RESPONSE")
    148 
    149 echo "Ok (order $ORDER_ID)"
    150 
    151 NOW=$(date +%s)
    152 
    153 echo -n "Claim the order but do not pay it ..."
    154 taler-wallet-cli \
    155     --no-throttle \
    156     --wallet-db="$WALLET_DB" \
    157     advanced pay-prepare \
    158     "${PAY_URL}" \
    159     2> wallet-claim1.err > wallet-claim1.log
    160 
    161 STATUS=$(curl "http://localhost:9966/private/orders/${ORDER_ID}" \
    162     -H "Authorization: Bearer $ADMIN_TOKEN" \
    163     -w "%{http_code}" -s -o "$LAST_RESPONSE")
    164 
    165 if [ "$STATUS" != "200" ]
    166 then
    167     cat "$LAST_RESPONSE"
    168     exit_fail "Expected 200 ok, after pay. got: $STATUS"
    169 fi
    170 
    171 ORDER_STATUS=$(jq -r .order_status < "$LAST_RESPONSE")
    172 
    173 if [ "$ORDER_STATUS" != "claimed" ]
    174 then
    175     cat "$LAST_RESPONSE"
    176     exit_fail "Expected 'paid'. got: $ORDER_STATUS"
    177 fi
    178 NOW2=$(date +%s)
    179 echo " OK (took $(( NOW2 - NOW)) secs)"
    180 
    181 echo "Wait 8 secs ..."
    182 sleep 8
    183 
    184 echo -n "Trying to get the list of orders..."
    185 STATUS=$(curl "http://localhost:9966/private/orders" \
    186     -H "Authorization: Bearer $ADMIN_TOKEN" \
    187     -w "%{http_code}" -s -o "$LAST_RESPONSE")
    188 
    189 if [ "$STATUS" != "200" ]
    190 then
    191     cat "$LAST_RESPONSE"
    192     exit_fail "Expected 200 ok. got: $STATUS"
    193 fi
    194 echo "ok"
    195 
    196 echo -n "Creating a new order that will trigger the db cleanup..."
    197 STATUS=$(curl 'http://localhost:9966/private/orders' \
    198     -H "Authorization: Bearer $ADMIN_TOKEN" \
    199     -d '{"order":{"amount":"TESTKUDOS:1","summary":"payme"}}' \
    200     -w "%{http_code}" -s -o "$LAST_RESPONSE")
    201 
    202 if [ "$STATUS" != "200" ]
    203 then
    204     cat "$LAST_RESPONSE"
    205     exit_fail "Expected 200 ok, order created. got: $STATUS"
    206 fi
    207 
    208 ORDER_ID=$(jq -e -r .order_id < "$LAST_RESPONSE")
    209 TOKEN=$(jq -e -r .token < "$LAST_RESPONSE")
    210 
    211 STATUS=$(curl "http://localhost:9966/private/orders/${ORDER_ID}" \
    212     -H "Authorization: Bearer $ADMIN_TOKEN" \
    213     -w "%{http_code}" -s -o "$LAST_RESPONSE")
    214 
    215 if [ "$STATUS" != "200" ]
    216 then
    217     cat "$LAST_RESPONSE"
    218     exit_fail "Expected 200 ok, getting order info before claming it. got: $STATUS"
    219 fi
    220 
    221 PAY_URL=$(jq -e -r .taler_pay_uri < "$LAST_RESPONSE")
    222 
    223 echo "Ok (order $ORDER_ID)"
    224 
    225 echo -n "Trying to get the list of orders (issue #7025)..."
    226 STATUS=$(curl "http://localhost:9966/private/orders" \
    227     -H "Authorization: Bearer $ADMIN_TOKEN" \
    228     -w "%{http_code}" -s -o "$LAST_RESPONSE")
    229 
    230 if [ "$STATUS" != "200" ]
    231 then
    232     cat "$LAST_RESPONSE"
    233     exit_fail "Expected 200 ok. got: $STATUS"
    234 fi
    235 echo "OK"
    236 
    237 # set -x
    238 
    239 echo -n "Now paying this order..."
    240 taler-wallet-cli \
    241     --no-throttle \
    242     --wallet-db="$WALLET_DB" \
    243     handle-uri "${PAY_URL}"\
    244     -y \
    245     2> wallet-pay1.err > wallet-pay1.log
    246 
    247 STATUS=$(curl "http://localhost:9966/private/orders/${ORDER_ID}" \
    248     -H "Authorization: Bearer $ADMIN_TOKEN" \
    249     -w "%{http_code}" -s -o "$LAST_RESPONSE")
    250 
    251 if [ "$STATUS" != "200" ]
    252 then
    253     cat "$LAST_RESPONSE"
    254     exit_fail "Expected 200 ok, after pay. got: $STATUS"
    255 fi
    256 
    257 ORDER_STATUS=$(jq -r .order_status < "$LAST_RESPONSE")
    258 
    259 if [ "$ORDER_STATUS" != "paid" ]
    260 then
    261     cat "$LAST_RESPONSE"
    262     exit_fail "Expected 'paid'. got: $ORDER_STATUS"
    263 fi
    264 NOW2=$(date +%s)
    265 echo " OK (took $(( NOW2 - NOW)) secs )"
    266 
    267 
    268 echo -n "Trying to get the list of orders..."
    269 STATUS=$(curl "http://localhost:9966/private/orders" \
    270     -H "Authorization: Bearer $ADMIN_TOKEN" \
    271     -w "%{http_code}" -s -o "$LAST_RESPONSE")
    272 
    273 if [ "$STATUS" != "200" ]
    274 then
    275     cat "$LAST_RESPONSE"
    276     exit_fail "Expected 200 ok. got: $STATUS"
    277 fi
    278 echo ok
    279 
    280 
    281 echo -n "Finally, create another order..."
    282 STATUS=$(curl 'http://localhost:9966/private/orders' \
    283     -H "Authorization: Bearer $ADMIN_TOKEN" \
    284     -d '{"order":{"amount":"TESTKUDOS:1","summary":"payme"}}' \
    285     -w "%{http_code}" -s -o "$LAST_RESPONSE")
    286 
    287 if [ "$STATUS" != "200" ]
    288 then
    289     cat "$LAST_RESPONSE"
    290     exit_fail "Expected 200 ok, order created. got: $STATUS"
    291 fi
    292 
    293 ORDER_ID=$(jq -e -r .order_id < "$LAST_RESPONSE")
    294 TOKEN=$(jq -e -r .token < "$LAST_RESPONSE")
    295 
    296 STATUS=$(curl "http://localhost:9966/private/orders/${ORDER_ID}" \
    297     -H "Authorization: Bearer $ADMIN_TOKEN" \
    298     -w "%{http_code}" -s -o "$LAST_RESPONSE")
    299 
    300 if [ "$STATUS" != "200" ]
    301 then
    302     cat "$LAST_RESPONSE"
    303     exit_fail "Expected 200 ok, getting order info before claiming it. got: $STATUS"
    304 fi
    305 
    306 PAY_URL=$(jq -e -r .taler_pay_uri < "$LAST_RESPONSE")
    307 
    308 echo "Ok (order $ORDER_ID)"
    309 
    310 echo -n "Now paying this order..."
    311 taler-wallet-cli \
    312     --no-throttle \
    313     --wallet-db="$WALLET_DB" \
    314     handle-uri \
    315     "${PAY_URL}" \
    316     -y \
    317     2> wallet-pay1.err > wallet-pay1.log
    318 
    319 STATUS=$(curl "http://localhost:9966/private/orders/${ORDER_ID}" \
    320     -H "Authorization: Bearer $ADMIN_TOKEN" \
    321     -w "%{http_code}" -s -o "$LAST_RESPONSE")
    322 
    323 if [ "$STATUS" != "200" ]
    324 then
    325     cat "$LAST_RESPONSE"
    326     exit_fail "Expected 200 ok. got: $STATUS"
    327 fi
    328 
    329 ORDER_STATUS=$(jq -r .order_status < "$LAST_RESPONSE")
    330 
    331 if [ "$ORDER_STATUS" != "paid" ]
    332 then
    333     cat "$LAST_RESPONSE"
    334     exit_fail "Expected 'paid'. got: $ORDER_STATUS"
    335 fi
    336 NOW2=$(date +%s)
    337 echo " OK (took $( echo -n $(($NOW2 - $NOW)) ) secs )"
    338 
    339 echo -n "Trying to get the list of orders..."
    340 STATUS=$(curl "http://localhost:9966/private/orders" \
    341     -H "Authorization: Bearer $ADMIN_TOKEN" \
    342     -w "%{http_code}" -s -o "$LAST_RESPONSE")
    343 
    344 if [ "$STATUS" != "200" ]
    345 then
    346     cat "$LAST_RESPONSE"
    347     exit_fail "Expected 200 ok. got: $STATUS"
    348 fi
    349 echo "ok"
    350 
    351 echo "Test PASSED"
    352 
    353 exit 0