From ebe58b6d086ebd6245a1520316a914dd5ef356ce Mon Sep 17 00:00:00 2001 From: snsd0805 Date: Sun, 11 Jun 2023 15:22:32 +0800 Subject: [PATCH] feat: complete payment flow --- backend/main.py | 8 +- src/assets/Bank.json | 494 +++++++++++++++++++----------------- src/router/index.js | 6 + src/views/ClientPayView.vue | 97 +++++++ src/views/PaymentView.vue | 159 ++++++++++++ 5 files changed, 523 insertions(+), 241 deletions(-) create mode 100644 src/views/ClientPayView.vue create mode 100644 src/views/PaymentView.vue diff --git a/backend/main.py b/backend/main.py index 9b6593e..4cbaba6 100644 --- a/backend/main.py +++ b/backend/main.py @@ -1,8 +1,10 @@ from flask import Flask, request, jsonify import sqlite3 import os +from flask_cors import CORS app = Flask(__name__) +CORS(app) DATABASE = './main.db' @@ -77,7 +79,7 @@ def get_order(id): for product in products: ans['products'].append({ 'name': product[0], - 'price': product[1], + 'price': str(product[1]), 'count': product[2] }) @@ -88,11 +90,11 @@ def get_order(id): 'name': result[1], 'address': result[0] } - ans['amount'] = result[2] + ans['amount'] = str(result[2]) return jsonify(ans) if __name__ == '__main__': initDB() - app.run() + app.run(host="0.0.0.0") diff --git a/src/assets/Bank.json b/src/assets/Bank.json index 2b08e11..e7af049 100644 --- a/src/assets/Bank.json +++ b/src/assets/Bank.json @@ -1,239 +1,257 @@ [ - { - "inputs": [ - { - "internalType": "address", - "name": "SBT_addr", - "type": "address" - } - ], - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "inputs": [], - "name": "owner", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function", - "constant": true - }, - { - "inputs": [], - "name": "recv", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function", - "constant": true - }, - { - "inputs": [], - "name": "sbt", - "outputs": [ - { - "internalType": "contract SoulboundToken", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function", - "constant": true - }, - { - "stateMutability": "payable", - "type": "receive", - "payable": true - }, - { - "inputs": [ - { - "internalType": "address", - "name": "client", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "setCredit", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "number", - "type": "uint256" - } - ], - "name": "register", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "shop", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "pay", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "repay", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "payable", - "type": "function", - "payable": true - }, - { - "inputs": [], - "name": "start_recv", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "stop_recv", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "client", - "type": "address" - } - ], - "name": "getCredit", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function", - "constant": true - }, - { - "inputs": [ - { - "internalType": "address", - "name": "client", - "type": "address" - } - ], - "name": "getArrear", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function", - "constant": true - }, - { - "inputs": [ - { - "internalType": "address", - "name": "client", - "type": "address" - } - ], - "name": "getClientOrders", - "outputs": [ - { - "components": [ - { - "internalType": "bool", - "name": "isFinished", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - }, - { - "internalType": "address", - "name": "shop", - "type": "address" - } - ], - "internalType": "struct Order[]", - "name": "", - "type": "tuple[]" - } - ], - "stateMutability": "view", - "type": "function", - "constant": true - }, - { - "inputs": [ - { - "internalType": "address", - "name": "client", - "type": "address" - } - ], - "name": "getSBTNumber", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function", - "constant": true - } - ] \ No newline at end of file + { + "inputs": [ + { + "internalType": "address", + "name": "SBT_addr", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function", + "constant": true + }, + { + "inputs": [], + "name": "recv", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function", + "constant": true + }, + { + "inputs": [], + "name": "sbt", + "outputs": [ + { + "internalType": "contract SoulboundToken", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function", + "constant": true + }, + { + "stateMutability": "payable", + "type": "receive", + "payable": true + }, + { + "inputs": [ + { + "internalType": "address", + "name": "client", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "setCredit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "number", + "type": "uint256" + } + ], + "name": "register", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "id", + "type": "uint256" + }, + { + "internalType": "address", + "name": "shop", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "pay", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "repay", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "payable", + "type": "function", + "payable": true + }, + { + "inputs": [ + { + "internalType": "address", + "name": "client", + "type": "address" + } + ], + "name": "warning", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "start_recv", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "stop_recv", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "client", + "type": "address" + } + ], + "name": "getCredit", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function", + "constant": true + }, + { + "inputs": [ + { + "internalType": "address", + "name": "client", + "type": "address" + } + ], + "name": "getArrear", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function", + "constant": true + }, + { + "inputs": [ + { + "internalType": "address", + "name": "client", + "type": "address" + } + ], + "name": "getClientOrders", + "outputs": [ + { + "components": [ + { + "internalType": "bool", + "name": "isFinished", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "address", + "name": "shop", + "type": "address" + } + ], + "internalType": "struct Order[]", + "name": "", + "type": "tuple[]" + } + ], + "stateMutability": "view", + "type": "function", + "constant": true + }, + { + "inputs": [ + { + "internalType": "address", + "name": "client", + "type": "address" + } + ], + "name": "getSBTNumber", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function", + "constant": true + } +] \ No newline at end of file diff --git a/src/router/index.js b/src/router/index.js index 3dce51e..c553cb9 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -7,6 +7,7 @@ import ClientMainView from '../views/ClientMainView.vue' import ClientInfoView from '../views/ClientInfoView.vue' import ClientCreditView from '../views/ClientCreditView.vue' import ClientPayView from '../views/ClientPayView.vue' +import PaymentView from '../views/PaymentView.vue' const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), @@ -51,6 +52,11 @@ const router = createRouter({ name: 'clientpay', component: ClientPayView }, + { + path: '/client/pay/:id', + name: 'clientpayment', + component: PaymentView + }, ] }) diff --git a/src/views/ClientPayView.vue b/src/views/ClientPayView.vue new file mode 100644 index 0000000..b431631 --- /dev/null +++ b/src/views/ClientPayView.vue @@ -0,0 +1,97 @@ + + + diff --git a/src/views/PaymentView.vue b/src/views/PaymentView.vue new file mode 100644 index 0000000..79c2098 --- /dev/null +++ b/src/views/PaymentView.vue @@ -0,0 +1,159 @@ + + +