merchant

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

test_merchant_kyc.sh (6552B)


      1 #!/bin/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               -H 'Authorization: Bearer secret-token:super_secret' \
     37               http://localhost:9966/management/instances \
     38               -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}}' \
     39               -w "%{http_code}" \
     40               -s \
     41               -o /dev/null)
     42 
     43 if [ "$STATUS" != "204" ]
     44 then
     45     exit_fail "Expected 204 ok, instance created. got: $STATUS"
     46 fi
     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 secret-token:super_secret' \
     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 secret-token:super_secret' \
     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 secret-token:super_secret' \
     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 instance exists ..."
    105 
    106 STATUS=$(curl -H "Content-Type: application/json" \
    107               -X GET \
    108               http://localhost:9966/private/ \
    109               -w "%{http_code}" \
    110               -s \
    111               -o /dev/null)
    112 
    113 if [ "$STATUS" != "200" ]
    114 then
    115     exit_fail "Expected 200 ok, instance exists. got: $STATUS"
    116 fi
    117 
    118 echo " OK"
    119 
    120 RANDOM_IMG='data:image/png;base64,abcdefg'
    121 
    122 #
    123 # CREATE AN ORDER WITHOUT TOKEN
    124 #
    125 
    126 echo -n "Creating order without TOKEN..."
    127 STATUS=$(curl 'http://localhost:9966/private/orders' \
    128               -d '{"create_token":false,"order":{"amount":"TESTKUDOS:7","summary":"3","products":[{"description":"desct","image":"'"$RANDOM_IMG"'","price":"TESTKUDOS:1","taxes":[],"unit":"u","quantity":1}]}}' \
    129               -w "%{http_code}" \
    130               -s \
    131               -o "$LAST_RESPONSE")
    132 
    133 if [ "$STATUS" != "200" ]
    134 then
    135     echo "Should respond 200 OK, order created. got: $STATUS"
    136     jq < "$LAST_RESPONSE"
    137     exit 1
    138 fi
    139 
    140 ORDER_ID=$(jq -r .order_id < "$LAST_RESPONSE")
    141 TOKEN=$(jq -r .token < "$LAST_RESPONSE")
    142 
    143 if [ "$TOKEN" != "null" ]
    144 then
    145     exit_fail "Token should be null, got: $TOKEN"
    146 fi
    147 
    148 echo "OK"
    149 
    150 echo -n "Checking created order without TOKEN..."
    151 
    152 STATUS=$(curl http://localhost:9966/orders/$ORDER_ID \
    153               -w "%{http_code}" \
    154               -s \
    155               -o "$LAST_RESPONSE")
    156 
    157 PAY_URI=$(jq -r .taler_pay_uri < "$LAST_RESPONSE")
    158 
    159 if [ "$PAY_URI" == "null" ]
    160 then
    161     cat "$LAST_RESPONSE"
    162     exit_fail "Expected a taler_pay_uri. Got: $PAY_URI"
    163 fi
    164 echo "OK"
    165 
    166 
    167 echo -n "Getting information about KYC ..."
    168 
    169 STATUS=$(curl -H "Accept: application/json" \
    170               -X GET \
    171               http://localhost:9966/private/kyc \
    172               -w "%{http_code}" \
    173               -s \
    174               -o "$LAST_RESPONSE")
    175 
    176 if [ "$STATUS" != "200" ]
    177 then
    178     exit_fail "Expected 200. got: $STATUS"
    179 fi
    180 H_WIRE=$(jq -r .kyc_data[0].h_wire < "$LAST_RESPONSE")
    181 echo " OK"
    182 
    183 echo -n "Getting information about KYC in plaintext ..."
    184 
    185 STATUS=$(curl -H "Accept: text/plain" \
    186               -X GET \
    187               http://localhost:9966/private/kyc \
    188               -w "%{http_code}" \
    189               -s \
    190               -o "$LAST_RESPONSE")
    191 
    192 if [ "$STATUS" != "200" ]
    193 then
    194     exit_fail "Expected 200. got: $STATUS"
    195 fi
    196 # cat "$LAST_RESPONSE"
    197 
    198 echo " OK"
    199 
    200 echo -n "Getting exchange status information ..."
    201 
    202 STATUS=$(curl -H "Accept: application/json" \
    203               -X GET \
    204               http://localhost:9966/exchanges \
    205               -w "%{http_code}" \
    206               -s \
    207               -o "$LAST_RESPONSE")
    208 
    209 if [ "$STATUS" != "200" ]
    210 then
    211     jq < "$LAST_RESPONSE"
    212     exit_fail "Expected 200. got: $STATUS"
    213 fi
    214 echo " OK"
    215 
    216 
    217 echo -n "Requesting KYC wire transfer instructions ..."
    218 
    219 STATUS=$(curl -H "Accept: application/json" \
    220               -X POST \
    221               "http://localhost:9966/private/accounts/$H_WIRE/kycauth" \
    222               -d '{"exchange_url":"http://localhost:8081/"}' \
    223               -w "%{http_code}" \
    224               -s \
    225               -o "$LAST_RESPONSE")
    226 
    227 if [ "$STATUS" != "200" ]
    228 then
    229     jq < "$LAST_RESPONSE"
    230     exit_fail "Expected 200. got: $STATUS"
    231 fi
    232 
    233 WI_TYPE=$(jq -r .wire_instructions[0].subject.type < "$LAST_RESPONSE")
    234 
    235 if [ "$WI_TYPE" != "SIMPLE" ]
    236 then
    237     jq < "$LAST_RESPONSE"
    238     exit_fail "Type should be SIMPLE, got: $WI_TYPE"
    239 fi
    240 echo " OK"
    241 
    242 
    243 
    244 echo "TEST PASSED"
    245 
    246 exit 0