merchant

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

test_merchant_kyc.sh (5123B)


      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" -X POST \
     35     -H 'Authorization: Bearer secret-token:super_secret' \
     36     http://localhost:9966/management/instances \
     37     -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}}' \
     38     -w "%{http_code}" -s -o /dev/null)
     39 
     40 if [ "$STATUS" != "204" ]
     41 then
     42     exit_fail "Expected 204 ok, instance created. got: $STATUS"
     43 fi
     44 
     45 echo " OK"
     46 
     47 echo -n "Creating account ..."
     48 
     49 STATUS=$(curl -H "Content-Type: application/json" -X POST \
     50     -H 'Authorization: Bearer secret-token:super_secret' \
     51     http://localhost:9966/private/accounts \
     52     -d '{"payto_uri":"payto://x-taler-bank/localhost:8082/43?receiver-name=user43"}' \
     53     -w "%{http_code}" -s -o /dev/null)
     54 
     55 
     56 if [ "$STATUS" != "200" ]
     57 then
     58     exit_fail "Expected 200 OK. Got: $STATUS"
     59 fi
     60 
     61 echo " OK"
     62 
     63 echo -n "Creating conflicting account with different receiver name ..."
     64 
     65 STATUS=$(curl -H "Content-Type: application/json" -X POST \
     66     -H 'Authorization: Bearer secret-token:super_secret' \
     67     http://localhost:9966/private/accounts \
     68     -d '{"payto_uri":"payto://x-taler-bank/localhost:8082/43?receiver-name=user44"}' \
     69     -w "%{http_code}" -s -o /dev/null)
     70 
     71 
     72 if [ "$STATUS" != "409" ]
     73 then
     74     exit_fail "Expected 409 Conflict. Got: $STATUS"
     75 fi
     76 
     77 echo " OK"
     78 
     79 echo -n "Creating a second account ..."
     80 
     81 STATUS=$(curl -H "Content-Type: application/json" -X POST \
     82     -H 'Authorization: Bearer secret-token:super_secret' \
     83     http://localhost:9966/private/accounts \
     84     -d '{"payto_uri":"payto://x-taler-bank/localhost:8082/44?receiver-name=user44"}' \
     85     -w "%{http_code}" -s -o /dev/null)
     86 
     87 
     88 if [ "$STATUS" != "200" ]
     89 then
     90     exit_fail "Expected 200 OK. Got: $STATUS"
     91 fi
     92 
     93 echo " OK"
     94 
     95 echo -n "Check the instance exists ..."
     96 
     97 STATUS=$(curl -H "Content-Type: application/json" -X GET \
     98     http://localhost:9966/private/ \
     99     -w "%{http_code}" -s -o /dev/null)
    100 
    101 if [ "$STATUS" != "200" ]
    102 then
    103     exit_fail "Expected 200 ok, instance exists. got: $STATUS"
    104 fi
    105 
    106 echo " OK"
    107 
    108 RANDOM_IMG='data:image/png;base64,abcdefg'
    109 
    110 #
    111 # CREATE AN ORDER WITHOUT TOKEN
    112 #
    113 
    114 echo -n "Creating order without TOKEN..."
    115 STATUS=$(curl 'http://localhost:9966/private/orders' \
    116     -d '{"create_token":false,"order":{"amount":"TESTKUDOS:7","summary":"3","products":[{"description":"desct","image":"'"$RANDOM_IMG"'","price":"TESTKUDOS:1","taxes":[],"unit":"u","quantity":1}]}}' \
    117     -w "%{http_code}" -s -o "$LAST_RESPONSE")
    118 
    119 if [ "$STATUS" != "200" ]
    120 then
    121     echo "Should respond 200 OK, order created. got: $STATUS"
    122     jq < "$LAST_RESPONSE"
    123     exit 1
    124 fi
    125 
    126 ORDER_ID=$(jq -r .order_id < "$LAST_RESPONSE")
    127 TOKEN=$(jq -r .token < "$LAST_RESPONSE")
    128 
    129 if [ "$TOKEN" != "null" ]
    130 then
    131     exit_fail "Token should be null, got: $TOKEN"
    132 fi
    133 
    134 echo "OK"
    135 
    136 echo -n "Checking created order without TOKEN..."
    137 
    138 STATUS=$(curl http://localhost:9966/orders/$ORDER_ID \
    139     -w "%{http_code}" -s -o "$LAST_RESPONSE")
    140 
    141 PAY_URI=$(jq -r .taler_pay_uri < "$LAST_RESPONSE")
    142 
    143 if [ "$PAY_URI" == "null" ]
    144 then
    145     cat "$LAST_RESPONSE"
    146     exit_fail "Expected a taler_pay_uri. Got: $PAY_URI"
    147 fi
    148 echo "OK"
    149 
    150 
    151 echo -n "Getting information about KYC ..."
    152 
    153 STATUS=$(curl -H "Accept: application/json" -X GET \
    154     http://localhost:9966/private/kyc \
    155     -w "%{http_code}" -s -o "$LAST_RESPONSE")
    156 
    157 if [ "$STATUS" != "200" ]
    158 then
    159     exit_fail "Expected 200. got: $STATUS"
    160 fi
    161 
    162 echo " OK"
    163 
    164 echo -n "Getting information about KYC in plaintext ..."
    165 
    166 STATUS=$(curl -H "Accept: text/plain" -X GET \
    167     http://localhost:9966/private/kyc \
    168     -w "%{http_code}" -s -o "$LAST_RESPONSE")
    169 
    170 if [ "$STATUS" != "200" ]
    171 then
    172     exit_fail "Expected 200. got: $STATUS"
    173 fi
    174 # cat "$LAST_RESPONSE"
    175 
    176 echo " OK"
    177 
    178 echo -n "Getting exchange status information ..."
    179 
    180 STATUS=$(curl -H "Accept: application/json" -X GET \
    181     http://localhost:9966/exchanges \
    182     -w "%{http_code}" -s -o "$LAST_RESPONSE")
    183 
    184 if [ "$STATUS" != "200" ]
    185 then
    186     jq < "$LAST_RESPONSE"
    187     exit_fail "Expected 200. got: $STATUS"
    188 fi
    189 
    190 echo " OK"
    191 echo "TEST PASSED"
    192 
    193 exit 0