merchant

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

test_merchant_kyc.sh (6827B)


      1 #!/usr/bin/env bash
      2 # This file is part of TALER
      3 # Copyright (C) 2014-2023 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 set -eu
     20 
     21 . setup.sh
     22 
     23 
     24 # Launch system.
     25 setup \
     26     -c "test_template.conf" \
     27     -mef \
     28     -r "merchant-exchange-default" \
     29     -u "exchange-account-2"
     30 LAST_RESPONSE=$(mktemp -p "${TMPDIR:-/tmp}" test_response.conf-XXXXXX)
     31 
     32 echo -n "Configuring a merchant admin instance ..."
     33 
     34 STATUS=$(curl -H "Content-Type: application/json" \
     35               -X POST \
     36               http://localhost:9966/management/instances \
     37               -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}}' \
     38               -w "%{http_code}" \
     39               -s \
     40               -o /dev/null)
     41 
     42 if [ "$STATUS" != "204" ]
     43 then
     44     exit_fail "Expected 204 ok, instance created. got: $STATUS"
     45 fi
     46 ADMIN_TOKEN=$(merchant_login admin super_secret)
     47 
     48 echo " OK"
     49 
     50 echo -n "Creating account ..."
     51 
     52 STATUS=$(curl -H "Content-Type: application/json" \
     53               -X POST \
     54               -H "Authorization: Bearer $ADMIN_TOKEN" \
     55               http://localhost:9966/private/accounts \
     56               -d '{"payto_uri":"payto://x-taler-bank/localhost:8082/43?receiver-name=user43"}' \
     57               -w "%{http_code}" \
     58               -s \
     59               -o /dev/null)
     60 
     61 if [ "$STATUS" != "200" ]
     62 then
     63     exit_fail "Expected 200 OK. Got: $STATUS"
     64 fi
     65 
     66 echo " OK"
     67 
     68 echo -n "Creating conflicting account with different receiver name ..."
     69 
     70 STATUS=$(curl -H "Content-Type: application/json" \
     71               -X POST \
     72               -H "Authorization: Bearer $ADMIN_TOKEN" \
     73               http://localhost:9966/private/accounts \
     74               -d '{"payto_uri":"payto://x-taler-bank/localhost:8082/43?receiver-name=user44"}' \
     75               -w "%{http_code}" \
     76               -s \
     77               -o /dev/null)
     78 
     79 if [ "$STATUS" != "409" ]
     80 then
     81     exit_fail "Expected 409 Conflict. Got: $STATUS"
     82 fi
     83 
     84 echo " OK"
     85 
     86 echo -n "Creating a second account ..."
     87 
     88 STATUS=$(curl -H "Content-Type: application/json" \
     89               -X POST \
     90               -H "Authorization: Bearer $ADMIN_TOKEN" \
     91               http://localhost:9966/private/accounts \
     92               -d '{"payto_uri":"payto://x-taler-bank/localhost:8082/44?receiver-name=user44"}' \
     93               -w "%{http_code}" \
     94               -s \
     95               -o /dev/null)
     96 
     97 if [ "$STATUS" != "200" ]
     98 then
     99     exit_fail "Expected 200 OK. Got: $STATUS"
    100 fi
    101 
    102 echo " OK"
    103 
    104 echo -n "Check the (admin) instance exists ..."
    105 
    106 STATUS=$(curl -H "Content-Type: application/json" \
    107               -H "Authorization: Bearer $ADMIN_TOKEN" \
    108               -X GET \
    109               http://localhost:9966/private/ \
    110               -w "%{http_code}" \
    111               -s \
    112               -o /dev/null)
    113 
    114 if [ "$STATUS" != "200" ]
    115 then
    116     exit_fail "Expected 200 ok, instance exists. got: $STATUS"
    117 fi
    118 
    119 echo " OK"
    120 
    121 RANDOM_IMG='data:image/png;base64,abcdefg'
    122 
    123 #
    124 # CREATE AN ORDER WITHOUT TOKEN
    125 #
    126 
    127 echo -n "Creating order without TOKEN..."
    128 STATUS=$(curl 'http://localhost:9966/private/orders' \
    129               -H "Authorization: Bearer $ADMIN_TOKEN" \
    130               -d '{"create_token":false,"order":{"amount":"TESTKUDOS:7","summary":"3","products":[{"description":"desct","image":"'"$RANDOM_IMG"'","price":"TESTKUDOS:1","taxes":[],"unit":"u","quantity":1}]}}' \
    131               -w "%{http_code}" \
    132               -s \
    133               -o "$LAST_RESPONSE")
    134 
    135 if [ "$STATUS" != "200" ]
    136 then
    137     echo "Should respond 200 OK, order created. got: $STATUS"
    138     jq < "$LAST_RESPONSE"
    139     exit 1
    140 fi
    141 
    142 ORDER_ID=$(jq -r .order_id < "$LAST_RESPONSE")
    143 TOKEN=$(jq -r .token < "$LAST_RESPONSE")
    144 
    145 if [ "$TOKEN" != "null" ]
    146 then
    147     exit_fail "Token should be null, got: $TOKEN"
    148 fi
    149 
    150 echo "OK"
    151 
    152 echo -n "Checking created order without TOKEN..."
    153 
    154 STATUS=$(curl http://localhost:9966/orders/$ORDER_ID \
    155               -w "%{http_code}" \
    156               -s \
    157               -o "$LAST_RESPONSE")
    158 
    159 PAY_URI=$(jq -r .taler_pay_uri < "$LAST_RESPONSE")
    160 
    161 if [ "$PAY_URI" == "null" ]
    162 then
    163     cat "$LAST_RESPONSE"
    164     exit_fail "Expected a taler_pay_uri. Got: $PAY_URI"
    165 fi
    166 echo "OK"
    167 
    168 
    169 echo -n "Getting information about KYC ..."
    170 
    171 STATUS=$(curl -H "Accept: application/json" \
    172               -H "Authorization: Bearer $ADMIN_TOKEN" \
    173               -X GET \
    174               http://localhost:9966/private/kyc \
    175               -w "%{http_code}" \
    176               -s \
    177               -o "$LAST_RESPONSE")
    178 
    179 if [ "$STATUS" != "200" ]
    180 then
    181     exit_fail "Expected 200. got: $STATUS"
    182 fi
    183 H_WIRE=$(jq -r .kyc_data[0].h_wire < "$LAST_RESPONSE")
    184 echo " OK"
    185 
    186 echo -n "Getting information about KYC in plaintext ..."
    187 
    188 STATUS=$(curl -H "Accept: text/plain" \
    189               -H "Authorization: Bearer $ADMIN_TOKEN" \
    190               -X GET \
    191               http://localhost:9966/private/kyc \
    192               -w "%{http_code}" \
    193               -s \
    194               -o "$LAST_RESPONSE")
    195 
    196 if [ "$STATUS" != "200" ]
    197 then
    198     exit_fail "Expected 200 for text/plain. got: $STATUS"
    199 fi
    200 # cat "$LAST_RESPONSE"
    201 
    202 echo " OK"
    203 
    204 echo -n "Getting exchange status information ..."
    205 
    206 STATUS=$(curl -H "Accept: application/json" \
    207               -X GET \
    208               http://localhost:9966/exchanges \
    209               -w "%{http_code}" \
    210               -s \
    211               -o "$LAST_RESPONSE")
    212 
    213 if [ "$STATUS" != "200" ]
    214 then
    215     jq < "$LAST_RESPONSE"
    216     exit_fail "Expected 200. got: $STATUS"
    217 fi
    218 echo " OK"
    219 
    220 
    221 echo -n "Requesting KYC wire transfer instructions ..."
    222 
    223 STATUS=$(curl -H "Accept: application/json" \
    224               -H "Authorization: Bearer $ADMIN_TOKEN" \
    225               -X POST \
    226               "http://localhost:9966/private/accounts/$H_WIRE/kycauth" \
    227               -d '{"exchange_url":"http://localhost:8081/"}' \
    228               -w "%{http_code}" \
    229               -s \
    230               -o "$LAST_RESPONSE")
    231 
    232 if [ "$STATUS" != "200" ]
    233 then
    234     jq < "$LAST_RESPONSE"
    235     exit_fail "Expected 200. got: $STATUS"
    236 fi
    237 
    238 WI_TYPE=$(jq -r .wire_instructions[0].subject.type < "$LAST_RESPONSE")
    239 
    240 if [ "$WI_TYPE" != "SIMPLE" ]
    241 then
    242     jq < "$LAST_RESPONSE"
    243     exit_fail "Type should be SIMPLE, got: $WI_TYPE"
    244 fi
    245 echo " OK"
    246 
    247 
    248 
    249 echo "TEST PASSED"
    250 
    251 exit 0