merchant

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

test_merchant_transfer_tracking.sh (21721B)


      1 #!/bin/bash
      2 # This file is part of TALER
      3 # Copyright (C) 2014-2024 Taler Systems SA
      4 #
      5 # TALER is free software; you can redistribute it and/or modify
      6 # it under the terms of the GNU General Public License as
      7 # published by the Free Software Foundation; either version 3, or
      8 # (at your option) any later version.
      9 #
     10 # TALER is distributed in the hope that it will be useful, but
     11 # WITHOUT ANY WARRANTY; without even the implied warranty of
     12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 # GNU General Public License for more details.
     14 #
     15 # You should have received a copy of the GNU General Public
     16 # License along with TALER; see the file COPYING.  If not, see
     17 # <http://www.gnu.org/licenses/>
     18 #
     19 # Testcase for #6912 and #8061
     20 
     21 set -eu
     22 
     23 . setup.sh
     24 
     25 # Replace with 0 for nexus...
     26 USE_FAKEBANK=1
     27 if [ 1 = "$USE_FAKEBANK" ]
     28 then
     29     ACCOUNT="exchange-account-2"
     30     WIRE_METHOD="x-taler-bank"
     31     BANK_FLAGS="-f -d $WIRE_METHOD -u $ACCOUNT"
     32     BANK_URL="http://localhost:8082/"
     33 else
     34     echo -n "Testing for libeufin-bank"
     35     libeufin-bank --help >/dev/null </dev/null || exit_skip " MISSING"
     36     echo " FOUND"
     37     ACCOUNT="exchange-account-1"
     38     WIRE_METHOD="iban"
     39     BANK_FLAGS="-ns -d $WIRE_METHOD -u $ACCOUNT"
     40     BANK_URL="http://localhost:18082/"
     41 fi
     42 
     43 
     44 echo -n "Testing for taler-harness"
     45 taler-harness --help >/dev/null </dev/null || exit_skip " MISSING"
     46 echo " FOUND"
     47 
     48 # Launch system.
     49 setup -c "test_template.conf" \
     50       -r "merchant-exchange-default" \
     51       -em \
     52       $BANK_FLAGS
     53 LAST_RESPONSE=$(mktemp -p "${TMPDIR:-/tmp}" test_response.conf-XXXXXX)
     54 WALLET_DB=$(mktemp -p "${TMPDIR:-/tmp}" test_wallet.json-XXXXXX)
     55 CONF="test_template.conf.edited"
     56 EXCHANGE_URL="http://localhost:8081/"
     57 
     58 echo -n "First prepare wallet with coins..."
     59 rm -f "$WALLET_DB"
     60 taler-wallet-cli \
     61     --no-throttle \
     62     --wallet-db="$WALLET_DB" \
     63     api \
     64     --expect-success 'withdrawTestBalance' \
     65   "$(jq -n '
     66     {
     67         amount: "TESTKUDOS:99",
     68         corebankApiBaseUrl: $BANK_URL,
     69         exchangeBaseUrl: $EXCHANGE_URL
     70     }' \
     71     --arg BANK_URL "${BANK_URL}" \
     72     --arg EXCHANGE_URL "$EXCHANGE_URL"
     73   )" 2>wallet-withdraw-1.err >wallet-withdraw-1.out
     74 echo -n "."
     75 if [ 1 = "$USE_FAKEBANK" ]
     76 then
     77     # Fakebank is instant...
     78     sleep 0
     79 else
     80     sleep 10
     81     # NOTE: once libeufin can do long-polling, we should
     82     # be able to reduce the delay here and run wirewatch
     83     # always in the background via setup
     84 fi
     85 echo -n "."
     86 # NOTE: once libeufin can do long-polling, we should
     87 # be able to reduce the delay here and run wirewatch
     88 # always in the background via setup
     89 taler-exchange-wirewatch \
     90     -L "INFO" \
     91     -c "$CONF" \
     92     -t &> taler-exchange-wirewatch0.out
     93 echo -n "."
     94 
     95 taler-wallet-cli \
     96     --wallet-db="$WALLET_DB" \
     97     run-until-done \
     98     2>wallet-withdraw-finish-1.err >wallet-withdraw-finish-1.out
     99 echo " OK"
    100 
    101 #
    102 # CREATE INSTANCE FOR TESTING
    103 #
    104 
    105 echo -n "Configuring merchant admin instance ..."
    106 if [ 1 = "$USE_FAKEBANK" ]
    107 then
    108     TOR_PAYTO="payto://x-taler-bank/localhost/tor?receiver-name=tor"
    109     GNUNET_PAYTO="payto://x-taler-bank/localhost/gnunet?receiver-name=gnunet"
    110     SURVEY_PAYTO="payto://x-taler-bank/localhost/survey?receiver-name=survey"
    111     TUTORIAL_PAYTO="payto://x-taler-bank/localhost/tutorial?receiver-name=tutorial"
    112 else
    113     TOR_PAYTO=$(get_payto_uri tor x)
    114     GNUNET_PAYTO=$(get_payto_uri gnunet x)
    115     SURVEY_PAYTO=$(get_payto_uri survey x)
    116     TUTORIAL_PAYTO=$(get_payto_uri tutorial x)
    117 fi
    118 # create with 2 address
    119 
    120 STATUS=$(curl -H "Content-Type: application/json" -X POST \
    121     -H 'Authorization: Bearer secret-token:super_secret' \
    122     http://localhost:9966/management/instances \
    123     -d '{"auth":{"method":"external"},"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}}' \
    124     -w "%{http_code}" -s -o /dev/null)
    125 
    126 if [ "$STATUS" != "204" ]
    127 then
    128     exit_fail "Expected 204, instance created. got: $STATUS"
    129 fi
    130 
    131 STATUS=$(curl -H "Content-Type: application/json" -X POST \
    132     -H 'Authorization: Bearer secret-token:super_secret' \
    133     http://localhost:9966/private/accounts \
    134     -d '{"payto_uri":"'"$TOR_PAYTO"'"}' \
    135     -w "%{http_code}" -s -o /dev/null)
    136 
    137 if [ "$STATUS" != "200" ]
    138 then
    139     exit_fail "Expected 200 OK. Got: $STATUS"
    140 fi
    141 STATUS=$(curl -H "Content-Type: application/json" -X POST \
    142     -H 'Authorization: Bearer secret-token:super_secret' \
    143     http://localhost:9966/private/accounts \
    144     -d '{"payto_uri":"'"$GNUNET_PAYTO"'"}' \
    145     -w "%{http_code}" -s -o /dev/null)
    146 
    147 if [ "$STATUS" != "200" ]
    148 then
    149     exit_fail "Expected 200 OK. Got: $STATUS"
    150 fi
    151 
    152 echo "OK"
    153 
    154 echo -n "Configuring merchant test instance ..."
    155 # create with 2 address
    156 
    157 STATUS=$(curl -H "Content-Type: application/json" -X POST \
    158     -H 'Authorization: Bearer secret-token:super_secret' \
    159     http://localhost:9966/management/instances \
    160     -d '{"auth":{"method":"external"},"id":"test","name":"test","user_type":"business","address":{},"jurisdiction":{},"use_stefan":true,"default_wire_transfer_delay":{"d_us" : 50000000},"default_pay_delay":{"d_us": 60000000}}' \
    161     -w "%{http_code}" -s -o /dev/null)
    162 
    163 if [ "$STATUS" != "204" ]
    164 then
    165     exit_fail "Expected 204, instance created. got: $STATUS"
    166 fi
    167 STATUS=$(curl -H "Content-Type: application/json" -X POST \
    168     -H 'Authorization: Bearer secret-token:super_secret' \
    169     http://localhost:9966/instances/test/private/accounts \
    170     -d '{"payto_uri":"'"$SURVEY_PAYTO"'","credit_facade_url":"http://localhost:8082/accounts/survey/taler-revenue/","credit_facade_credentials":{"type":"basic","username":"survey","password":"x"}}' \
    171     -w "%{http_code}" -s -o /dev/null)
    172 
    173 if [ "$STATUS" != "200" ]
    174 then
    175     exit_fail "Expected 200 OK. Got: $STATUS"
    176 fi
    177 
    178 
    179 # CREATE ORDER AND SELL IT
    180 echo -n "Creating order to be paid..."
    181 STATUS=$(curl 'http://localhost:9966/instances/test/private/orders' \
    182     -d '{"refund_delay":{"d_us":0}, "order":{"amount":"TESTKUDOS:1","summary":"payme"}}' \
    183     -w "%{http_code}" -s -o "$LAST_RESPONSE")
    184 
    185 if [ "$STATUS" != "200" ]
    186 then
    187     cat "$LAST_RESPONSE"
    188     exit_fail "Expected 200 ok, order created. got: $STATUS"
    189 fi
    190 
    191 ORDER_ID=$(jq -e -r .order_id < "$LAST_RESPONSE")
    192 #TOKEN=$(jq -e -r .token < "$LAST_RESPONSE")
    193 
    194 STATUS=$(curl "http://localhost:9966/instances/test/private/orders/${ORDER_ID}" \
    195     -w "%{http_code}" -s -o "$LAST_RESPONSE")
    196 
    197 if [ "$STATUS" != "200" ]
    198 then
    199     cat "$LAST_RESPONSE"
    200     exit_fail "Expected 200 ok, getting order info before claming it. got: $STATUS"
    201 fi
    202 PAY_URL=$(jq -e -r .taler_pay_uri < "$LAST_RESPONSE")
    203 echo "OK"
    204 
    205 NOW=$(date +%s)
    206 echo -n "Pay first order ..."
    207 taler-wallet-cli \
    208     --no-throttle \
    209     --wallet-db="$WALLET_DB" \
    210     handle-uri "${PAY_URL}" \
    211     -y \
    212     2> wallet-pay1.err > wallet-pay1.log
    213 NOW2=$(date +%s)
    214 echo " OK (took $(( NOW2 - NOW )) secs)"
    215 
    216 STATUS=$(curl "http://localhost:9966/instances/test/private/orders/${ORDER_ID}" \
    217     -w "%{http_code}" -s -o "$LAST_RESPONSE")
    218 
    219 if [ "$STATUS" != "200" ]
    220 then
    221     cat "$LAST_RESPONSE"
    222     exit_fail "Expected 200 ok, after pay. got: $STATUS"
    223 fi
    224 
    225 ORDER_STATUS=$(jq -r .order_status < "$LAST_RESPONSE")
    226 
    227 if [ "$ORDER_STATUS" != "paid" ]
    228 then
    229     cat "$LAST_RESPONSE"
    230     exit_fail "Expected 'paid'. got: $ORDER_STATUS"
    231 fi
    232 
    233 #
    234 # WIRE TRANSFER TO MERCHANT AND NOTIFY BACKEND
    235 #
    236 
    237 #PAY_DEADLINE=$(jq -r .contract_terms.pay_deadline.t_s < "$LAST_RESPONSE")
    238 WIRE_DEADLINE=$(jq -r .contract_terms.wire_transfer_deadline.t_s < "$LAST_RESPONSE")
    239 
    240 NOW=$(date +%s)
    241 
    242 TO_SLEEP=$((3600 + WIRE_DEADLINE - NOW ))
    243 echo "waiting $TO_SLEEP secs for wire transfer"
    244 
    245 echo -n "Perform wire transfers ..."
    246 taler-exchange-aggregator -y -c $CONF -T ${TO_SLEEP}000000 -t -L INFO &> aggregator.log
    247 taler-exchange-transfer -c $CONF -t -L INFO &> transfer.log
    248 echo " DONE"
    249 
    250 echo -n "Obtaining wire transfer details from bank..."
    251 
    252 BANKDATA="$(curl 'http://localhost:8082/accounts/exchange/taler-wire-gateway/history/outgoing?delta=1' -s)"
    253 WTID=$(echo "$BANKDATA" | jq -r .outgoing_transactions[0].wtid)
    254 WURL=$(echo "$BANKDATA" | jq -r .outgoing_transactions[0].exchange_base_url)
    255 CREDIT_AMOUNT=$(echo "$BANKDATA" | jq -r .outgoing_transactions[0].amount)
    256 TARGET_PAYTO=$(echo "$BANKDATA" | jq -r .outgoing_transactions[0].credit_account)
    257 TARGET=$(echo "$TARGET_PAYTO" | awk -F = '{print $2}')
    258 
    259 # Figure out which account got paid, in order to
    260 # resort the right (and complete: including the receiver-name)
    261 # TARGET_PAYTO
    262 if echo "$SURVEY_PAYTO" | grep -q "$TARGET" > /dev/null; then
    263   TARGET_PAYTO="$SURVEY_PAYTO";
    264 fi
    265 if echo "$SURVEY_PAYTO" | grep -q "$TARGET" > /dev/null; then
    266   TARGET_PAYTO="$SURVEY_PAYTO";
    267 fi
    268 if [ "$EXCHANGE_URL" != "$WURL" ]
    269 then
    270     exit_fail "Wrong exchange URL in subject '$SUBJECT', expected $EXCHANGE_URL"
    271 fi
    272 echo " OK"
    273 
    274 set +e
    275 
    276 echo -n "Notifying merchant of correct wire transfer, but on wrong instance..."
    277 
    278 #issue 6912
    279 #here we are notifying the transfer into a wrong instance (admin) and the payto_uri of the admin instance
    280 STATUS=$(curl 'http://localhost:9966/private/transfers' \
    281     -d "{\"credit_amount\":\"$CREDIT_AMOUNT\",\"wtid\":\"$WTID\",\"payto_uri\":\"$TOR_PAYTO\",\"exchange_url\":\"$WURL\"}" \
    282     -m 3 \
    283     -w "%{http_code}" \
    284     -s \
    285     -o "$LAST_RESPONSE")
    286 
    287 if [ "$STATUS" != "204" ]
    288 then
    289     jq . < "$LAST_RESPONSE"
    290     exit_fail "Expected response 204 no content, after providing transfer data. Got: $STATUS"
    291 fi
    292 echo " OK"
    293 
    294 
    295 echo -n "Fetching wire transfers of ADMIN instance ..."
    296 
    297 STATUS=$(curl 'http://localhost:9966/private/transfers' \
    298               -w "%{http_code}" \
    299               -s \
    300               -o "$LAST_RESPONSE")
    301 
    302 if [ "$STATUS" != "200" ]
    303 then
    304     jq . < "$LAST_RESPONSE"
    305     exit_fail "Expected response 200 Ok. got: $STATUS"
    306 fi
    307 
    308 TRANSFERS_LIST_SIZE=$(jq -r '.transfers | length' < "$LAST_RESPONSE")
    309 
    310 if [ "$TRANSFERS_LIST_SIZE" != "1" ]
    311 then
    312     jq . < "$LAST_RESPONSE"
    313     exit_fail "Expected one transfer. got: $TRANSFERS_LIST_SIZE"
    314 fi
    315 
    316 echo "OK"
    317 
    318 echo -n "Fetching running taler-merchant-reconciliation on bogus transfer ..."
    319 taler-merchant-reconciliation \
    320     -c "$CONF" \
    321     -L INFO \
    322     -t &> taler-merchant-reconciliation0.log
    323 echo "OK"
    324 
    325 echo -n "Fetching wire transfers of 'test' instance ..."
    326 
    327 STATUS=$(curl 'http://localhost:9966/instances/test/private/transfers' \
    328               -w "%{http_code}" \
    329               -s \
    330               -o "$LAST_RESPONSE")
    331 
    332 if [ "$STATUS" != "200" ]
    333 then
    334     jq . < "$LAST_RESPONSE"
    335     exit_fail "Expected response 200 Ok. got: $STATUS"
    336 fi
    337 
    338 TRANSFERS_LIST_SIZE=$(jq -r '.transfers | length' < "$LAST_RESPONSE")
    339 
    340 if [ "$TRANSFERS_LIST_SIZE" != "0" ]
    341 then
    342     jq . < "$LAST_RESPONSE"
    343     exit_fail "Expected non-empty transfer list size. got: $TRANSFERS_LIST_SIZE"
    344 fi
    345 
    346 echo "OK"
    347 
    348 echo -n "Checking order status ..."
    349 STATUS=$(curl "http://localhost:9966/instances/test/private/orders/${ORDER_ID}?transfer=YES" \
    350     -w "%{http_code}" -s -o "$LAST_RESPONSE")
    351 
    352 if [ "$STATUS" != "200" ]
    353 then
    354     jq . < "$LAST_RESPONSE"
    355     exit_fail "Expected 200 ok, after order inquiry. got: $STATUS"
    356 fi
    357 
    358 WAS_WIRED=$(jq -r .wired < "$LAST_RESPONSE")
    359 
    360 if [ "$WAS_WIRED" == "true" ]
    361 then
    362     jq . < "$LAST_RESPONSE"
    363     exit_fail ".wired is true, expected false"
    364 fi
    365 
    366 echo " OK"
    367 
    368 echo -n "Notifying merchant of correct wire transfer in the correct instance..."
    369 #this time in the correct instance so the order will be marked as wired...
    370 
    371 echo -n "Running taler-merchant-wirewatch to check transfer ..."
    372 taler-merchant-wirewatch \
    373     -c $CONF \
    374     -t \
    375     -L INFO &> taler-merchant-wirewatch1.log
    376 echo " DONE"
    377 
    378 echo -n "Post-check for exchange deposit ..."
    379 taler-merchant-depositcheck \
    380     -c $CONF \
    381     -t \
    382     -e "http://localhost:8081/" \
    383     -T ${TO_SLEEP}000000 \
    384     -L INFO &> depositcheck1a.log
    385 echo " DONE"
    386 
    387 echo -n "Fetching running taler-merchant-reconciliation on good transfer ..."
    388 taler-merchant-reconciliation \
    389     -c $CONF \
    390     -L INFO \
    391     -T ${TO_SLEEP}000000 \
    392     -t &> taler-merchant-reconciliation1.log
    393 echo "OK"
    394 
    395 echo -n "Fetching wire transfers of TEST instance ..."
    396 
    397 STATUS=$(curl 'http://localhost:9966/instances/test/private/transfers' \
    398               -w "%{http_code}" \
    399               -s \
    400               -o "$LAST_RESPONSE")
    401 
    402 if [ "$STATUS" != "200" ]
    403 then
    404     jq . < "$LAST_RESPONSE"
    405     exit_fail "Expected response 200 Ok. got: $STATUS"
    406 fi
    407 
    408 TRANSFERS_LIST_SIZE=$(jq -r '.transfers | length' < "$LAST_RESPONSE")
    409 
    410 if [ "$TRANSFERS_LIST_SIZE" != "1" ]
    411 then
    412     jq . < "$LAST_RESPONSE"
    413     exit_fail "Expected one transfer. got: $TRANSFERS_LIST_SIZE"
    414 fi
    415 
    416 echo "OK"
    417 
    418 echo -n "Checking order status ..."
    419 STATUS=$(curl "http://localhost:9966/instances/test/private/orders/${ORDER_ID}" \
    420     -w "%{http_code}" -s -o "$LAST_RESPONSE")
    421 
    422 if [ "$STATUS" != "200" ]
    423 then
    424     jq . < "$LAST_RESPONSE"
    425     exit_fail "Expected 200 ok, after order inquiry. got: $STATUS"
    426 fi
    427 
    428 WAS_WIRED=$(jq -r .wired < "$LAST_RESPONSE")
    429 
    430 if [ "$WAS_WIRED" != "true" ]
    431 then
    432     jq . < "$LAST_RESPONSE"
    433     exit_fail ".wired false, expected true"
    434 fi
    435 
    436 echo " OK"
    437 
    438 
    439 echo "================== 2nd order ====================== "
    440 
    441 
    442 
    443 # CREATE ORDER AND SELL IT
    444 echo -n "Creating 2nd order to be paid..."
    445 STATUS=$(curl 'http://localhost:9966/instances/test/private/orders' \
    446     -d '{"refund_delay":{"d_us":0}, "order":{"amount":"TESTKUDOS:2","summary":"payme"}}' \
    447     -w "%{http_code}" -s -o "$LAST_RESPONSE")
    448 
    449 if [ "$STATUS" != "200" ]
    450 then
    451     cat "$LAST_RESPONSE"
    452     exit_fail "Expected 200 ok, order created. got: $STATUS"
    453 fi
    454 
    455 ORDER_ID=$(jq -e -r .order_id < "$LAST_RESPONSE")
    456 #TOKEN=$(jq -e -r .token < "$LAST_RESPONSE")
    457 
    458 STATUS=$(curl "http://localhost:9966/instances/test/private/orders/${ORDER_ID}" \
    459     -w "%{http_code}" -s -o "$LAST_RESPONSE")
    460 
    461 if [ "$STATUS" != "200" ]
    462 then
    463     cat "$LAST_RESPONSE"
    464     exit_fail "Expected 200 ok, getting order info before claming it. got: $STATUS"
    465 fi
    466 PAY_URL=$(jq -e -r .taler_pay_uri < "$LAST_RESPONSE")
    467 echo "OK"
    468 
    469 NOW=$(date +%s)
    470 echo -n "Pay second order ..."
    471 taler-wallet-cli \
    472     --no-throttle \
    473     --wallet-db="$WALLET_DB" \
    474     handle-uri "${PAY_URL}" \
    475     -y \
    476     2> wallet-pay2.err > wallet-pay2.log
    477 NOW2=$(date +%s)
    478 echo " OK (took $(( NOW2 - NOW )) secs)"
    479 
    480 STATUS=$(curl "http://localhost:9966/instances/test/private/orders/${ORDER_ID}" \
    481     -w "%{http_code}" -s -o "$LAST_RESPONSE")
    482 
    483 if [ "$STATUS" != "200" ]
    484 then
    485     cat "$LAST_RESPONSE"
    486     exit_fail "Expected 200 ok, after pay. got: $STATUS"
    487 fi
    488 
    489 ORDER_STATUS=$(jq -r .order_status < "$LAST_RESPONSE")
    490 
    491 if [ "$ORDER_STATUS" != "paid" ]
    492 then
    493     cat "$LAST_RESPONSE"
    494     exit_fail "Expected 'paid'. got: $ORDER_STATUS"
    495 fi
    496 
    497 #
    498 # WIRE TRANSFER TO MERCHANT AND NOTIFY BACKEND
    499 #
    500 
    501 #PAY_DEADLINE=$(jq -r .contract_terms.pay_deadline.t_s < "$LAST_RESPONSE")
    502 WIRE_DEADLINE=$(jq -r .contract_terms.wire_transfer_deadline.t_s < "$LAST_RESPONSE")
    503 
    504 NOW=$(date +%s)
    505 
    506 TO_SLEEP=$((3600 + WIRE_DEADLINE - NOW ))
    507 echo "waiting $TO_SLEEP secs for wire transfer"
    508 
    509 echo -n "Pre-check for exchange deposit ..."
    510 taler-merchant-depositcheck \
    511     -c $CONF \
    512     -t \
    513     -e "http://localhost:8081/" \
    514     -L INFO &> depositcheck1b.log
    515 echo " DONE"
    516 
    517 echo -n "Perform wire transfers ..."
    518 taler-exchange-aggregator \
    519     -y \
    520     -c $CONF \
    521     -T ${TO_SLEEP}000000 \
    522     -t \
    523     -L INFO &> aggregator2.log
    524 taler-exchange-transfer \
    525     -c $CONF \
    526     -t \
    527     -L INFO &> transfer2.log
    528 echo " DONE"
    529 
    530 echo -n "Post-check for exchange deposit ..."
    531 taler-merchant-depositcheck \
    532     -c $CONF \
    533     -t \
    534     -e "http://localhost:8081/" \
    535     -T ${TO_SLEEP}000000 \
    536     -L INFO &> depositcheck1c.log
    537 echo " DONE"
    538 
    539 
    540 echo -n "Obtaining wire transfer details from bank..."
    541 
    542 BANKDATA="$(curl 'http://localhost:8082/accounts/exchange/taler-wire-gateway/history/outgoing?delta=2' -s)"
    543 
    544 WTID=$(echo "$BANKDATA" | jq -r .outgoing_transactions[1].wtid)
    545 WURL=$(echo "$BANKDATA" | jq -r .outgoing_transactions[1].exchange_base_url)
    546 CREDIT_AMOUNT=$(echo "$BANKDATA" | jq -r .outgoing_transactions[1].amount)
    547 TARGET_PAYTO=$(echo "$BANKDATA" | jq -r .outgoing_transactions[1].credit_account)
    548 TARGET=$(echo "$TARGET_PAYTO" | awk -F = '{print $2}')
    549 
    550 # Figure out which account got paid, in order to
    551 # resort the right (and complete: including the receiver-name)
    552 # TARGET_PAYTO
    553 if echo "$SURVEY_PAYTO" | grep -q "$TARGET" > /dev/null; then
    554   TARGET_PAYTO="$SURVEY_PAYTO";
    555 fi
    556 if echo "$SURVEY_PAYTO" | grep -q "$TARGET" > /dev/null; then
    557   TARGET_PAYTO="$SURVEY_PAYTO";
    558 fi
    559 if [ "$EXCHANGE_URL" != "$WURL" ]
    560 then
    561     exit_fail "Wrong exchange URL in subject '$SUBJECT', expected $EXCHANGE_URL"
    562 fi
    563 echo " OK"
    564 
    565 echo -n "Running taler-merchant-wirewatch to check transfer ..."
    566 taler-merchant-wirewatch \
    567     -c $CONF \
    568     -t \
    569     -L INFO &> taler-merchant-wirewatch2.log
    570 echo " DONE"
    571 
    572 echo -n "Fetching running taler-merchant-reconciliation on good transfer ..."
    573 taler-merchant-reconciliation \
    574     -c $CONF \
    575     -L INFO \
    576     -T ${TO_SLEEP}000000 \
    577     -t &> taler-merchant-reconciliation2.log
    578 echo "OK"
    579 
    580 echo -n "Fetching wire transfers of TEST instance ..."
    581 
    582 STATUS=$(curl 'http://localhost:9966/instances/test/private/transfers' \
    583               -w "%{http_code}" \
    584               -s \
    585               -o "$LAST_RESPONSE")
    586 
    587 if [ "$STATUS" != "200" ]
    588 then
    589     jq . < "$LAST_RESPONSE"
    590     exit_fail "Expected response 200 Ok. got: $STATUS"
    591 fi
    592 
    593 TRANSFERS_LIST_SIZE=$(jq -r '.transfers | length' < "$LAST_RESPONSE")
    594 
    595 if [ "$TRANSFERS_LIST_SIZE" != "2" ]
    596 then
    597     jq . < "$LAST_RESPONSE"
    598     exit_fail "Expected two transfers. got: $TRANSFERS_LIST_SIZE"
    599 fi
    600 
    601 echo "OK"
    602 
    603 echo -n "Checking order status ..."
    604 STATUS=$(curl "http://localhost:9966/instances/test/private/orders/${ORDER_ID}" \
    605     -w "%{http_code}" -s -o "$LAST_RESPONSE")
    606 
    607 if [ "$STATUS" != "200" ]
    608 then
    609     jq . < "$LAST_RESPONSE"
    610     exit_fail "Expected 200 ok, after order inquiry. got: $STATUS"
    611 fi
    612 
    613 WAS_WIRED=$(jq -r .wired < "$LAST_RESPONSE")
    614 
    615 if [ "$WAS_WIRED" != "true" ]
    616 then
    617     jq . < "$LAST_RESPONSE"
    618     exit_fail ".wired false, expected true"
    619 fi
    620 
    621 echo " OK"
    622 
    623 echo "================== 3rd order ====================== "
    624 
    625 # CREATE ORDER AND SELL IT
    626 echo -n "Creating 3rd order to be paid..."
    627 STATUS=$(curl 'http://localhost:9966/instances/test/private/orders' \
    628     -d '{"refund_delay":{"d_us":0}, "order":{"amount":"TESTKUDOS:3","summary":"payme"}}' \
    629     -w "%{http_code}" -s -o "$LAST_RESPONSE")
    630 
    631 if [ "$STATUS" != "200" ]
    632 then
    633     cat "$LAST_RESPONSE"
    634     exit_fail "Expected 200 ok, order created. got: $STATUS"
    635 fi
    636 
    637 ORDER_ID=$(jq -e -r .order_id < "$LAST_RESPONSE")
    638 #TOKEN=$(jq -e -r .token < "$LAST_RESPONSE")
    639 
    640 STATUS=$(curl "http://localhost:9966/instances/test/private/orders/${ORDER_ID}" \
    641     -w "%{http_code}" -s -o "$LAST_RESPONSE")
    642 
    643 if [ "$STATUS" != "200" ]
    644 then
    645     cat "$LAST_RESPONSE"
    646     exit_fail "Expected 200 ok, getting order info before claming it. got: $STATUS"
    647 fi
    648 PAY_URL=$(jq -e -r .taler_pay_uri < "$LAST_RESPONSE")
    649 echo "OK"
    650 
    651 NOW=$(date +%s)
    652 echo -n "Pay third order ..."
    653 taler-wallet-cli \
    654     --no-throttle \
    655     --wallet-db="$WALLET_DB" \
    656     handle-uri "${PAY_URL}" \
    657     -y \
    658     2> wallet-pay2.err > wallet-pay2.log
    659 NOW2=$(date +%s)
    660 echo " OK (took $(( NOW2 - NOW )) secs)"
    661 
    662 STATUS=$(curl "http://localhost:9966/instances/test/private/orders/${ORDER_ID}" \
    663     -w "%{http_code}" -s -o "$LAST_RESPONSE")
    664 
    665 if [ "$STATUS" != "200" ]
    666 then
    667     cat "$LAST_RESPONSE"
    668     exit_fail "Expected 200 ok, after pay. got: $STATUS"
    669 fi
    670 
    671 ORDER_STATUS=$(jq -r .order_status < "$LAST_RESPONSE")
    672 
    673 if [ "$ORDER_STATUS" != "paid" ]
    674 then
    675     cat "$LAST_RESPONSE"
    676     exit_fail "Expected 'paid'. got: $ORDER_STATUS"
    677 fi
    678 
    679 #
    680 # WIRE TRANSFER TO MERCHANT AND NOTIFY BACKEND
    681 #
    682 
    683 #PAY_DEADLINE=$(jq -r .contract_terms.pay_deadline.t_s < "$LAST_RESPONSE")
    684 WIRE_DEADLINE=$(jq -r .contract_terms.wire_transfer_deadline.t_s < "$LAST_RESPONSE")
    685 
    686 NOW=$(date +%s)
    687 
    688 TO_SLEEP=$((1200 + WIRE_DEADLINE - NOW ))
    689 echo "waiting $TO_SLEEP secs for wire transfer"
    690 
    691 echo -n "Perform wire transfers for 3rd order..."
    692 taler-exchange-aggregator \
    693     -y \
    694     -c $CONF \
    695     -T ${TO_SLEEP}000000 \
    696     -t \
    697     -L INFO &> aggregator3.log
    698 taler-exchange-transfer \
    699     -c $CONF \
    700     -t \
    701     -L INFO &> transfer3.log
    702 echo " DONE"
    703 
    704 echo -n "Running taler-merchant-wirewatch to check transfer ..."
    705 taler-merchant-wirewatch \
    706     -c $CONF \
    707     -t \
    708     -L INFO &> taler-merchant-wirewatch3.log
    709 echo " DONE"
    710 
    711 echo -n "Post-wirewatch check for exchange deposit ..."
    712 taler-merchant-depositcheck \
    713     -c $CONF \
    714     -t \
    715     -e "http://localhost:8081/" \
    716     -T ${TO_SLEEP}000000 \
    717     -L INFO &> depositcheck1d.log
    718 echo " DONE"
    719 
    720 echo -n "Fetching wire transfers of TEST instance ..."
    721 
    722 STATUS=$(curl 'http://localhost:9966/instances/test/private/transfers' \
    723               -w "%{http_code}" \
    724               -s \
    725               -o "$LAST_RESPONSE")
    726 
    727 if [ "$STATUS" != "200" ]
    728 then
    729     jq . < "$LAST_RESPONSE"
    730     exit_fail "Expected response 200 Ok. got: $STATUS"
    731 fi
    732 
    733 TRANSFERS_LIST_SIZE=$(jq -r '.transfers | length' < "$LAST_RESPONSE")
    734 
    735 if [ "$TRANSFERS_LIST_SIZE" != "3" ]
    736 then
    737     jq . < "$LAST_RESPONSE"
    738     exit_fail "Expected three transfers. got: $TRANSFERS_LIST_SIZE"
    739 fi
    740 
    741 echo "OK"
    742 
    743 echo -n "Fetching running taler-merchant-reconciliation on good transfer ..."
    744 taler-merchant-reconciliation \
    745     -c $CONF \
    746     -L INFO \
    747     -T ${TO_SLEEP}000000 \
    748     -t &> taler-merchant-reconciliation3.log
    749 echo "OK"
    750 
    751 echo -n "Checking order status ..."
    752 STATUS=$(curl "http://localhost:9966/instances/test/private/orders/${ORDER_ID}" \
    753     -w "%{http_code}" -s -o "$LAST_RESPONSE")
    754 
    755 if [ "$STATUS" != "200" ]
    756 then
    757     jq . < "$LAST_RESPONSE"
    758     exit_fail "Expected 200 ok, after order inquiry. got: $STATUS"
    759 fi
    760 
    761 WAS_WIRED=$(jq -r .wired < "$LAST_RESPONSE")
    762 
    763 if [ "$WAS_WIRED" != "true" ]
    764 then
    765     jq . < "$LAST_RESPONSE"
    766     exit_fail ".wired false, expected true"
    767 fi
    768 
    769 echo " OK"
    770 
    771 
    772 exit 0